mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
SqlDataSources: Update metricFindQuery to pass on scopedVars to templateSrv (#73333)
This commit is contained in:
parent
c8a9adf52a
commit
3245e25273
@ -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, TOptions>,
|
||||
TQuery extends DataQuery = DataQuery,
|
||||
|
@ -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<SQLQuery, SQLO
|
||||
return;
|
||||
}
|
||||
|
||||
async metricFindQuery(query: string, optionalOptions?: MetricFindQueryOptions): Promise<MetricFindValue[]> {
|
||||
async metricFindQuery(query: string, options?: LegacyMetricFindQueryOptions): Promise<MetricFindValue[]> {
|
||||
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<SQLQuery, SQLO
|
||||
format: QueryFormat.Table,
|
||||
};
|
||||
|
||||
const response = await this.runMetaQuery(interpolatedQuery, optionalOptions);
|
||||
const response = await this.runMetaQuery(interpolatedQuery, options);
|
||||
return this.getResponseParser().transformMetricFindResponse(response);
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
|
||||
return new DataFrameView<T>(frame);
|
||||
}
|
||||
|
||||
private runMetaQuery(request: Partial<SQLQuery>, options?: MetricFindQueryOptions): Promise<DataFrame> {
|
||||
private runMetaQuery(request: Partial<SQLQuery>, options?: LegacyMetricFindQueryOptions): Promise<DataFrame> {
|
||||
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<SQLQuery, SQLO
|
||||
}
|
||||
}
|
||||
|
||||
interface RunSQLOptions extends MetricFindQueryOptions {
|
||||
interface RunSQLOptions extends LegacyMetricFindQueryOptions {
|
||||
refId?: string;
|
||||
}
|
||||
|
||||
interface MetricFindQueryOptions extends SearchFilterOptions {
|
||||
range?: TimeRange;
|
||||
variable?: VariableWithMultiSupport;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user