diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index 9395dafb313..e54bde8734d 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -254,7 +254,7 @@ export default class InfluxDatasource extends DataSourceWithBackend { return { ...select, - params: select.params?.map((param) => this.templateSrv.replace(param.toString(), undefined)), + params: select.params?.map((param) => this.templateSrv.replace(param.toString(), scopedVars)), }; }); }); diff --git a/public/app/plugins/datasource/influxdb/datasource_backend_mode.test.ts b/public/app/plugins/datasource/influxdb/datasource_backend_mode.test.ts index 4ce1dff8e2f..691677ce07d 100644 --- a/public/app/plugins/datasource/influxdb/datasource_backend_mode.test.ts +++ b/public/app/plugins/datasource/influxdb/datasource_backend_mode.test.ts @@ -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', () => {