mirror of
https://github.com/grafana/grafana.git
synced 2024-12-30 10:47:30 -06:00
loki: handle ad hoc filters in backend mode (#50135)
* loki: handle ad hoc filters in backend mode * devenv: better loki fake data * added test
This commit is contained in:
parent
468ed68d64
commit
6011c373ae
@ -125,8 +125,8 @@ async function main() {
|
||||
await sleep(getNextSineWaveSleepDuration());
|
||||
const timestampMs = new Date().getTime();
|
||||
const item = getRandomLogItem(step + 1)
|
||||
lokiSendLogLine(timestampMs, JSON.stringify(item), {place:'moon'});
|
||||
lokiSendLogLine(timestampMs, logFmtLine(item), {place:'luna'});
|
||||
lokiSendLogLine(timestampMs, JSON.stringify(item), {place:'moon', source: 'data'});
|
||||
lokiSendLogLine(timestampMs, logFmtLine(item), {place:'luna', source: 'data'});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -887,10 +887,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),
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user