mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Also replace step
with vars (#91031)
This commit is contained in:
parent
f66149807d
commit
f5b4fc58e3
@ -1875,7 +1875,7 @@ describe('applyTemplateVariables', () => {
|
|||||||
{ expr: 'rate({job="grafana"}[$__interval]) + rate({job="grafana"}[$__interval_ms])', refId: 'A' },
|
{ expr: 'rate({job="grafana"}[$__interval]) + rate({job="grafana"}[$__interval_ms])', refId: 'A' },
|
||||||
scopedVars
|
scopedVars
|
||||||
);
|
);
|
||||||
expect(templateSrvMock.replace).toHaveBeenCalledTimes(2);
|
expect(templateSrvMock.replace).toHaveBeenCalledTimes(3);
|
||||||
// Interpolated legend
|
// Interpolated legend
|
||||||
expect(templateSrvMock.replace).toHaveBeenCalledWith(
|
expect(templateSrvMock.replace).toHaveBeenCalledWith(
|
||||||
undefined,
|
undefined,
|
||||||
@ -1910,7 +1910,7 @@ describe('applyTemplateVariables', () => {
|
|||||||
},
|
},
|
||||||
scopedVars
|
scopedVars
|
||||||
);
|
);
|
||||||
expect(templateSrvMock.replace).toHaveBeenCalledTimes(2);
|
expect(templateSrvMock.replace).toHaveBeenCalledTimes(3);
|
||||||
// Interpolated legend
|
// Interpolated legend
|
||||||
expect(templateSrvMock.replace).toHaveBeenCalledWith(
|
expect(templateSrvMock.replace).toHaveBeenCalledWith(
|
||||||
undefined,
|
undefined,
|
||||||
@ -1931,6 +1931,52 @@ describe('applyTemplateVariables', () => {
|
|||||||
expect.any(Function)
|
expect.any(Function)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should replace step', () => {
|
||||||
|
const templateSrvMock = {
|
||||||
|
getAdhocFilters: jest.fn().mockImplementation((query: string) => query),
|
||||||
|
replace: jest.fn((a: string | undefined, ...rest: unknown[]) => a?.replace('$testVariable', 'foo')),
|
||||||
|
} as unknown as TemplateSrv;
|
||||||
|
|
||||||
|
const ds = createLokiDatasource(templateSrvMock);
|
||||||
|
ds.addAdHocFilters = jest.fn().mockImplementation((query: string) => query);
|
||||||
|
const replacedQuery = ds.applyTemplateVariables(
|
||||||
|
{
|
||||||
|
expr: 'rate({job="grafana"}[$__range]) + rate({job="grafana"}[$__range_ms]) + rate({job="grafana"}[$__range_s])',
|
||||||
|
refId: 'A',
|
||||||
|
step: '$testVariable',
|
||||||
|
},
|
||||||
|
scopedVars
|
||||||
|
);
|
||||||
|
expect(replacedQuery).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
step: 'foo',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should replace legendFormat', () => {
|
||||||
|
const templateSrvMock = {
|
||||||
|
getAdhocFilters: jest.fn().mockImplementation((query: string) => query),
|
||||||
|
replace: jest.fn((a: string | undefined, ...rest: unknown[]) => a?.replace('$testVariable', 'foo')),
|
||||||
|
} as unknown as TemplateSrv;
|
||||||
|
|
||||||
|
const ds = createLokiDatasource(templateSrvMock);
|
||||||
|
ds.addAdHocFilters = jest.fn().mockImplementation((query: string) => query);
|
||||||
|
const replacedQuery = ds.applyTemplateVariables(
|
||||||
|
{
|
||||||
|
expr: 'rate({job="grafana"}[$__range]) + rate({job="grafana"}[$__range_ms]) + rate({job="grafana"}[$__range_s])',
|
||||||
|
refId: 'A',
|
||||||
|
legendFormat: '$testVariable',
|
||||||
|
},
|
||||||
|
scopedVars
|
||||||
|
);
|
||||||
|
expect(replacedQuery).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
legendFormat: 'foo',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getStatsTimeRange', () => {
|
describe('getStatsTimeRange', () => {
|
||||||
|
@ -1106,10 +1106,14 @@ export class LokiDatasource
|
|||||||
adhocFilters
|
adhocFilters
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const step = this.templateSrv.replace(target.step, variables);
|
||||||
|
const legendFormat = this.templateSrv.replace(target.legendFormat, variables);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...target,
|
...target,
|
||||||
legendFormat: this.templateSrv.replace(target.legendFormat, rest),
|
|
||||||
expr: exprWithAdHoc,
|
expr: exprWithAdHoc,
|
||||||
|
step,
|
||||||
|
legendFormat,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user