mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Fix interpolation of legendFormat (#40635)
* Prometheus: Fix interpolation of legendFormat * Fix test
This commit is contained in:
parent
c70cfe9125
commit
998ba06f39
@ -570,6 +570,45 @@ describe('PrometheusDatasource', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('applyTemplateVariables', () => {
|
||||||
|
it('should call replace function for legendFormat', () => {
|
||||||
|
const query = {
|
||||||
|
expr: 'test{job="bar"}',
|
||||||
|
legendFormat: '$legend',
|
||||||
|
refId: 'A',
|
||||||
|
};
|
||||||
|
const legend = 'baz';
|
||||||
|
templateSrvStub.replace.mockReturnValue(legend);
|
||||||
|
|
||||||
|
const interpolatedQuery = ds.applyTemplateVariables(query, { legend: { text: legend, value: legend } });
|
||||||
|
expect(interpolatedQuery.legendFormat).toBe(legend);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call replace function for expr', () => {
|
||||||
|
const query = {
|
||||||
|
expr: 'test{job="$job"}',
|
||||||
|
refId: 'A',
|
||||||
|
};
|
||||||
|
const job = 'bar';
|
||||||
|
templateSrvStub.replace.mockReturnValue(job);
|
||||||
|
|
||||||
|
const interpolatedQuery = ds.applyTemplateVariables(query, { job: { text: job, value: job } });
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('metricFindQuery', () => {
|
describe('metricFindQuery', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const query = 'query_result(topk(5,rate(http_request_duration_microseconds_count[$__interval])))';
|
const query = 'query_result(topk(5,rate(http_request_duration_microseconds_count[$__interval])))';
|
||||||
|
@ -894,6 +894,7 @@ export class PrometheusDatasource extends DataSourceWithBackend<PromQuery, PromO
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...target,
|
...target,
|
||||||
|
legendFormat: this.templateSrv.replace(target.legendFormat, variables),
|
||||||
expr: this.templateSrv.replace(target.expr, variables, this.interpolateQueryExpr),
|
expr: this.templateSrv.replace(target.expr, variables, this.interpolateQueryExpr),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user