Influx: Replace pre-calculated $__interval values for backend interpolation (#84975)

This commit is contained in:
Dominik Prokop
2024-03-22 12:48:41 +01:00
committed by GitHub
parent 86bb91e1ce
commit 41bf6a92fd
@@ -171,18 +171,26 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
}
applyTemplateVariables(query: InfluxQuery, scopedVars: ScopedVars): InfluxQuery & SQLQuery {
// We want to interpolate these variables on backend
const { __interval, __interval_ms, ...rest } = scopedVars || {};
const variables = scopedVars || {};
// We want to interpolate these variables on backend.
// The pre-calculated values are replaced withe the variable strings.
variables.__interval = {
value: '$__interval',
};
variables.__interval_ms = {
value: '$__interval_ms',
};
if (this.version === InfluxVersion.Flux) {
return {
...query,
query: this.templateSrv.replace(query.query ?? '', rest), // The raw query text
query: this.templateSrv.replace(query.query ?? '', variables), // The raw query text
};
}
if (this.version === InfluxVersion.SQL || this.isMigrationToggleOnAndIsAccessProxy()) {
query = this.applyVariables(query, rest);
query = this.applyVariables(query, variables);
if (query.adhocFilters?.length) {
const adhocFiltersToTags: InfluxQueryTag[] = (query.adhocFilters ?? []).map((af) => {
const { condition, ...asTag } = af;