mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki/Prometheus: Fix adding of ad hoc filters when jumping from dashboard to explore (#55915)
* Loki, Prometheus: Fix adding of ad hoc filters when jumping from dashbaord to explore * Update
This commit is contained in:
parent
9cf1f2224c
commit
21a99fba7e
@ -252,6 +252,22 @@ describe('LokiDatasource', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when running interpolateVariablesInQueries', () => {
|
||||
it('should call addAdHocFilters', () => {
|
||||
const ds = createLokiDatasource(templateSrvStub);
|
||||
ds.addAdHocFilters = jest.fn();
|
||||
const expr = 'rate({bar="baz", job="foo"} [5m]';
|
||||
const queries = [
|
||||
{
|
||||
refId: 'A',
|
||||
expr,
|
||||
},
|
||||
];
|
||||
ds.interpolateVariablesInQueries(queries, {});
|
||||
expect(ds.addAdHocFilters).toHaveBeenCalledWith(expr);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when performing testDataSource', () => {
|
||||
let ds: LokiDatasource;
|
||||
beforeEach(() => {
|
||||
|
@ -272,7 +272,7 @@ export class LokiDatasource
|
||||
expandedQueries = queries.map((query) => ({
|
||||
...query,
|
||||
datasource: this.getRef(),
|
||||
expr: this.templateSrv.replace(query.expr, scopedVars, this.interpolateQueryExpr),
|
||||
expr: this.addAdHocFilters(this.templateSrv.replace(query.expr, scopedVars, this.interpolateQueryExpr)),
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -624,6 +624,18 @@ describe('PrometheusDatasource', () => {
|
||||
expect(templateSrvStub.replace).toBeCalledTimes(2);
|
||||
expect(queries[0].interval).toBe(interval);
|
||||
});
|
||||
|
||||
it('should call enhanceExprWithAdHocFilters', () => {
|
||||
ds.enhanceExprWithAdHocFilters = jest.fn();
|
||||
const queries = [
|
||||
{
|
||||
refId: 'A',
|
||||
expr: 'rate({bar="baz", job="foo"} [5m]',
|
||||
},
|
||||
];
|
||||
ds.interpolateVariablesInQueries(queries, {});
|
||||
expect(ds.enhanceExprWithAdHocFilters).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('applyTemplateVariables', () => {
|
||||
|
@ -1001,7 +1001,9 @@ export class PrometheusDatasource
|
||||
const expandedQuery = {
|
||||
...query,
|
||||
datasource: this.getRef(),
|
||||
expr: this.templateSrv.replace(query.expr, scopedVars, this.interpolateQueryExpr),
|
||||
expr: this.enhanceExprWithAdHocFilters(
|
||||
this.templateSrv.replace(query.expr, scopedVars, this.interpolateQueryExpr)
|
||||
),
|
||||
interval: this.templateSrv.replace(query.interval, scopedVars),
|
||||
};
|
||||
return expandedQuery;
|
||||
|
Loading…
Reference in New Issue
Block a user