Prometheus: Fix interpolation of variables in Annotation queries (#43459)
This commit is contained in:
@@ -1062,6 +1062,31 @@ describe('PrometheusDatasource', () => {
|
|||||||
expect(results.map((result) => [result.time, result.timeEnd])).toEqual([[120000, 120000]]);
|
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', () => {
|
describe('When resultFormat is table and instant = true', () => {
|
||||||
|
|||||||
@@ -688,7 +688,7 @@ export class PrometheusDatasource
|
|||||||
data: {
|
data: {
|
||||||
from: (this.getPrometheusTime(options.range.from, false) * 1000).toString(),
|
from: (this.getPrometheusTime(options.range.from, false) * 1000).toString(),
|
||||||
to: (this.getPrometheusTime(options.range.to, true) * 1000).toString(),
|
to: (this.getPrometheusTime(options.range.to, true) * 1000).toString(),
|
||||||
queries: [queryModel],
|
queries: [this.applyTemplateVariables(queryModel, {})],
|
||||||
},
|
},
|
||||||
requestId: `prom-query-${annotation.name}`,
|
requestId: `prom-query-${annotation.name}`,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user