mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
InfluxDB: Fix interpolating field keys in influxql (#86401)
* interpolate field keys * use scopedVars
This commit is contained in:
parent
b311612cf2
commit
842c8dd206
@ -254,7 +254,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
return selects.map((select) => {
|
||||
return {
|
||||
...select,
|
||||
params: select.params?.map((param) => this.templateSrv.replace(param.toString(), undefined)),
|
||||
params: select.params?.map((param) => this.templateSrv.replace(param.toString(), scopedVars)),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
@ -221,6 +221,26 @@ describe('InfluxDataSource Backend Mode', () => {
|
||||
const variablesMock = [
|
||||
queryBuilder().withId('var1').withName('var1').withCurrent('var1').build(),
|
||||
queryBuilder().withId('path').withName('path').withCurrent('/etc/hosts').build(),
|
||||
queryBuilder()
|
||||
.withId('field_var')
|
||||
.withName('field_var')
|
||||
.withMulti(true)
|
||||
.withOptions(
|
||||
{
|
||||
text: `field_1`,
|
||||
value: `field_1`,
|
||||
},
|
||||
{
|
||||
text: `field_2`,
|
||||
value: `field_2`,
|
||||
},
|
||||
{
|
||||
text: `field_3`,
|
||||
value: `field_3`,
|
||||
}
|
||||
)
|
||||
.withCurrent(['field_1', 'field_3'])
|
||||
.build(),
|
||||
];
|
||||
const mockTemplateService = new TemplateSrv({
|
||||
getVariables: () => variablesMock,
|
||||
@ -328,6 +348,34 @@ describe('InfluxDataSource Backend Mode', () => {
|
||||
const expected = `/etc/hosts`;
|
||||
expect(res.tags?.[0].value).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should interpolate field keys with given scopedVars', () => {
|
||||
const query: InfluxQuery = {
|
||||
refId: 'A',
|
||||
tags: [
|
||||
{
|
||||
key: 'key',
|
||||
operator: '=',
|
||||
value: 'value',
|
||||
},
|
||||
],
|
||||
select: [
|
||||
[
|
||||
{
|
||||
type: 'field',
|
||||
params: ['$field_var'],
|
||||
},
|
||||
{
|
||||
type: 'mean',
|
||||
params: [],
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
const res = ds.applyVariables(query, { field_var: { text: 'field_3', value: 'field_3' } });
|
||||
const expected = `field_3`;
|
||||
expect(res.select?.[0][0].params?.[0]).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('metric find query', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user