mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
Prometheus: Interpolate template variables in interval (#42637)
* Interpolate interval * Add test
This commit is contained in:
parent
d1c7db5365
commit
5cbb4a0a2d
@ -591,6 +591,19 @@ describe('PrometheusDatasource', () => {
|
||||
expect(interpolatedQuery.legendFormat).toBe(legend);
|
||||
});
|
||||
|
||||
it('should call replace function for interval', () => {
|
||||
const query = {
|
||||
expr: 'test{job="bar"}',
|
||||
interval: '$step',
|
||||
refId: 'A',
|
||||
};
|
||||
const step = '5s';
|
||||
templateSrvStub.replace.mockReturnValue(step);
|
||||
|
||||
const interpolatedQuery = ds.applyTemplateVariables(query, { step: { text: step, value: step } });
|
||||
expect(interpolatedQuery.interval).toBe(step);
|
||||
});
|
||||
|
||||
it('should call replace function for expr', () => {
|
||||
const query = {
|
||||
expr: 'test{job="$job"}',
|
||||
@ -603,19 +616,6 @@ describe('PrometheusDatasource', () => {
|
||||
expect(interpolatedQuery.expr).toBe(job);
|
||||
});
|
||||
|
||||
it('should not call replace function for interval', () => {
|
||||
const query = {
|
||||
expr: 'test{job="bar"}',
|
||||
interval: '$interval',
|
||||
refId: 'A',
|
||||
};
|
||||
const interval = '10s';
|
||||
templateSrvStub.replace.mockReturnValue(interval);
|
||||
|
||||
const interpolatedQuery = ds.applyTemplateVariables(query, { interval: { text: interval, value: interval } });
|
||||
expect(interpolatedQuery.interval).not.toBe(interval);
|
||||
});
|
||||
|
||||
it('should add ad-hoc filters to expr', () => {
|
||||
templateSrvStub.replace = jest.fn((a: string) => a);
|
||||
templateSrvStub.getAdhocFilters.mockReturnValue([
|
||||
|
@ -961,6 +961,7 @@ export class PrometheusDatasource extends DataSourceWithBackend<PromQuery, PromO
|
||||
...target,
|
||||
legendFormat: this.templateSrv.replace(target.legendFormat, variables),
|
||||
expr: this.templateSrv.replace(expr, variables, this.interpolateQueryExpr),
|
||||
interval: this.templateSrv.replace(target.interval, variables),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user