DataSourceRef: use reference rather than id where possible (#41372)

This commit is contained in:
Ryan McKinley 2021-11-09 07:24:41 -08:00 committed by GitHub
parent 490d21fc5c
commit 6c1a0cc707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 39 deletions

View File

@ -55,7 +55,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
{ {
refId: 'annotationQuery', refId: 'annotationQuery',
type: 'annotationQuery', type: 'annotationQuery',
datasourceId: this.id, datasource: this.getRef(),
view: 'FULL', view: 'FULL',
crossSeriesReducer: 'REDUCE_NONE', crossSeriesReducer: 'REDUCE_NONE',
perSeriesAligner: 'ALIGN_NONE', perSeriesAligner: 'ALIGN_NONE',
@ -108,7 +108,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
scopedVars: ScopedVars scopedVars: ScopedVars
): Record<string, any> { ): Record<string, any> {
return { return {
datasourceId: this.id, datasource: this.getRef(),
refId, refId,
intervalMs: this.intervalMs, intervalMs: this.intervalMs,
type: 'timeSeriesQuery', type: 'timeSeriesQuery',
@ -133,7 +133,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
targets: [ targets: [
{ {
refId, refId,
datasourceId: this.id, datasource: this.getRef(),
queryType: QueryType.METRICS, queryType: QueryType.METRICS,
metricQuery: { metricQuery: {
projectName: this.templateSrv.replace(projectName), projectName: this.templateSrv.replace(projectName),
@ -212,7 +212,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
{ {
refId: 'getGCEDefaultProject', refId: 'getGCEDefaultProject',
type: 'getGCEDefaultProject', type: 'getGCEDefaultProject',
datasourceId: this.id, datasource: this.getRef(),
}, },
], ],
}) })

View File

@ -222,9 +222,9 @@ export class CloudWatchDatasource
return { return {
intervalMs: options.intervalMs, intervalMs: options.intervalMs,
maxDataPoints: options.maxDataPoints, maxDataPoints: options.maxDataPoints,
datasourceId: this.id,
type: 'timeSeriesQuery', type: 'timeSeriesQuery',
...item, ...item,
datasource: this.getRef(),
}; };
} }
); );
@ -506,7 +506,7 @@ export class CloudWatchDatasource
refId: 'metricFindQuery', refId: 'metricFindQuery',
intervalMs: 1, // dummy intervalMs: 1, // dummy
maxDataPoints: 1, // dummy maxDataPoints: 1, // dummy
datasourceId: this.id, datasource: this.getRef(),
type: 'metricFindQuery', type: 'metricFindQuery',
subtype: subtype, subtype: subtype,
...parameters, ...parameters,
@ -541,7 +541,7 @@ export class CloudWatchDatasource
refId: 'A', refId: 'A',
intervalMs: 1, // dummy intervalMs: 1, // dummy
maxDataPoints: 1, // dummy maxDataPoints: 1, // dummy
datasourceId: this.id, datasource: this.getRef(),
type: 'logAction', type: 'logAction',
subtype: subtype, subtype: subtype,
...param, ...param,
@ -773,7 +773,7 @@ export class CloudWatchDatasource
queries: [ queries: [
{ {
refId: 'annotationQuery', refId: 'annotationQuery',
datasourceId: this.id, datasource: this.getRef(),
type: 'annotationQuery', type: 'annotationQuery',
...parameters, ...parameters,
}, },

View File

@ -1,4 +1,4 @@
import { DataQuery, SelectableValue } from '@grafana/data'; import { DataQuery, DataSourceRef, SelectableValue } from '@grafana/data';
import { AwsAuthDataSourceSecureJsonData, AwsAuthDataSourceJsonData } from '@grafana/aws-sdk'; import { AwsAuthDataSourceSecureJsonData, AwsAuthDataSourceJsonData } from '@grafana/aws-sdk';
export interface CloudWatchMetricsQuery extends DataQuery { export interface CloudWatchMetricsQuery extends DataQuery {
@ -314,26 +314,12 @@ export interface MetricRequest {
export interface MetricQuery { export interface MetricQuery {
[key: string]: any; [key: string]: any;
datasourceId: number; datasource: DataSourceRef;
refId?: string; refId?: string;
maxDataPoints?: number; maxDataPoints?: number;
intervalMs?: number; intervalMs?: number;
} }
// interface TsdbQuery {
// TimeRange *TimeRange
// Queries []*Query
// Debug bool
// }
// type Query struct {
// RefId string
// Model *simplejson.Json
// DataSource *models.DataSource
// MaxDataPoints int64
// IntervalMs int64
// }
export interface ExecutedQueryPreview { export interface ExecutedQueryPreview {
id: string; id: string;
executedQuery: string; executedQuery: string;

View File

@ -8,7 +8,13 @@ import {
AzureQueryType, AzureQueryType,
DatasourceValidationResult, DatasourceValidationResult,
} from '../types'; } from '../types';
import { DataQueryRequest, DataQueryResponse, ScopedVars, DataSourceInstanceSettings } from '@grafana/data'; import {
DataQueryRequest,
DataQueryResponse,
ScopedVars,
DataSourceInstanceSettings,
DataSourceRef,
} from '@grafana/data';
import { getTemplateSrv, DataSourceWithBackend } from '@grafana/runtime'; import { getTemplateSrv, DataSourceWithBackend } from '@grafana/runtime';
import { Observable, from } from 'rxjs'; import { Observable, from } from 'rxjs';
import { mergeMap } from 'rxjs/operators'; import { mergeMap } from 'rxjs/operators';
@ -17,7 +23,7 @@ import { isGUIDish } from '../components/ResourcePicker/utils';
import { interpolateVariable, routeNames } from '../utils/common'; import { interpolateVariable, routeNames } from '../utils/common';
interface AdhocQuery { interface AdhocQuery {
datasourceId: number; datasource: DataSourceRef;
path: string; path: string;
resultFormat: string; resultFormat: string;
} }
@ -234,7 +240,7 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
const queries = [ const queries = [
{ {
datasourceId: this.id, datasource: this.getRef(),
path: path, path: path,
resultFormat: 'table', resultFormat: 'table',
}, },

View File

@ -74,7 +74,7 @@ export class MssqlDatasource extends DataSourceWithBackend<MssqlQuery, MssqlOpti
applyTemplateVariables(target: MssqlQuery, scopedVars: ScopedVars): Record<string, any> { applyTemplateVariables(target: MssqlQuery, scopedVars: ScopedVars): Record<string, any> {
return { return {
refId: target.refId, refId: target.refId,
datasourceId: this.id, datasource: this.getRef(),
rawSql: this.templateSrv.replace(target.rawSql, scopedVars, this.interpolateVariable), rawSql: this.templateSrv.replace(target.rawSql, scopedVars, this.interpolateVariable),
format: target.format, format: target.format,
}; };
@ -87,7 +87,7 @@ export class MssqlDatasource extends DataSourceWithBackend<MssqlQuery, MssqlOpti
const query = { const query = {
refId: options.annotation.name, refId: options.annotation.name,
datasourceId: this.id, datasource: this.getRef(),
rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable), rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable),
format: 'table', format: 'table',
}; };
@ -127,7 +127,7 @@ export class MssqlDatasource extends DataSourceWithBackend<MssqlQuery, MssqlOpti
const interpolatedQuery = { const interpolatedQuery = {
refId: refId, refId: refId,
datasourceId: this.id, datasource: this.getRef(),
rawSql: this.templateSrv.replace(query, {}, this.interpolateVariable), rawSql: this.templateSrv.replace(query, {}, this.interpolateVariable),
format: 'table', format: 'table',
}; };
@ -169,7 +169,7 @@ export class MssqlDatasource extends DataSourceWithBackend<MssqlQuery, MssqlOpti
refId: 'A', refId: 'A',
intervalMs: 1, intervalMs: 1,
maxDataPoints: 1, maxDataPoints: 1,
datasourceId: this.id, datasource: this.getRef(),
rawSql: 'SELECT 1', rawSql: 'SELECT 1',
format: 'table', format: 'table',
}, },

View File

@ -80,7 +80,7 @@ export class MysqlDatasource extends DataSourceWithBackend<MySQLQuery, MySQLOpti
const queryModel = new MySQLQueryModel(target, this.templateSrv, scopedVars); const queryModel = new MySQLQueryModel(target, this.templateSrv, scopedVars);
return { return {
refId: target.refId, refId: target.refId,
datasourceId: this.id, datasource: this.getRef(),
rawSql: queryModel.render(this.interpolateVariable as any), rawSql: queryModel.render(this.interpolateVariable as any),
format: target.format, format: target.format,
}; };
@ -95,7 +95,7 @@ export class MysqlDatasource extends DataSourceWithBackend<MySQLQuery, MySQLOpti
const query = { const query = {
refId: options.annotation.name, refId: options.annotation.name,
datasourceId: this.id, datasource: this.getRef(),
rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable), rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable),
format: 'table', format: 'table',
}; };
@ -135,7 +135,7 @@ export class MysqlDatasource extends DataSourceWithBackend<MySQLQuery, MySQLOpti
const interpolatedQuery = { const interpolatedQuery = {
refId: refId, refId: refId,
datasourceId: this.id, datasource: this.getRef(),
rawSql, rawSql,
format: 'table', format: 'table',
}; };
@ -179,7 +179,7 @@ export class MysqlDatasource extends DataSourceWithBackend<MySQLQuery, MySQLOpti
refId: 'A', refId: 'A',
intervalMs: 1, intervalMs: 1,
maxDataPoints: 1, maxDataPoints: 1,
datasourceId: this.id, datasource: this.getRef(),
rawSql: 'SELECT 1', rawSql: 'SELECT 1',
format: 'table', format: 'table',
}, },

View File

@ -82,7 +82,7 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
const queryModel = new PostgresQueryModel(target, this.templateSrv, scopedVars); const queryModel = new PostgresQueryModel(target, this.templateSrv, scopedVars);
return { return {
refId: target.refId, refId: target.refId,
datasourceId: this.id, datasource: this.getRef(),
rawSql: queryModel.render(this.interpolateVariable as any), rawSql: queryModel.render(this.interpolateVariable as any),
format: target.format, format: target.format,
}; };
@ -97,7 +97,7 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
const query = { const query = {
refId: options.annotation.name, refId: options.annotation.name,
datasourceId: this.id, datasource: this.getRef(),
rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable), rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable),
format: 'table', format: 'table',
}; };
@ -137,7 +137,7 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
const interpolatedQuery = { const interpolatedQuery = {
refId: refId, refId: refId,
datasourceId: this.id, datasource: this.getRef(),
rawSql, rawSql,
format: 'table', format: 'table',
}; };

View File

@ -672,7 +672,7 @@ export class PrometheusDatasource extends DataSourceWithBackend<PromQuery, PromO
interval: step, interval: step,
queryType: PromQueryType.timeSeriesQuery, queryType: PromQueryType.timeSeriesQuery,
refId: 'X', refId: 'X',
datasourceId: this.id, datasource: this.getRef(),
}; };
return await lastValueFrom( return await lastValueFrom(