Prometheus: interpolate variable for step field (#36437)

* Prometheus: interpolate variable for step

* Add test for variable interpolation
This commit is contained in:
Zoltán Bedi 2021-07-07 08:43:46 +02:00 committed by GitHub
parent 1655ff1e49
commit 55e763b4cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -553,6 +553,23 @@ describe('PrometheusDatasource', () => {
});
});
describe('interpolateVariablesInQueries', () => {
it('should call replace function 2 times', () => {
const query = {
expr: 'test{job="testjob"}',
format: 'time_series',
interval: '$Interval',
refId: 'A',
};
const interval = '10m';
templateSrvStub.replace.mockReturnValue(interval);
const queries = ds.interpolateVariablesInQueries([query], { Interval: { text: interval, value: interval } });
expect(templateSrvStub.replace).toBeCalledTimes(2);
expect(queries[0].interval).toBe(interval);
});
});
describe('metricFindQuery', () => {
beforeEach(() => {
const query = 'query_result(topk(5,rate(http_request_duration_microseconds_count[$__interval])))';

View File

@ -735,6 +735,7 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
...query,
datasource: this.name,
expr: this.templateSrv.replace(query.expr, scopedVars, this.interpolateQueryExpr),
interval: this.templateSrv.replace(query.interval, scopedVars),
};
return expandedQuery;
});