loki: no histogram for instant queries (#50711)

This commit is contained in:
Gábor Farkas
2022-06-20 11:31:36 +02:00
committed by GitHub
parent f35aa8c7d7
commit 48a258f515
2 changed files with 27 additions and 12 deletions

View File

@@ -24,7 +24,7 @@ import { CustomVariableModel } from '../../../features/variables/types';
import { isMetricsQuery, LokiDatasource } from './datasource';
import { makeMockLokiDatasource } from './mocks';
import { LokiQuery } from './types';
import { LokiQuery, LokiQueryType } from './types';
const rawRange = {
from: toUtc('2018-04-25 10:00'),
@@ -758,6 +758,15 @@ describe('LokiDatasource', () => {
expect(ds.getLogsVolumeDataProvider(options)).toBeDefined();
});
it('does not create provider if there is only an instant logs query', () => {
const ds = createLokiDSForTests();
const options = getQueryOptions<LokiQuery>({
targets: [{ expr: '{label=value', refId: 'A', queryType: LokiQueryType.Instant }],
});
expect(ds.getLogsVolumeDataProvider(options)).not.toBeDefined();
});
});
describe('importing queries', () => {

View File

@@ -104,22 +104,28 @@ export class LokiDatasource
}
getLogsVolumeDataProvider(request: DataQueryRequest<LokiQuery>): Observable<DataQueryResponse> | undefined {
const isLogsVolumeAvailable = request.targets.some((target) => target.expr && !isMetricsQuery(target.expr));
const isQuerySuitable = (query: LokiQuery) => {
const normalized = getNormalizedLokiQuery(query);
const { expr } = normalized;
// it has to be a logs-producing range-query
return expr && !isMetricsQuery(expr) && normalized.queryType === LokiQueryType.Range;
};
const isLogsVolumeAvailable = request.targets.some(isQuerySuitable);
if (!isLogsVolumeAvailable) {
return undefined;
}
const logsVolumeRequest = cloneDeep(request);
logsVolumeRequest.targets = logsVolumeRequest.targets
.filter((target) => target.expr && !isMetricsQuery(target.expr))
.map((target) => {
return {
...target,
instant: false,
volumeQuery: true,
expr: `sum by (level) (count_over_time(${target.expr}[$__interval]))`,
};
});
logsVolumeRequest.targets = logsVolumeRequest.targets.filter(isQuerySuitable).map((target) => {
return {
...target,
instant: false,
volumeQuery: true,
expr: `sum by (level) (count_over_time(${target.expr}[$__interval]))`,
};
});
return queryLogsVolume(this, logsVolumeRequest, {
extractLevel,