Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loki: Run logs volume for query when switching from trace to logs #72268

Merged
merged 1 commit into from Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions public/app/plugins/datasource/loki/datasource.test.ts
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions public/app/plugins/datasource/loki/datasource.ts
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down