diff --git a/public/app/features/logs/components/logParser.test.ts b/public/app/features/logs/components/logParser.test.ts index 764461cf95e..68487d12690 100644 --- a/public/app/features/logs/components/logParser.test.ts +++ b/public/app/features/logs/components/logParser.test.ts @@ -46,15 +46,10 @@ describe('logParser', () => { expect(getAllFields(createScenario(-0))).toHaveLength(1); }); - it('should filter out field with labels name old-loki-style frame', () => { + it('should filter out field with labels in frame', () => { const logRow = createLogRow({ entryFieldIndex: 1, dataFrame: new MutableDataFrame({ - meta: { - custom: { - frameType: 'LabeledTimeValues', - }, - }, refId: 'A', fields: [ testTimeField, diff --git a/public/app/features/logs/legacyLogsFrame.ts b/public/app/features/logs/legacyLogsFrame.ts index 7d9582ae834..c50d2eec349 100644 --- a/public/app/features/logs/legacyLogsFrame.ts +++ b/public/app/features/logs/legacyLogsFrame.ts @@ -1,6 +1,6 @@ import { DataFrame, FieldCache, FieldType, Field, Labels, FieldWithIndex } from '@grafana/data'; -import type { LogsFrame } from './logsFrame'; +import { logFrameLabelsToLabels, LogsFrame } from './logsFrame'; // take the labels from the line-field, and "stretch" it into an array // with the length of the frame (so there are the same labels for every row) @@ -15,7 +15,7 @@ function makeLabelsArray(lineField: Field, length: number): Labels[] | null { } } -// we decide if the frame is old-loki-style frame, and adjust the behavior. +// if the frame has "labels" field with type "other", adjust the behavior. // we also have to return the labels-field (if we used it), // to be able to remove it from the unused-fields, later. function makeLabelsGetter( @@ -23,11 +23,13 @@ function makeLabelsGetter( lineField: Field, frame: DataFrame ): [FieldWithIndex | null, () => Labels[] | null] { - if (frame.meta?.custom?.frameType === 'LabeledTimeValues') { - const labelsField = cache.getFieldByName('labels'); - return labelsField === undefined ? [null, () => null] : [labelsField, () => labelsField.values]; + // If we have labels field with type "other", use that + const labelsField = cache.getFieldByName('labels'); + if (labelsField !== undefined && labelsField.type === FieldType.other) { + const values = labelsField.values.map(logFrameLabelsToLabels); + return [labelsField, () => values]; } else { - // we use the labels on the line-field, and make an array with it + // Otherwise we use the labels on the line-field, and make an array with it return [null, () => makeLabelsArray(lineField, frame.length)]; } } diff --git a/public/app/features/logs/logsFrame.test.ts b/public/app/features/logs/logsFrame.test.ts index e57832ee5d1..dda099a2886 100644 --- a/public/app/features/logs/logsFrame.test.ts +++ b/public/app/features/logs/logsFrame.test.ts @@ -96,6 +96,39 @@ describe('parseLogsFrame should parse different logs-dataframe formats', () => { expect(result?.extraFields).toStrictEqual([]); }); + it('should parse frames with labels field of type other', () => { + const time = makeTime('Time', [1687185711795, 1687185711995]); + const line = makeString('Line', ['line1', 'line2']); + const id = makeString('id', ['id1', 'id2']); + const ns = makeString('tsNs', ['1687185711795123456', '1687185711995987654']); + const labels = makeObject('labels', [ + { counter: '38141', label: 'val2', level: 'warning' }, + { counter: '38143', label: 'val2', level: 'info' }, + ]); + + const result = parseLogsFrame({ + fields: [labels, time, line, ns, id], + length: 2, + }); + + expect(result).not.toBeNull(); + + expect(result!.timeField.values[0]).toBe(time.values[0]); + expect(result!.bodyField.values[0]).toBe(line.values[0]); + expect(result!.idField?.values[0]).toBe(id.values[0]); + expect(result!.timeNanosecondField?.values[0]).toBe(ns.values[0]); + expect(result!.severityField).toBeNull(); + expect(result!.getLogFrameLabels()).toStrictEqual([ + { counter: '38141', label: 'val2', level: 'warning' }, + { counter: '38143', label: 'val2', level: 'info' }, + ]); + expect(result!.getLogFrameLabelsAsLabels()).toStrictEqual([ + { counter: '38141', label: 'val2', level: 'warning' }, + { counter: '38143', label: 'val2', level: 'info' }, + ]); + expect(result?.extraFields).toStrictEqual([]); + }); + it('should parse a Loki-style frame (single-frame, labels-in-json)', () => { const time = makeTime('Time', [1687185711795, 1687185711995]); const line = makeString('Line', ['line1', 'line2']); @@ -145,11 +178,6 @@ describe('parseLogsFrame should parse different logs-dataframe formats', () => { const level = makeString('level', ['info', 'error']); const result = parseLogsFrame({ - meta: { - custom: { - frameType: 'LabeledTimeValues', - }, - }, fields: [time, line, source, level, host], length: 2, }); diff --git a/public/app/features/logs/logsModel.test.ts b/public/app/features/logs/logsModel.test.ts index 2c2443bb479..78fd89cd80d 100644 --- a/public/app/features/logs/logsModel.test.ts +++ b/public/app/features/logs/logsModel.test.ts @@ -436,9 +436,6 @@ describe('dataFrameToLogsModel', () => { ], meta: { limit: 1000, - custom: { - frameType: 'LabeledTimeValues', - }, }, refId: 'A', }), @@ -516,25 +513,15 @@ describe('dataFrameToLogsModel', () => { type: FieldType.string, values: ['line1'], }; - - const meta = { - custom: { - frameType: 'LabeledTimeValues', - }, - }; - const frame1 = new MutableDataFrame({ - meta, fields: [labels, time, line], }); const frame2 = new MutableDataFrame({ - meta, fields: [time, labels, line], }); const frame3 = new MutableDataFrame({ - meta, fields: [time, line, labels], }); diff --git a/public/app/features/logs/logsModel_parse.test.ts b/public/app/features/logs/logsModel_parse.test.ts index cc08a90dd7d..e87b304c83c 100644 --- a/public/app/features/logs/logsModel_parse.test.ts +++ b/public/app/features/logs/logsModel_parse.test.ts @@ -373,7 +373,7 @@ describe('logSeriesToLogsModel should parse different logs-dataframe formats', ( expect(logSeriesToLogsModel(frames)).toStrictEqual(expected); }); - it('should parse a Loki-style frame (single-frame, labels-in-json)', () => { + it('should parse a frame with a labels field (single-frame, labels-in-json)', () => { const frames: DataFrame[] = [ { refId: 'A', @@ -427,11 +427,6 @@ describe('logSeriesToLogsModel should parse different logs-dataframe formats', ( }, ], length: 3, - meta: { - custom: { - frameType: 'LabeledTimeValues', - }, - }, }, ];