Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
plugins
/
datasource
/
loki
/
File Content:
queryHints.ts
import { DataFrame, QueryHint } from '@grafana/data'; import { isQueryWithLabelFilter, isQueryPipelineErrorFiltering, isQueryWithLabelFormat, isQueryWithParser, isQueryWithLineFilter, } from './queryUtils'; import { dataFrameHasLevelLabel, extractHasErrorLabelFromDataFrame, extractLevelLikeLabelFromDataFrame, extractLogParserFromDataFrame, } from './responseUtils'; export function getQueryHints(query: string, series: DataFrame[]): QueryHint[] { if (series.length === 0) { return []; } const hints: QueryHint[] = []; const { queryWithParser, parserCount } = isQueryWithParser(query); if (!queryWithParser) { const { hasLogfmt, hasJSON, hasPack } = extractLogParserFromDataFrame(series[0]); if (hasJSON) { if (hasPack) { hints.push({ type: 'ADD_UNPACK_PARSER', label: 'Selected log stream selector has packed logs.', fix: { title: 'add unpack parser', label: 'Consider using unpack parser.', action: { type: 'ADD_UNPACK_PARSER', query, }, }, }); } else { hints.push({ type: 'ADD_JSON_PARSER', label: 'Selected log stream selector has JSON formatted logs.', fix: { title: 'add json parser', label: 'Consider using JSON parser.', action: { type: 'ADD_JSON_PARSER', query, }, }, }); } } if (hasLogfmt) { hints.push({ type: 'ADD_LOGFMT_PARSER', label: 'Selected log stream selector has logfmt formatted logs.', fix: { title: 'add logfmt parser', label: 'Consider using logfmt parser to turn key-value pairs in your log lines to labels.', action: { type: 'ADD_LOGFMT_PARSER', query, }, }, }); } } if (queryWithParser) { // To keep this simple, we consider pipeline error filtering hint only is query has up to 1 parser if (parserCount === 1) { const hasPipelineErrorFiltering = isQueryPipelineErrorFiltering(query); const hasError = extractHasErrorLabelFromDataFrame(series[0]); if (hasError && !hasPipelineErrorFiltering) { hints.push({ type: 'ADD_NO_PIPELINE_ERROR', label: 'Some logs in your selected log streams have parsing error.', fix: { title: 'remove pipeline errors', label: 'Consider filtering out logs with parsing errors.', action: { type: 'ADD_NO_PIPELINE_ERROR', query, }, }, }); } } const hasLabelFilter = isQueryWithLabelFilter(query); if (!hasLabelFilter) { hints.push({ type: 'ADD_LABEL_FILTER', label: 'Consider filtering logs by their label and value.', fix: { title: 'add label filter', label: '', action: { type: 'ADD_LABEL_FILTER', query, }, }, }); } } const queryWithLabelFormat = isQueryWithLabelFormat(query); if (!queryWithLabelFormat) { const hasLevel = dataFrameHasLevelLabel(series[0]); const levelLikeLabel = extractLevelLikeLabelFromDataFrame(series[0]); // Add hint only if we don't have "level" label and have level-like label if (!hasLevel && levelLikeLabel) { hints.push({ type: 'ADD_LEVEL_LABEL_FORMAT', label: `Some logs in your selected log stream have "${levelLikeLabel}" label.`, fix: { title: 'add label level format', label: `If ${levelLikeLabel} label has level values, consider using label_format to rename it to "level". Level label can be then visualized in log volumes.`, action: { type: 'ADD_LEVEL_LABEL_FORMAT', query, options: { renameTo: 'level', originalLabel: levelLikeLabel, }, }, }, }); } } const hasLineFilter = isQueryWithLineFilter(query); if (!hasLineFilter) { hints.push({ type: 'ADD_LINE_FILTER', label: 'Consider filtering logs for specific string.', fix: { title: 'add line filter', label: '', action: { type: 'ADD_LINE_FILTER', query, }, }, }); } return hints; }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
__mocks__
---
0755
components
---
0755
configuration
---
0755
docs
---
0755
img
---
0755
migrations
---
0755
querybuilder
---
0755
LanguageProvider.test.ts
23374 bytes
0644
LanguageProvider.ts
13424 bytes
0644
LiveStreams.test.ts
7021 bytes
0644
LiveStreams.ts
2641 bytes
0644
LogContextProvider.test.ts
21477 bytes
0644
LogContextProvider.ts
14192 bytes
0644
LokiVariableSupport.test.ts
3307 bytes
0644
LokiVariableSupport.ts
984 bytes
0644
README.md
127 bytes
0644
backendResultTransformer.test.ts
5537 bytes
0644
backendResultTransformer.ts
5248 bytes
0644
dataquery.cue
1633 bytes
0644
dataquery.gen.ts
1269 bytes
0644
datasource.test.ts
67600 bytes
0644
datasource.ts
42882 bytes
0644
getDerivedFields.test.ts
6291 bytes
0644
getDerivedFields.ts
4351 bytes
0644
languageUtils.test.ts
4461 bytes
0644
languageUtils.ts
5123 bytes
0644
language_utils.test.ts
1463 bytes
0644
lineParser.test.ts
1846 bytes
0644
lineParser.ts
912 bytes
0644
liveStreamsResultTransformer.test.ts
3396 bytes
0644
liveStreamsResultTransformer.ts
2624 bytes
0644
logsTimeSplitting.test.ts
1463 bytes
0644
logsTimeSplitting.ts
1661 bytes
0644
makeTableFrames.test.ts
3834 bytes
0644
makeTableFrames.ts
2415 bytes
0644
metricTimeSplitting.test.ts
2925 bytes
0644
metricTimeSplitting.ts
1586 bytes
0644
modifyQuery.test.ts
27450 bytes
0644
modifyQuery.ts
20058 bytes
0644
module.test.ts
2975 bytes
0644
module.ts
809 bytes
0644
plugin.json
756 bytes
0644
queryHints.test.ts
7526 bytes
0644
queryHints.ts
4453 bytes
0644
querySplitting.test.ts
20808 bytes
0644
querySplitting.ts
9911 bytes
0644
queryUtils.test.ts
20063 bytes
0644
queryUtils.ts
11174 bytes
0644
responseUtils.test.ts
5757 bytes
0644
responseUtils.ts
4637 bytes
0644
sortDataFrame.test.ts
5184 bytes
0644
sortDataFrame.ts
2708 bytes
0644
streaming.test.ts
1264 bytes
0644
streaming.ts
2939 bytes
0644
syntax.test.ts
3545 bytes
0644
syntax.ts
7646 bytes
0644
tracking.test.ts
6407 bytes
0644
tracking.ts
8353 bytes
0644
types.ts
2568 bytes
0644
N4ST4R_ID | Naxtarrr