[release-11.6.2] InfluxDB: Fix variable interpolation on adhoc filters (#106949)
InfluxDB: Fix variable interpolation on adhoc filters (#104931)
Grafana frontend code sends adhoc filters to the backend in both the
`tags` and `adhocFilters` params.
The values in `tags` have dashboard variables interpolated, while those
in `adhocFilters` don't. This PR updates the frontend code to
also interpolate variables into the `adhocFilters` param.
The duplicated values are left as they are in `tags`, in case some other
spooky code at a distance relies on that.
(cherry picked from commit 02d977e1af)
Co-authored-by: beejeebus <justin.randell@grafana.com>
This commit is contained in:
co-authored by
beejeebus
parent
e0ba4b4809
commit
e5b0ed00ac
@@ -404,5 +404,6 @@ describe('interpolateQueryExpr', () => {
|
||||
const adhocFilter: AdHocVariableFilter[] = [{ key: 'bar', value: templateVarName, operator: '=' }];
|
||||
const result = ds.applyTemplateVariables(mockInfluxQueryRequest() as unknown as InfluxQuery, {}, adhocFilter);
|
||||
expect(result.tags![0].value).toBe(templateVarValue);
|
||||
expect(result.adhocFilters![0].value).toBe(templateVarValue);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,14 +47,7 @@ import { buildMetadataQuery } from './influxql_query_builder';
|
||||
import { prepareAnnotation } from './migrations';
|
||||
import { buildRawQuery, removeRegexWrapper } from './queryUtils';
|
||||
import ResponseParser from './response_parser';
|
||||
import {
|
||||
DEFAULT_POLICY,
|
||||
InfluxOptions,
|
||||
InfluxQuery,
|
||||
InfluxQueryTag,
|
||||
InfluxVariableQuery,
|
||||
InfluxVersion,
|
||||
} from './types';
|
||||
import { DEFAULT_POLICY, InfluxOptions, InfluxQuery, InfluxVariableQuery, InfluxVersion } from './types';
|
||||
import { InfluxVariableSupport } from './variables';
|
||||
|
||||
export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery, InfluxOptions> {
|
||||
@@ -206,12 +199,12 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
if (this.version === InfluxVersion.SQL || this.isMigrationToggleOnAndIsAccessProxy()) {
|
||||
query = this.applyVariables(query, variables, filters);
|
||||
if (query.adhocFilters?.length) {
|
||||
const adhocFiltersToTags: InfluxQueryTag[] = (query.adhocFilters ?? []).map((af) => {
|
||||
query.adhocFilters = (query.adhocFilters ?? []).map((af) => {
|
||||
const { condition, ...asTag } = af;
|
||||
asTag.value = this.templateSrv.replace(asTag.value ?? '', variables);
|
||||
return asTag;
|
||||
});
|
||||
query.tags = [...(query.tags ?? []), ...adhocFiltersToTags];
|
||||
query.tags = [...(query.tags ?? []), ...query.adhocFilters];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user