Loki/Prometheus: Fix adding of ad hoc filters when jumping from dashboard to explore (#55915) (#55992)

* Loki, Prometheus: Fix adding of ad hoc filters when jumping from dashbaord to explore

* Update

(cherry picked from commit 21a99fba7e)

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot) 2022-09-29 11:47:37 +00:00 committed by GitHub
parent 29826e0eb8
commit 08d12df9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 2 deletions

View File

@ -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(() => {

View File

@ -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)),
}));
}

View File

@ -622,6 +622,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', () => {

View File

@ -1002,7 +1002,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;