/usr/share/grafana/public/app/plugins/datasource/loki
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
..
Edit
CHANGELOG.md
Edit
LanguageProvider.test.ts
Edit
LanguageProvider.ts
Edit
LiveStreams.test.ts
Edit
LiveStreams.ts
Edit
LogContextProvider.test.ts
Edit
LogContextProvider.ts
Edit
LokiVariableSupport.test.ts
Edit
LokiVariableSupport.ts
Edit
README.md
Edit
backendResultTransformer.test.ts
Edit
backendResultTransformer.ts
Edit
components
Edit
configuration
Edit
dataquery.cue
Edit
dataquery.gen.ts
Edit
datasource.test.ts
Edit
datasource.ts
Edit
dist
Edit
docs
Edit
getDerivedFields.test.ts
Edit
getDerivedFields.ts
Edit
img
Edit
jest-setup.js
Edit
jest.config.js
Edit
languageUtils.test.ts
Edit
languageUtils.ts
Edit
language_utils.test.ts
Edit
lineParser.test.ts
Edit
lineParser.ts
Edit
liveStreamsResultTransformer.test.ts
Edit
liveStreamsResultTransformer.ts
Edit
logsTimeSplitting.test.ts
Edit
logsTimeSplitting.ts
Edit
makeTableFrames.test.ts
Edit
makeTableFrames.ts
Edit
mergeResponses.test.ts
Edit
mergeResponses.ts
Edit
metricTimeSplitting.test.ts
Edit
metricTimeSplitting.ts
Edit
migrations
Edit
mocks
Edit
modifyQuery.test.ts
Edit
modifyQuery.ts
Edit
module.test.ts
Edit
module.ts
Edit
package.json
Edit
plugin.json
Edit
project.json
Edit
queryHints.test.ts
Edit
queryHints.ts
Edit
querySplitting.test.ts
Edit
querySplitting.ts
Edit
queryUtils.test.ts
Edit
queryUtils.ts
Edit
querybuilder
Edit
responseUtils.test.ts
Edit
responseUtils.ts
Edit
shardQuerySplitting.test.ts
Edit
shardQuerySplitting.ts
Edit
sortDataFrame.test.ts
Edit
sortDataFrame.ts
Edit
streaming.test.ts
Edit
streaming.ts
Edit
syntax.test.ts
Edit
syntax.ts
Edit
tracking.test.ts
Edit
tracking.ts
Edit
tsconfig.json
Edit
types.ts
Edit
webpack.config.ts
Edit