|
|
@ -11,10 +11,9 @@ import { |
|
|
|
DataSourceRef, |
|
|
|
DataSourceRef, |
|
|
|
MetricFindValue, |
|
|
|
MetricFindValue, |
|
|
|
ScopedVars, |
|
|
|
ScopedVars, |
|
|
|
TimeRange, |
|
|
|
|
|
|
|
CoreApp, |
|
|
|
CoreApp, |
|
|
|
getSearchFilterScopedVar, |
|
|
|
getSearchFilterScopedVar, |
|
|
|
SearchFilterOptions, |
|
|
|
LegacyMetricFindQueryOptions, |
|
|
|
} from '@grafana/data'; |
|
|
|
} from '@grafana/data'; |
|
|
|
import { EditorMode } from '@grafana/experimental'; |
|
|
|
import { EditorMode } from '@grafana/experimental'; |
|
|
|
import { |
|
|
|
import { |
|
|
@ -172,17 +171,18 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async metricFindQuery(query: string, optionalOptions?: MetricFindQueryOptions): Promise<MetricFindValue[]> { |
|
|
|
async metricFindQuery(query: string, options?: LegacyMetricFindQueryOptions): Promise<MetricFindValue[]> { |
|
|
|
let refId = 'tempvar'; |
|
|
|
let refId = 'tempvar'; |
|
|
|
if (optionalOptions && optionalOptions.variable && optionalOptions.variable.name) { |
|
|
|
if (options && options.variable && options.variable.name) { |
|
|
|
refId = optionalOptions.variable.name; |
|
|
|
refId = options.variable.name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const rawSql = this.templateSrv.replace( |
|
|
|
const scopedVars = { |
|
|
|
query, |
|
|
|
...options?.scopedVars, |
|
|
|
getSearchFilterScopedVar({ query, wildcardChar: '%', options: optionalOptions }), |
|
|
|
...getSearchFilterScopedVar({ query, wildcardChar: '%', options }), |
|
|
|
this.interpolateVariable |
|
|
|
}; |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const rawSql = this.templateSrv.replace(query, scopedVars, this.interpolateVariable); |
|
|
|
|
|
|
|
|
|
|
|
const interpolatedQuery: SQLQuery = { |
|
|
|
const interpolatedQuery: SQLQuery = { |
|
|
|
refId: refId, |
|
|
|
refId: refId, |
|
|
@ -191,7 +191,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO |
|
|
|
format: QueryFormat.Table, |
|
|
|
format: QueryFormat.Table, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const response = await this.runMetaQuery(interpolatedQuery, optionalOptions); |
|
|
|
const response = await this.runMetaQuery(interpolatedQuery, options); |
|
|
|
return this.getResponseParser().transformMetricFindResponse(response); |
|
|
|
return this.getResponseParser().transformMetricFindResponse(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -200,7 +200,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO |
|
|
|
return new DataFrameView<T>(frame); |
|
|
|
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 range = getTimeSrv().timeRange(); |
|
|
|
const refId = request.refId || 'meta'; |
|
|
|
const refId = request.refId || 'meta'; |
|
|
|
const queries: DataQuery[] = [{ ...request, datasource: request.datasource || this.getRef(), refId }]; |
|
|
|
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; |
|
|
|
refId?: string; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface MetricFindQueryOptions extends SearchFilterOptions { |
|
|
|
|
|
|
|
range?: TimeRange; |
|
|
|
|
|
|
|
variable?: VariableWithMultiSupport; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|