From 061055fac9228e701fa2b8b529211ea458c9e899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Fri, 20 May 2022 17:27:49 +0200 Subject: [PATCH] loki: dataframes: do not set field.config.DisplayName (#49317) --- public/app/plugins/datasource/loki/datasource.test.ts | 2 +- public/app/plugins/datasource/loki/datasource.ts | 6 +++--- .../app/plugins/datasource/loki/live_streams.test.ts | 8 ++++---- public/app/plugins/datasource/loki/live_streams.ts | 6 +++--- .../plugins/datasource/loki/result_transformer.test.ts | 2 +- .../app/plugins/datasource/loki/result_transformer.ts | 10 +++++----- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/public/app/plugins/datasource/loki/datasource.test.ts b/public/app/plugins/datasource/loki/datasource.test.ts index c71756edd43..c792e24a564 100644 --- a/public/app/plugins/datasource/loki/datasource.test.ts +++ b/public/app/plugins/datasource/loki/datasource.test.ts @@ -369,7 +369,7 @@ describe('LokiDatasource', () => { const dataFrame = result.data[0] as DataFrame; const fieldCache = new FieldCache(dataFrame); - expect(fieldCache.getFieldByName('line')?.values.get(0)).toBe('hello'); + expect(fieldCache.getFieldByName('Line')?.values.get(0)).toBe('hello'); expect(dataFrame.meta?.limit).toBe(20); expect(dataFrame.meta?.searchWords).toEqual(['foo']); }); diff --git a/public/app/plugins/datasource/loki/datasource.ts b/public/app/plugins/datasource/loki/datasource.ts index bf8f70c1a79..0c846361316 100644 --- a/public/app/plugins/datasource/loki/datasource.ts +++ b/public/app/plugins/datasource/loki/datasource.ts @@ -765,7 +765,7 @@ export class LokiDatasource const splitKeys: string[] = tagKeys.split(',').filter((v: string) => v !== ''); for (const frame of data) { - const view = new DataFrameView<{ ts: string; line: string; labels: Labels }>(frame); + const view = new DataFrameView<{ Time: string; Line: string; labels: Labels }>(frame); view.forEach((row) => { const { labels } = row; @@ -791,9 +791,9 @@ export class LokiDatasource const tags = Array.from(new Set(maybeDuplicatedTags)); annotations.push({ - time: new Date(row.ts).valueOf(), + time: new Date(row.Time).valueOf(), title: renderLegendFormat(titleFormat, labels), - text: renderLegendFormat(textFormat, labels) || row.line, + text: renderLegendFormat(textFormat, labels) || row.Line, tags, }); }); diff --git a/public/app/plugins/datasource/loki/live_streams.test.ts b/public/app/plugins/datasource/loki/live_streams.test.ts index 8919e5d71fa..addc80cb44c 100644 --- a/public/app/plugins/datasource/loki/live_streams.test.ts +++ b/public/app/plugins/datasource/loki/live_streams.test.ts @@ -48,10 +48,10 @@ describe('Live Stream Tests', () => { const view = new DataFrameView(val[0]); const last = { ...view.get(view.length - 1) }; expect(last).toEqual({ - ts: '2019-08-28T20:50:40.118Z', + Time: '2019-08-28T20:50:40.118Z', tsNs: '1567025440118944705', id: '25d81461-a66f-53ff-98d5-e39515af4735_A', - line: 'Kittens', + Line: 'Kittens', labels: { filename: '/var/log/sntpc.log' }, }); }, @@ -148,8 +148,8 @@ describe('Live Stream Tests', () => { const firstLog = { ...view.get(0) }; const secondLog = { ...view.get(1) }; - expect(firstLog.line).toBe('Kittens'); - expect(secondLog.line).toBe('Doggos'); + expect(firstLog.Line).toBe('Kittens'); + expect(secondLog.Line).toBe('Doggos'); expect(retries).toBe(2); }); }); diff --git a/public/app/plugins/datasource/loki/live_streams.ts b/public/app/plugins/datasource/loki/live_streams.ts index 82319bec041..e917b90ea26 100644 --- a/public/app/plugins/datasource/loki/live_streams.ts +++ b/public/app/plugins/datasource/loki/live_streams.ts @@ -33,10 +33,10 @@ export class LiveStreams { const data = new CircularDataFrame({ capacity: target.size }); data.addField({ name: 'labels', type: FieldType.other }); // The labels for each line - data.addField({ name: 'ts', type: FieldType.time, config: { displayName: 'Time' } }); - data.addField({ name: 'line', type: FieldType.string }).labels = parseLabels(target.query); + data.addField({ name: 'Time', type: FieldType.time, config: {} }); + data.addField({ name: 'Line', type: FieldType.string }).labels = parseLabels(target.query); data.addField({ name: 'id', type: FieldType.string }); - data.addField({ name: 'tsNs', type: FieldType.time, config: { displayName: 'Time ns' } }); + data.addField({ name: 'tsNs', type: FieldType.time, config: {} }); data.meta = { ...data.meta, preferredVisualisationType: 'logs' }; data.refId = target.refId; diff --git a/public/app/plugins/datasource/loki/result_transformer.test.ts b/public/app/plugins/datasource/loki/result_transformer.test.ts index 8ed8a779dde..17c8ddcca94 100644 --- a/public/app/plugins/datasource/loki/result_transformer.test.ts +++ b/public/app/plugins/datasource/loki/result_transformer.test.ts @@ -242,7 +242,7 @@ describe('loki result transformer', () => { describe('enhanceDataFrame', () => { it('adds links to fields', () => { - const df = new MutableDataFrame({ fields: [{ name: 'line', values: ['nothing', 'trace1=1234', 'trace2=foo'] }] }); + const df = new MutableDataFrame({ fields: [{ name: 'Line', values: ['nothing', 'trace1=1234', 'trace2=foo'] }] }); ResultTransformer.enhanceDataFrame(df, { derivedFields: [ { diff --git a/public/app/plugins/datasource/loki/result_transformer.ts b/public/app/plugins/datasource/loki/result_transformer.ts index 31ff9fd7ec2..ca976959809 100644 --- a/public/app/plugins/datasource/loki/result_transformer.ts +++ b/public/app/plugins/datasource/loki/result_transformer.ts @@ -92,9 +92,9 @@ function constructDataFrame( refId, fields: [ { name: 'labels', type: FieldType.other, config: {}, values: labels }, - { name: 'ts', type: FieldType.time, config: { displayName: 'Time' }, values: times }, // Time - { name: 'line', type: FieldType.string, config: {}, values: lines }, // Line - needs to be the first field with string type - { name: 'tsNs', type: FieldType.time, config: { displayName: 'Time ns' }, values: timesNs }, // Time + { name: 'Time', type: FieldType.time, config: {}, values: times }, // Time + { name: 'Line', type: FieldType.string, config: {}, values: lines }, // Line - needs to be the first field with string type + { name: 'tsNs', type: FieldType.time, config: {}, values: timesNs }, // Time { name: 'id', type: FieldType.string, config: {}, values: uids }, ], length: times.length, @@ -391,9 +391,9 @@ export const enhanceDataFrame = (dataFrame: DataFrame, config: LokiOptions | nul const newFields = Object.values(derivedFieldsGrouped).map(fieldFromDerivedFieldConfig); const view = new DataFrameView(dataFrame); - view.forEach((row: { line: string }) => { + view.forEach((row: { Line: string }) => { for (const field of newFields) { - const logMatch = row.line.match(derivedFieldsGrouped[field.name][0].matcherRegex); + const logMatch = row.Line.match(derivedFieldsGrouped[field.name][0].matcherRegex); field.values.add(logMatch && logMatch[1]); } });