From 2a5a4ded53102358c69ff664dab3f4bccefbabfc Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:33:33 +0200 Subject: [PATCH] Loki: Run logs volume for query when switching from trace to logs (#72268) Loki: Run logs volume for query that has no queryType (defaults to range) --- .../plugins/datasource/loki/datasource.test.ts | 18 ++++++++++++++++++ .../app/plugins/datasource/loki/datasource.ts | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/loki/datasource.test.ts b/public/app/plugins/datasource/loki/datasource.test.ts index 1cb884e9e8c..d831efdc308 100644 --- a/public/app/plugins/datasource/loki/datasource.test.ts +++ b/public/app/plugins/datasource/loki/datasource.test.ts @@ -1093,6 +1093,24 @@ describe('LokiDatasource', () => { }); describe('logs volume', () => { + // The default queryType value is Range + it('returns logs volume for query with no queryType', () => { + expect( + ds.getSupplementaryQuery( + { type: SupplementaryQueryType.LogsVolume }, + { + expr: '{label=value}', + refId: 'A', + } + ) + ).toEqual({ + expr: 'sum by (level) (count_over_time({label=value}[$__interval]))', + queryType: LokiQueryType.Range, + refId: 'log-volume-A', + supportingQueryType: SupportingQueryType.LogsVolume, + }); + }); + it('returns logs volume query for range log query', () => { expect( ds.getSupplementaryQuery( diff --git a/public/app/plugins/datasource/loki/datasource.ts b/public/app/plugins/datasource/loki/datasource.ts index d28c760e946..890ffd42814 100644 --- a/public/app/plugins/datasource/loki/datasource.ts +++ b/public/app/plugins/datasource/loki/datasource.ts @@ -194,7 +194,7 @@ export class LokiDatasource switch (options.type) { case SupplementaryQueryType.LogsVolume: // it has to be a logs-producing range-query - isQuerySuitable = !!(query.expr && isLogsQuery(query.expr) && query.queryType === LokiQueryType.Range); + isQuerySuitable = !!(expr && isLogsQuery(expr) && normalizedQuery.queryType === LokiQueryType.Range); if (!isQuerySuitable) { return undefined; } @@ -209,7 +209,7 @@ export class LokiDatasource case SupplementaryQueryType.LogsSample: // it has to be a metric query - isQuerySuitable = !!(query.expr && !isLogsQuery(query.expr)); + isQuerySuitable = !!(expr && !isLogsQuery(expr)); if (!isQuerySuitable) { return undefined; }