mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Fix interpolation of variables in Annotation queries (#43459)
This commit is contained in:
parent
cd93c6cdc0
commit
f63c2e4bc4
@ -1062,6 +1062,31 @@ describe('PrometheusDatasource', () => {
|
||||
expect(results.map((result) => [result.time, result.timeEnd])).toEqual([[120000, 120000]]);
|
||||
});
|
||||
});
|
||||
describe('with template variables', () => {
|
||||
const originalReplaceMock = jest.fn((a: string, ...rest: any) => a);
|
||||
afterAll(() => {
|
||||
templateSrvStub.replace = originalReplaceMock;
|
||||
});
|
||||
|
||||
it('should interpolate variables in query expr', () => {
|
||||
const query = {
|
||||
...options,
|
||||
annotation: {
|
||||
...options.annotation,
|
||||
expr: '$variable',
|
||||
},
|
||||
range: {
|
||||
from: time({ seconds: 1 }),
|
||||
to: time({ seconds: 2 }),
|
||||
},
|
||||
};
|
||||
const interpolated = 'interpolated_expr';
|
||||
templateSrvStub.replace.mockReturnValue(interpolated);
|
||||
ds.annotationQuery(query);
|
||||
const req = fetchMock.mock.calls[0][0];
|
||||
expect(req.data.queries[0].expr).toBe(interpolated);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('When resultFormat is table and instant = true', () => {
|
||||
|
@ -688,7 +688,7 @@ export class PrometheusDatasource
|
||||
data: {
|
||||
from: (this.getPrometheusTime(options.range.from, false) * 1000).toString(),
|
||||
to: (this.getPrometheusTime(options.range.to, true) * 1000).toString(),
|
||||
queries: [queryModel],
|
||||
queries: [this.applyTemplateVariables(queryModel, {})],
|
||||
},
|
||||
requestId: `prom-query-${annotation.name}`,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user