mirror of
https://github.com/grafana/grafana.git
synced 2025-01-26 16:27:02 -06:00
explore: don't parse log levels if provided by field or label (#17180)
If a field or a label named level is returned from datasource that is used as log level for the logs result instead of parsing the log level from the message. Closes #17122
This commit is contained in:
parent
04d473b3e5
commit
a07296bf24
@ -23,6 +23,15 @@ export function getLogLevel(line: string): LogLevel {
|
||||
return LogLevel.unknown;
|
||||
}
|
||||
|
||||
export function getLogLevelFromKey(key: string): LogLevel {
|
||||
const level = (LogLevel as any)[key];
|
||||
if (level) {
|
||||
return level;
|
||||
}
|
||||
|
||||
return LogLevel.unknown;
|
||||
}
|
||||
|
||||
export function addLogLevelToSeries(series: SeriesData, lineIndex: number): SeriesData {
|
||||
return {
|
||||
...series, // Keeps Tags, RefID etc
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
toLegacyResponseData,
|
||||
FieldCache,
|
||||
FieldType,
|
||||
getLogLevelFromKey,
|
||||
LogRowModel,
|
||||
LogsModel,
|
||||
LogsMetaItem,
|
||||
@ -368,7 +369,17 @@ export function processLogSeriesRow(
|
||||
const timeEpochMs = time.valueOf();
|
||||
const timeFromNow = time.fromNow();
|
||||
const timeLocal = time.format('YYYY-MM-DD HH:mm:ss');
|
||||
const logLevel = getLogLevel(message);
|
||||
|
||||
let logLevel = LogLevel.unknown;
|
||||
const logLevelField = fieldCache.getFieldByName('level');
|
||||
|
||||
if (logLevelField) {
|
||||
logLevel = getLogLevelFromKey(row[logLevelField.index]);
|
||||
} else if (series.labels && Object.keys(series.labels).indexOf('level') !== -1) {
|
||||
logLevel = getLogLevelFromKey(series.labels['level']);
|
||||
} else {
|
||||
logLevel = getLogLevel(message);
|
||||
}
|
||||
const hasAnsi = hasAnsiCodes(message);
|
||||
const searchWords = series.meta && series.meta.searchWords ? series.meta.searchWords : [];
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SeriesData, FieldType, LogsModel, LogsMetaKind, LogsDedupStrategy } from '@grafana/ui';
|
||||
import { SeriesData, FieldType, LogsModel, LogsMetaKind, LogsDedupStrategy, LogLevel } from '@grafana/ui';
|
||||
import {
|
||||
dedupLogRows,
|
||||
calculateFieldStats,
|
||||
@ -460,8 +460,12 @@ describe('seriesDataToLogsModel', () => {
|
||||
name: 'message',
|
||||
type: FieldType.string,
|
||||
},
|
||||
{
|
||||
name: 'level',
|
||||
type: FieldType.string,
|
||||
},
|
||||
],
|
||||
rows: [['1970-01-01T00:00:01Z', 'WARN boooo']],
|
||||
rows: [['1970-01-01T00:00:01Z', 'WARN boooo', 'dbug']],
|
||||
},
|
||||
];
|
||||
const logsModel = seriesDataToLogsModel(series, 0);
|
||||
@ -470,7 +474,7 @@ describe('seriesDataToLogsModel', () => {
|
||||
{
|
||||
entry: 'WARN boooo',
|
||||
labels: undefined,
|
||||
logLevel: 'warning',
|
||||
logLevel: LogLevel.debug,
|
||||
uniqueLabels: {},
|
||||
},
|
||||
]);
|
||||
@ -482,6 +486,7 @@ describe('seriesDataToLogsModel', () => {
|
||||
labels: {
|
||||
foo: 'bar',
|
||||
baz: '1',
|
||||
level: 'dbug',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
@ -500,6 +505,7 @@ describe('seriesDataToLogsModel', () => {
|
||||
labels: {
|
||||
foo: 'bar',
|
||||
baz: '2',
|
||||
level: 'err',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
@ -521,19 +527,19 @@ describe('seriesDataToLogsModel', () => {
|
||||
{
|
||||
entry: 'INFO 2',
|
||||
labels: { foo: 'bar', baz: '2' },
|
||||
logLevel: 'info',
|
||||
logLevel: LogLevel.error,
|
||||
uniqueLabels: { baz: '2' },
|
||||
},
|
||||
{
|
||||
entry: 'WARN boooo',
|
||||
labels: { foo: 'bar', baz: '1' },
|
||||
logLevel: 'warning',
|
||||
logLevel: LogLevel.debug,
|
||||
uniqueLabels: { baz: '1' },
|
||||
},
|
||||
{
|
||||
entry: 'INFO 1',
|
||||
labels: { foo: 'bar', baz: '2' },
|
||||
logLevel: 'info',
|
||||
logLevel: LogLevel.error,
|
||||
uniqueLabels: { baz: '2' },
|
||||
},
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user