InfluxDB: Fix custom variable support (#88642)

* fix variable support

* prettier
This commit is contained in:
ismail simsek 2024-06-03 22:47:27 +02:00 committed by GitHub
parent 043e19afb5
commit f458e57523
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View File

@ -13,7 +13,7 @@ type Props = QueryEditorProps<InfluxDatasource, InfluxQuery, InfluxOptions, Infl
const refId = 'InfluxVariableQueryEditor-VariableQuery';
export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) => {
const getFluxVariableQuery = (q: InfluxVariableQuery | string) => {
const getVariableQuery = (q: InfluxVariableQuery | string) => {
// in legacy variable support query can be only a string
// in new variable support query can be an object and hold more information
// to be able to support old version we check the query here
@ -24,7 +24,7 @@ export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) =>
return {
refId,
query: q,
maxDataPoints: 1000,
...(datasource.version === InfluxVersion.Flux ? { maxDataPoints: 1000 } : {}),
};
};
@ -34,7 +34,7 @@ export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) =>
<>
<FluxQueryEditor
datasource={datasource}
query={getFluxVariableQuery(query)}
query={getVariableQuery(query)}
onChange={(q) => {
onChange({ ...query, query: q.query ?? '' });
}}
@ -72,11 +72,11 @@ export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) =>
<InlineField label="Query" labelWidth={20} required grow aria-labelledby="influx-variable-query">
<TextArea
aria-label="influx-variable-query"
defaultValue={query.query}
defaultValue={getVariableQuery(query).query}
placeholder="metric name or tags query"
rows={1}
onBlur={(e) => {
onChange({ refId, query: query.query ?? '' });
onChange({ refId, query: e.currentTarget.value ?? '' });
}}
/>
</InlineField>

View File

@ -30,7 +30,9 @@ export class InfluxVariableSupport extends CustomVariableSupport<InfluxDatasourc
return of({ data: [] });
}
const interpolated = this.templateSrv.replace(query, request.scopedVars, this.datasource.interpolateQueryExpr);
const q = this.templateSrv.replace(query, request.scopedVars, this.datasource.interpolateQueryExpr);
const timeFilter = this.datasource.getTimeFilter({ rangeRaw: request.range.raw, timezone: request.timezone });
const interpolated = q.replace('$timeFilter', timeFilter);
const metricFindStream = from(
this.datasource.metricFindQuery(
{