From f7355668e7c021cd8ce8292f33832296d73557ac Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Mon, 21 Aug 2023 14:19:20 +0200 Subject: [PATCH] Query splitting: combine nanos attribute con time fields (#73505) --- .../datasource/loki/responseUtils.test.ts | 75 +++++++++++++++++++ .../plugins/datasource/loki/responseUtils.ts | 4 + 2 files changed, 79 insertions(+) diff --git a/public/app/plugins/datasource/loki/responseUtils.test.ts b/public/app/plugins/datasource/loki/responseUtils.test.ts index cde7de2956e..fe033a30854 100644 --- a/public/app/plugins/datasource/loki/responseUtils.test.ts +++ b/public/app/plugins/datasource/loki/responseUtils.test.ts @@ -403,6 +403,81 @@ describe('combineResponses', () => { expect(combined.errors?.[1]?.message).toBe('errorB'); }); + it('combines frames with nanoseconds', () => { + const { logFrameA, logFrameB } = getMockFrames(); + logFrameA.fields[0].nanos = [333333, 444444]; + logFrameB.fields[0].nanos = [111111, 222222]; + const responseA: DataQueryResponse = { + data: [logFrameA], + }; + const responseB: DataQueryResponse = { + data: [logFrameB], + }; + expect(combineResponses(responseA, responseB)).toEqual({ + data: [ + { + fields: [ + { + config: {}, + name: 'Time', + type: 'time', + values: [1, 2, 3, 4], + nanos: [111111, 222222, 333333, 444444], + }, + { + config: {}, + name: 'Line', + type: 'string', + values: ['line3', 'line4', 'line1', 'line2'], + }, + { + config: {}, + name: 'labels', + type: 'other', + values: [ + { + otherLabel: 'other value', + }, + { + label: 'value', + }, + { + otherLabel: 'other value', + }, + ], + }, + { + config: {}, + name: 'tsNs', + type: 'string', + values: ['1000000', '2000000', '3000000', '4000000'], + }, + { + config: {}, + name: 'id', + type: 'string', + values: ['id3', 'id4', 'id1', 'id2'], + }, + ], + length: 4, + meta: { + custom: { + frameType: 'LabeledTimeValues', + }, + stats: [ + { + displayName: 'Summary: total bytes processed', + unit: 'decbytes', + value: 33, + }, + ], + }, + refId: 'A', + }, + ], + }); + }); + describe('combine stats', () => { const { metricFrameA } = getMockFrames(); const makeResponse = (stats?: QueryResultMetaStat[]): DataQueryResponse => ({ diff --git a/public/app/plugins/datasource/loki/responseUtils.ts b/public/app/plugins/datasource/loki/responseUtils.ts index 7207851bbb9..b2afbe32429 100644 --- a/public/app/plugins/datasource/loki/responseUtils.ts +++ b/public/app/plugins/datasource/loki/responseUtils.ts @@ -203,6 +203,10 @@ function combineFrames(dest: DataFrame, source: DataFrame) { const totalFields = dest.fields.length; for (let i = 0; i < totalFields; i++) { dest.fields[i].values = [].concat.apply(source.fields[i].values, dest.fields[i].values); + if (source.fields[i].nanos) { + const nanos: number[] = dest.fields[i].nanos?.slice() || []; + dest.fields[i].nanos = source.fields[i].nanos?.concat(nanos); + } } dest.length += source.length; dest.meta = {