From 192308aac7bc5ac04f55481a443638dfc855c596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Fri, 3 Mar 2023 10:58:28 +0100 Subject: [PATCH] loki: query splitting: better stats (#64105) --- public/app/plugins/datasource/loki/mocks.ts | 10 +++++----- .../plugins/datasource/loki/queryUtils.test.ts | 15 +++++++++------ public/app/plugins/datasource/loki/queryUtils.ts | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/public/app/plugins/datasource/loki/mocks.ts b/public/app/plugins/datasource/loki/mocks.ts index c9241709161..584b99a5106 100644 --- a/public/app/plugins/datasource/loki/mocks.ts +++ b/public/app/plugins/datasource/loki/mocks.ts @@ -152,7 +152,7 @@ export function getMockFrames() { ], meta: { stats: [ - { displayName: 'Summary: total bytes processed', value: 11 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 11 }, { displayName: 'Ingester: total reached', value: 1 }, ], }, @@ -199,7 +199,7 @@ export function getMockFrames() { ], meta: { stats: [ - { displayName: 'Summary: total bytes processed', value: 22 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 22 }, { displayName: 'Ingester: total reached', value: 2 }, ], }, @@ -225,7 +225,7 @@ export function getMockFrames() { meta: { stats: [ { displayName: 'Ingester: total reached', value: 1 }, - { displayName: 'Summary: total bytes processed', value: 11 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 11 }, ], }, length: 2, @@ -250,7 +250,7 @@ export function getMockFrames() { meta: { stats: [ { displayName: 'Ingester: total reached', value: 2 }, - { displayName: 'Summary: total bytes processed', value: 22 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 22 }, ], }, length: 2, @@ -276,7 +276,7 @@ export function getMockFrames() { meta: { stats: [ { displayName: 'Ingester: total reached', value: 2 }, - { displayName: 'Summary: total bytes processed', value: 33 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 33 }, ], }, length: 2, diff --git a/public/app/plugins/datasource/loki/queryUtils.test.ts b/public/app/plugins/datasource/loki/queryUtils.test.ts index 25cc9577c2e..3fb0d985699 100644 --- a/public/app/plugins/datasource/loki/queryUtils.test.ts +++ b/public/app/plugins/datasource/loki/queryUtils.test.ts @@ -369,6 +369,7 @@ describe('combineResponses', () => { stats: [ { displayName: 'Summary: total bytes processed', + unit: 'decbytes', value: 33, }, ], @@ -409,6 +410,7 @@ describe('combineResponses', () => { stats: [ { displayName: 'Summary: total bytes processed', + unit: 'decbytes', value: 33, }, ], @@ -449,6 +451,7 @@ describe('combineResponses', () => { stats: [ { displayName: 'Summary: total bytes processed', + unit: 'decbytes', value: 33, }, ], @@ -488,31 +491,31 @@ describe('combineResponses', () => { it('two values', () => { const responseA = makeResponse([ { displayName: 'Ingester: total reached', value: 1 }, - { displayName: 'Summary: total bytes processed', value: 11 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 11 }, ]); const responseB = makeResponse([ { displayName: 'Ingester: total reached', value: 2 }, - { displayName: 'Summary: total bytes processed', value: 22 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 22 }, ]); expect(combineResponses(responseA, responseB).data[0].meta.stats).toStrictEqual([ - { displayName: 'Summary: total bytes processed', value: 33 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 33 }, ]); }); it('one value', () => { const responseA = makeResponse([ { displayName: 'Ingester: total reached', value: 1 }, - { displayName: 'Summary: total bytes processed', value: 11 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 11 }, ]); const responseB = makeResponse(); expect(combineResponses(responseA, responseB).data[0].meta.stats).toStrictEqual([ - { displayName: 'Summary: total bytes processed', value: 11 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 11 }, ]); expect(combineResponses(responseB, responseA).data[0].meta.stats).toStrictEqual([ - { displayName: 'Summary: total bytes processed', value: 11 }, + { displayName: 'Summary: total bytes processed', unit: 'decbytes', value: 11 }, ]); }); diff --git a/public/app/plugins/datasource/loki/queryUtils.ts b/public/app/plugins/datasource/loki/queryUtils.ts index ef040bfe73d..5e5f2da7c45 100644 --- a/public/app/plugins/datasource/loki/queryUtils.ts +++ b/public/app/plugins/datasource/loki/queryUtils.ts @@ -365,7 +365,7 @@ function getCombinedMetadataStats( const sourceStat = sourceStats.find((s) => s.displayName === TOTAL_BYTES_STAT); if (sourceStat != null && destStat != null) { - return [{ value: sourceStat.value + destStat.value, displayName: TOTAL_BYTES_STAT }]; + return [{ value: sourceStat.value + destStat.value, displayName: TOTAL_BYTES_STAT, unit: destStat.unit }]; } // maybe one of them exist