diff --git a/packages/grafana-data/src/types/datasource.ts b/packages/grafana-data/src/types/datasource.ts index cabc2dedf74..44d588650bb 100644 --- a/packages/grafana-data/src/types/datasource.ts +++ b/packages/grafana-data/src/types/datasource.ts @@ -383,6 +383,13 @@ export interface MetadataInspectorProps< data: DataFrame[]; } +export interface LegacyMetricFindQueryOptions { + searchFilter?: string; + scopedVars?: ScopedVars; + range?: TimeRange; + variable?: { name: string }; +} + export interface QueryEditorProps< DSType extends DataSourceApi, TQuery extends DataQuery = DataQuery, diff --git a/public/app/features/plugins/sql/datasource/SqlDatasource.ts b/public/app/features/plugins/sql/datasource/SqlDatasource.ts index 284b5758367..3f9b51a2c83 100644 --- a/public/app/features/plugins/sql/datasource/SqlDatasource.ts +++ b/public/app/features/plugins/sql/datasource/SqlDatasource.ts @@ -11,10 +11,9 @@ import { DataSourceRef, MetricFindValue, ScopedVars, - TimeRange, CoreApp, getSearchFilterScopedVar, - SearchFilterOptions, + LegacyMetricFindQueryOptions, } from '@grafana/data'; import { EditorMode } from '@grafana/experimental'; import { @@ -172,17 +171,18 @@ export abstract class SqlDatasource extends DataSourceWithBackend { + async metricFindQuery(query: string, options?: LegacyMetricFindQueryOptions): Promise { let refId = 'tempvar'; - if (optionalOptions && optionalOptions.variable && optionalOptions.variable.name) { - refId = optionalOptions.variable.name; + if (options && options.variable && options.variable.name) { + refId = options.variable.name; } - const rawSql = this.templateSrv.replace( - query, - getSearchFilterScopedVar({ query, wildcardChar: '%', options: optionalOptions }), - this.interpolateVariable - ); + const scopedVars = { + ...options?.scopedVars, + ...getSearchFilterScopedVar({ query, wildcardChar: '%', options }), + }; + + const rawSql = this.templateSrv.replace(query, scopedVars, this.interpolateVariable); const interpolatedQuery: SQLQuery = { refId: refId, @@ -191,7 +191,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend(frame); } - private runMetaQuery(request: Partial, options?: MetricFindQueryOptions): Promise { + private runMetaQuery(request: Partial, options?: LegacyMetricFindQueryOptions): Promise { const range = getTimeSrv().timeRange(); const refId = request.refId || 'meta'; const queries: DataQuery[] = [{ ...request, datasource: request.datasource || this.getRef(), refId }]; @@ -236,11 +236,6 @@ export abstract class SqlDatasource extends DataSourceWithBackend