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)
This commit is contained in:
Ivana Huckova 2023-07-25 14:33:33 +02:00 committed by GitHub
parent c1c8b4d368
commit 2a5a4ded53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -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(

View File

@ -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;
}