loki: handle ad hoc filters in backend mode (#50135) (#50145)

(cherry picked from commit 6011c373ae)
This commit is contained in:
Gábor Farkas
2022-06-03 09:15:12 +00:00
committed by GitHub
parent ccee1f7f18
commit 493d43449c
2 changed files with 12 additions and 1 deletions
@@ -1058,6 +1058,15 @@ describe('isMetricsQuery', () => {
});
});
describe('applyTemplateVariables', () => {
it('should add the adhoc filter to the query', () => {
const ds = createLokiDSForTests();
const spy = jest.spyOn(ds, 'addAdHocFilters');
ds.applyTemplateVariables({ expr: '{test}', refId: 'A' }, {});
expect(spy).toHaveBeenCalledWith('{test}');
});
});
function assertAdHocFilters(query: string, expectedResults: string, ds: LokiDatasource) {
const lokiQuery: LokiQuery = { refId: 'A', expr: query };
const result = ds.addAdHocFilters(lokiQuery.expr);
@@ -889,10 +889,12 @@ export class LokiDatasource
// We want to interpolate these variables on backend
const { __interval, __interval_ms, ...rest } = scopedVars;
const exprWithAdHoc = this.addAdHocFilters(target.expr);
return {
...target,
legendFormat: this.templateSrv.replace(target.legendFormat, rest),
expr: this.templateSrv.replace(target.expr, rest, this.interpolateQueryExpr),
expr: this.templateSrv.replace(exprWithAdHoc, rest, this.interpolateQueryExpr),
};
}