mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
influxdb: more robust query-has-variables check (#37493)
* influxdb: moved queryUtils file to better place * influxdb: more robust query-has-variables check
This commit is contained in:
@@ -7,7 +7,7 @@ import { FluxQueryEditor } from './FluxQueryEditor';
|
||||
import { RawInfluxQLEditor } from './RawInfluxQLEditor';
|
||||
import { Editor as VisualInfluxQLEditor } from './VisualInfluxQLEditor/Editor';
|
||||
import { QueryEditorModeSwitcher } from './QueryEditorModeSwitcher';
|
||||
import { buildRawQuery } from './queryUtils';
|
||||
import { buildRawQuery } from '../queryUtils';
|
||||
|
||||
type Props = QueryEditorProps<InfluxDatasource, InfluxQuery, InfluxOptions>;
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import {
|
||||
removeGroupByPart,
|
||||
changeSelectPart,
|
||||
changeGroupByPart,
|
||||
} from '../queryUtils';
|
||||
} from '../../queryUtils';
|
||||
import { FormatAsSection } from './FormatAsSection';
|
||||
import { SectionLabel } from './SectionLabel';
|
||||
import { SectionFill } from './SectionFill';
|
||||
|
@@ -31,6 +31,7 @@ import { getBackendSrv, DataSourceWithBackend, frameToMetricFindValue } from '@g
|
||||
import { Observable, throwError, of } from 'rxjs';
|
||||
import { FluxQueryEditor } from './components/FluxQueryEditor';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { buildRawQuery } from './queryUtils';
|
||||
|
||||
// we detect the field type based on the value-array
|
||||
function getFieldType(values: unknown[]): FieldType {
|
||||
@@ -321,34 +322,11 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
}
|
||||
|
||||
targetContainsTemplate(target: any) {
|
||||
if (this.isFlux) {
|
||||
return this.templateSrv.variableExists(target.query);
|
||||
}
|
||||
// for flux-mode we just take target.query,
|
||||
// for influxql-mode we use InfluxQueryModel to create the text-representation
|
||||
const queryText = this.isFlux ? target.query : buildRawQuery(target);
|
||||
|
||||
// now we know it is an InfluxQL query.
|
||||
// it can be either a raw-query or a not-raw-query
|
||||
|
||||
if (target.rawQuery) {
|
||||
return this.templateSrv.variableExists(target.query);
|
||||
}
|
||||
|
||||
// now we know it is an InfluxQL not-raw-query
|
||||
|
||||
for (const group of target.groupBy) {
|
||||
for (const param of group.params) {
|
||||
if (this.templateSrv.variableExists(param)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const i in target.tags) {
|
||||
if (this.templateSrv.variableExists(target.tags[i].value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.templateSrv.variableExists(queryText);
|
||||
}
|
||||
|
||||
interpolateVariablesInQueries(queries: InfluxQuery[], scopedVars: ScopedVars): InfluxQuery[] {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { InfluxQuery } from '../types';
|
||||
import { InfluxQuery } from './types';
|
||||
import { buildRawQuery, normalizeQuery, changeSelectPart, changeGroupByPart } from './queryUtils';
|
||||
|
||||
describe('InfluxDB query utils', () => {
|
@@ -1,6 +1,6 @@
|
||||
import { cloneDeep } from 'lodash';
|
||||
import InfluxQueryModel from '../influx_query_model';
|
||||
import { InfluxQuery } from '../types';
|
||||
import InfluxQueryModel from './influx_query_model';
|
||||
import { InfluxQuery } from './types';
|
||||
|
||||
// FIXME: these functions are a beginning of a refactoring of influx_query_model.ts
|
||||
// into a simpler approach with full typescript types.
|
Reference in New Issue
Block a user