mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
InfluxDB: Fix adhoc filter calls by properly checking optional parameter in metricFindQuery (#77113)
* Handle optional options parameter * unit tests
This commit is contained in:
parent
ba9c22f51b
commit
283f279a17
@ -161,6 +161,9 @@ describe('InfluxDataSource Frontend Mode', () => {
|
||||
const mockTemplateService = new TemplateSrv();
|
||||
mockTemplateService.getAdhocFilters = jest.fn((_: string) => adhocFilters);
|
||||
let ds = getMockInfluxDS(getMockDSInstanceSettings(), mockTemplateService);
|
||||
|
||||
// const fetchMock = jest.fn().mockReturnValue(fetchResult);
|
||||
|
||||
it('query should contain the ad-hoc variable', () => {
|
||||
ds.query(mockInfluxQueryRequest());
|
||||
const expected = encodeURIComponent(
|
||||
@ -168,6 +171,54 @@ describe('InfluxDataSource Frontend Mode', () => {
|
||||
);
|
||||
expect(fetchMock.mock.calls[0][0].data).toBe(`q=${expected}`);
|
||||
});
|
||||
|
||||
it('should make the fetch call for adhoc filter keys', () => {
|
||||
fetchMock.mockReturnValue(
|
||||
of({
|
||||
results: [
|
||||
{
|
||||
statement_id: 0,
|
||||
series: [
|
||||
{
|
||||
name: 'cpu',
|
||||
columns: ['tagKey'],
|
||||
values: [['datacenter'], ['geohash'], ['source']],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
ds.getTagKeys();
|
||||
expect(fetchMock).toHaveBeenCalled();
|
||||
const fetchReq = fetchMock.mock.calls[0][0];
|
||||
expect(fetchReq).not.toBeNull();
|
||||
expect(fetchReq.data).toMatch(encodeURIComponent(`SHOW TAG KEYS`));
|
||||
});
|
||||
|
||||
it('should make the fetch call for adhoc filter values', () => {
|
||||
fetchMock.mockReturnValue(
|
||||
of({
|
||||
results: [
|
||||
{
|
||||
statement_id: 0,
|
||||
series: [
|
||||
{
|
||||
name: 'mykey',
|
||||
columns: ['key', 'value'],
|
||||
values: [['mykey', 'value']],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
ds.getTagValues({ key: 'mykey', filters: [] });
|
||||
expect(fetchMock).toHaveBeenCalled();
|
||||
const fetchReq = fetchMock.mock.calls[0][0];
|
||||
expect(fetchReq).not.toBeNull();
|
||||
expect(fetchReq.data).toMatch(encodeURIComponent(`SHOW TAG VALUES WITH KEY = "mykey"`));
|
||||
});
|
||||
});
|
||||
|
||||
describe('datasource contract', () => {
|
||||
|
@ -313,7 +313,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
};
|
||||
return lastValueFrom(
|
||||
super.query({
|
||||
...options, // includes 'range'
|
||||
...(options ?? {}), // includes 'range'
|
||||
targets: [target],
|
||||
})
|
||||
).then((rsp) => {
|
||||
@ -324,7 +324,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
});
|
||||
}
|
||||
|
||||
const interpolated = this.templateSrv.replace(query, options.scopedVars, this.interpolateQueryExpr);
|
||||
const interpolated = this.templateSrv.replace(query, options?.scopedVars, this.interpolateQueryExpr);
|
||||
|
||||
return lastValueFrom(this._seriesQuery(interpolated, options)).then((resp) => {
|
||||
return this.responseParser.parse(query, resp);
|
||||
|
Loading…
Reference in New Issue
Block a user