mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 11:34:06 +08:00
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.
This commit is contained in:
@ -416,5 +416,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