Commit 1d8786e3 by Ryan McKinley Committed by Torkel Ödegaard

DataSource Plugins: consistent generics order <TQuery,TOptions> (#16936)

* consistent TQuery,TOptions

* add json for azure

* cloudwatch
parent b08cf1e7
...@@ -11,13 +11,13 @@ export interface DataSourcePluginOptionsEditorProps<TOptions> { ...@@ -11,13 +11,13 @@ export interface DataSourcePluginOptionsEditorProps<TOptions> {
} }
export class DataSourcePlugin< export class DataSourcePlugin<
TOptions extends DataSourceJsonData = DataSourceJsonData, TQuery extends DataQuery = DataQuery,
TQuery extends DataQuery = DataQuery TOptions extends DataSourceJsonData = DataSourceJsonData
> extends GrafanaPlugin<DataSourcePluginMeta> { > extends GrafanaPlugin<DataSourcePluginMeta> {
DataSourceClass: DataSourceConstructor<TQuery>; DataSourceClass: DataSourceConstructor<TQuery, TOptions>;
components: DataSourcePluginComponents<TOptions, TQuery>; components: DataSourcePluginComponents<TQuery, TOptions>;
constructor(DataSourceClass: DataSourceConstructor<TQuery>) { constructor(DataSourceClass: DataSourceConstructor<TQuery, TOptions>) {
super(); super();
this.DataSourceClass = DataSourceClass; this.DataSourceClass = DataSourceClass;
this.components = {}; this.components = {};
...@@ -89,8 +89,8 @@ interface PluginMetaQueryOptions { ...@@ -89,8 +89,8 @@ interface PluginMetaQueryOptions {
} }
export interface DataSourcePluginComponents< export interface DataSourcePluginComponents<
TOptions extends DataSourceJsonData = DataSourceJsonData, TQuery extends DataQuery = DataQuery,
TQuery extends DataQuery = DataQuery TOptions extends DataSourceJsonData = DataSourceJsonData
> { > {
QueryCtrl?: any; QueryCtrl?: any;
AnnotationsQueryCtrl?: any; AnnotationsQueryCtrl?: any;
...@@ -101,14 +101,20 @@ export interface DataSourcePluginComponents< ...@@ -101,14 +101,20 @@ export interface DataSourcePluginComponents<
ConfigEditor?: React.ComponentType<DataSourcePluginOptionsEditorProps<DataSourceSettings<TOptions>>>; ConfigEditor?: React.ComponentType<DataSourcePluginOptionsEditorProps<DataSourceSettings<TOptions>>>;
} }
export interface DataSourceConstructor<TQuery extends DataQuery = DataQuery> { export interface DataSourceConstructor<
new (instanceSettings: DataSourceInstanceSettings, ...args: any[]): DataSourceApi<TQuery>; TQuery extends DataQuery = DataQuery,
TOptions extends DataSourceJsonData = DataSourceJsonData
> {
new (instanceSettings: DataSourceInstanceSettings<TOptions>, ...args: any[]): DataSourceApi<TQuery, TOptions>;
} }
/** /**
* The main data source abstraction interface, represents an instance of a data source * The main data source abstraction interface, represents an instance of a data source
*/ */
export interface DataSourceApi<TQuery extends DataQuery = DataQuery> { export interface DataSourceApi<
TQuery extends DataQuery = DataQuery,
TOptions extends DataSourceJsonData = DataSourceJsonData
> {
/** /**
* min interval range * min interval range
*/ */
...@@ -158,7 +164,7 @@ export interface DataSourceApi<TQuery extends DataQuery = DataQuery> { ...@@ -158,7 +164,7 @@ export interface DataSourceApi<TQuery extends DataQuery = DataQuery> {
* Set after constructor call, as the data source instance is the most common thing to pass around * Set after constructor call, as the data source instance is the most common thing to pass around
* we attach the components to this instance for easy access * we attach the components to this instance for easy access
*/ */
components?: DataSourcePluginComponents; components?: DataSourcePluginComponents<TQuery, TOptions>;
/** /**
* static information about the datasource * static information about the datasource
......
...@@ -10,10 +10,21 @@ import templateSrv from 'app/features/templating/template_srv'; ...@@ -10,10 +10,21 @@ import templateSrv from 'app/features/templating/template_srv';
import { PanelQueryState } from './PanelQueryState'; import { PanelQueryState } from './PanelQueryState';
// Types // Types
import { PanelData, DataQuery, TimeRange, ScopedVars, DataQueryRequest, DataSourceApi } from '@grafana/ui'; import {
PanelData,
export interface QueryRunnerOptions<TQuery extends DataQuery = DataQuery> { DataQuery,
datasource: string | DataSourceApi<TQuery>; TimeRange,
ScopedVars,
DataQueryRequest,
DataSourceApi,
DataSourceJsonData,
} from '@grafana/ui';
export interface QueryRunnerOptions<
TQuery extends DataQuery = DataQuery,
TOptions extends DataSourceJsonData = DataSourceJsonData
> {
datasource: string | DataSourceApi<TQuery, TOptions>;
queries: TQuery[]; queries: TQuery[];
panelId: number; panelId: number;
dashboardId?: number; dashboardId?: number;
......
...@@ -3,7 +3,10 @@ import _ from 'lodash'; ...@@ -3,7 +3,10 @@ import _ from 'lodash';
import * as dateMath from '@grafana/ui/src/utils/datemath'; import * as dateMath from '@grafana/ui/src/utils/datemath';
import kbn from 'app/core/utils/kbn'; import kbn from 'app/core/utils/kbn';
import { CloudWatchQuery } from './types'; import { CloudWatchQuery } from './types';
import { DataSourceApi, DataQueryRequest } from '@grafana/ui/src/types'; import { DataSourceApi, DataQueryRequest, DataSourceInstanceSettings } from '@grafana/ui/src/types';
import { BackendSrv } from 'app/core/services/backend_srv';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
// import * as moment from 'moment'; // import * as moment from 'moment';
export default class CloudWatchDatasource implements DataSourceApi<CloudWatchQuery> { export default class CloudWatchDatasource implements DataSourceApi<CloudWatchQuery> {
...@@ -11,10 +14,16 @@ export default class CloudWatchDatasource implements DataSourceApi<CloudWatchQue ...@@ -11,10 +14,16 @@ export default class CloudWatchDatasource implements DataSourceApi<CloudWatchQue
name: any; name: any;
proxyUrl: any; proxyUrl: any;
defaultRegion: any; defaultRegion: any;
instanceSettings: any;
standardStatistics: any; standardStatistics: any;
/** @ngInject */ /** @ngInject */
constructor(instanceSettings, private $q, private backendSrv, private templateSrv, private timeSrv) { constructor(
private instanceSettings: DataSourceInstanceSettings,
private $q,
private backendSrv: BackendSrv,
private templateSrv: TemplateSrv,
private timeSrv: TimeSrv
) {
this.type = 'cloudwatch'; this.type = 'cloudwatch';
this.name = instanceSettings.name; this.name = instanceSettings.name;
this.proxyUrl = instanceSettings.url; this.proxyUrl = instanceSettings.url;
......
...@@ -5,11 +5,14 @@ import { TemplateSrv } from 'app/features/templating/template_srv'; ...@@ -5,11 +5,14 @@ import { TemplateSrv } from 'app/features/templating/template_srv';
import { CustomVariable } from 'app/features/templating/all'; import { CustomVariable } from 'app/features/templating/all';
import _ from 'lodash'; import _ from 'lodash';
import { CloudWatchQuery } from '../types'; import { CloudWatchQuery } from '../types';
import { DataSourceInstanceSettings } from '@grafana/ui';
import { BackendSrv } from 'app/core/services/backend_srv';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
describe('CloudWatchDatasource', () => { describe('CloudWatchDatasource', () => {
const instanceSettings = { const instanceSettings = {
jsonData: { defaultRegion: 'us-east-1', access: 'proxy' }, jsonData: { defaultRegion: 'us-east-1' },
}; } as DataSourceInstanceSettings;
const templateSrv = new TemplateSrv(); const templateSrv = new TemplateSrv();
...@@ -21,8 +24,8 @@ describe('CloudWatchDatasource', () => { ...@@ -21,8 +24,8 @@ describe('CloudWatchDatasource', () => {
to: dateMath.parse(timeSrv.time.to, true), to: dateMath.parse(timeSrv.time.to, true),
}; };
}, },
}; } as TimeSrv;
const backendSrv = {}; const backendSrv = {} as BackendSrv;
const ctx = { const ctx = {
backendSrv, backendSrv,
templateSrv, templateSrv,
......
...@@ -2,6 +2,10 @@ import _ from 'lodash'; ...@@ -2,6 +2,10 @@ import _ from 'lodash';
import AppInsightsQuerystringBuilder from './app_insights_querystring_builder'; import AppInsightsQuerystringBuilder from './app_insights_querystring_builder';
import LogAnalyticsQuerystringBuilder from '../log_analytics/querystring_builder'; import LogAnalyticsQuerystringBuilder from '../log_analytics/querystring_builder';
import ResponseParser from './response_parser'; import ResponseParser from './response_parser';
import { DataSourceInstanceSettings } from '@grafana/ui';
import { AzureDataSourceJsonData } from '../types';
import { BackendSrv } from 'app/core/services/backend_srv';
import { TemplateSrv } from 'app/features/templating/template_srv';
export interface LogAnalyticsColumn { export interface LogAnalyticsColumn {
text: string; text: string;
...@@ -16,7 +20,12 @@ export default class AppInsightsDatasource { ...@@ -16,7 +20,12 @@ export default class AppInsightsDatasource {
logAnalyticsColumns: { [key: string]: LogAnalyticsColumn[] } = {}; logAnalyticsColumns: { [key: string]: LogAnalyticsColumn[] } = {};
/** @ngInject */ /** @ngInject */
constructor(instanceSettings, private backendSrv, private templateSrv, private $q) { constructor(
instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
private backendSrv: BackendSrv,
private templateSrv: TemplateSrv,
private $q
) {
this.id = instanceSettings.id; this.id = instanceSettings.id;
this.applicationId = instanceSettings.jsonData.appInsightsAppId; this.applicationId = instanceSettings.jsonData.appInsightsAppId;
this.baseUrl = `/appinsights/${this.version}/apps/${this.applicationId}`; this.baseUrl = `/appinsights/${this.version}/apps/${this.applicationId}`;
......
import _ from 'lodash'; import _ from 'lodash';
import LogAnalyticsQuerystringBuilder from '../log_analytics/querystring_builder'; import LogAnalyticsQuerystringBuilder from '../log_analytics/querystring_builder';
import ResponseParser from './response_parser'; import ResponseParser from './response_parser';
import { AzureMonitorQuery } from '../types'; import { AzureMonitorQuery, AzureDataSourceJsonData } from '../types';
import { DataQueryRequest } from '@grafana/ui/src/types'; import { DataQueryRequest, DataSourceInstanceSettings } from '@grafana/ui/src/types';
import { BackendSrv } from 'app/core/services/backend_srv';
import { TemplateSrv } from 'app/features/templating/template_srv';
export default class AzureLogAnalyticsDatasource { export default class AzureLogAnalyticsDatasource {
id: number; id: number;
...@@ -14,7 +16,12 @@ export default class AzureLogAnalyticsDatasource { ...@@ -14,7 +16,12 @@ export default class AzureLogAnalyticsDatasource {
subscriptionId: string; subscriptionId: string;
/** @ngInject */ /** @ngInject */
constructor(private instanceSettings, private backendSrv, private templateSrv, private $q) { constructor(
private instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
private backendSrv: BackendSrv,
private templateSrv: TemplateSrv,
private $q
) {
this.id = instanceSettings.id; this.id = instanceSettings.id;
this.baseUrl = this.instanceSettings.jsonData.azureLogAnalyticsSameAs this.baseUrl = this.instanceSettings.jsonData.azureLogAnalyticsSameAs
? '/sameasloganalyticsazure' ? '/sameasloganalyticsazure'
......
...@@ -4,8 +4,10 @@ import UrlBuilder from './url_builder'; ...@@ -4,8 +4,10 @@ import UrlBuilder from './url_builder';
import ResponseParser from './response_parser'; import ResponseParser from './response_parser';
import SupportedNamespaces from './supported_namespaces'; import SupportedNamespaces from './supported_namespaces';
import TimegrainConverter from '../time_grain_converter'; import TimegrainConverter from '../time_grain_converter';
import { AzureMonitorQuery } from '../types'; import { AzureMonitorQuery, AzureDataSourceJsonData } from '../types';
import { DataQueryRequest } from '@grafana/ui/src/types'; import { DataQueryRequest, DataSourceInstanceSettings } from '@grafana/ui/src/types';
import { BackendSrv } from 'app/core/services/backend_srv';
import { TemplateSrv } from 'app/features/templating/template_srv';
export default class AzureMonitorDatasource { export default class AzureMonitorDatasource {
apiVersion = '2018-01-01'; apiVersion = '2018-01-01';
...@@ -20,7 +22,11 @@ export default class AzureMonitorDatasource { ...@@ -20,7 +22,11 @@ export default class AzureMonitorDatasource {
supportedMetricNamespaces: any[] = []; supportedMetricNamespaces: any[] = [];
/** @ngInject */ /** @ngInject */
constructor(private instanceSettings, private backendSrv, private templateSrv) { constructor(
private instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
private backendSrv: BackendSrv,
private templateSrv: TemplateSrv
) {
this.id = instanceSettings.id; this.id = instanceSettings.id;
this.subscriptionId = instanceSettings.jsonData.subscriptionId; this.subscriptionId = instanceSettings.jsonData.subscriptionId;
this.cloudName = instanceSettings.jsonData.cloudName || 'azuremonitor'; this.cloudName = instanceSettings.jsonData.cloudName || 'azuremonitor';
......
...@@ -2,10 +2,12 @@ import _ from 'lodash'; ...@@ -2,10 +2,12 @@ import _ from 'lodash';
import AzureMonitorDatasource from './azure_monitor/azure_monitor_datasource'; import AzureMonitorDatasource from './azure_monitor/azure_monitor_datasource';
import AppInsightsDatasource from './app_insights/app_insights_datasource'; import AppInsightsDatasource from './app_insights/app_insights_datasource';
import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource'; import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
import { AzureMonitorQuery } from './types'; import { AzureMonitorQuery, AzureDataSourceJsonData } from './types';
import { DataSourceApi, DataQueryRequest } from '@grafana/ui/src/types'; import { DataSourceApi, DataQueryRequest, DataSourceInstanceSettings } from '@grafana/ui/src/types';
import { BackendSrv } from 'app/core/services/backend_srv';
import { TemplateSrv } from 'app/features/templating/template_srv';
export default class Datasource implements DataSourceApi<AzureMonitorQuery> { export default class Datasource implements DataSourceApi<AzureMonitorQuery, AzureDataSourceJsonData> {
id: number; id: number;
name: string; name: string;
azureMonitorDatasource: AzureMonitorDatasource; azureMonitorDatasource: AzureMonitorDatasource;
...@@ -13,7 +15,12 @@ export default class Datasource implements DataSourceApi<AzureMonitorQuery> { ...@@ -13,7 +15,12 @@ export default class Datasource implements DataSourceApi<AzureMonitorQuery> {
azureLogAnalyticsDatasource: AzureLogAnalyticsDatasource; azureLogAnalyticsDatasource: AzureLogAnalyticsDatasource;
/** @ngInject */ /** @ngInject */
constructor(instanceSettings, private backendSrv, private templateSrv, private $q) { constructor(
instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
private backendSrv: BackendSrv,
private templateSrv: TemplateSrv,
private $q
) {
this.name = instanceSettings.name; this.name = instanceSettings.name;
this.id = instanceSettings.id; this.id = instanceSettings.id;
this.azureMonitorDatasource = new AzureMonitorDatasource(instanceSettings, this.backendSrv, this.templateSrv); this.azureMonitorDatasource = new AzureMonitorDatasource(instanceSettings, this.backendSrv, this.templateSrv);
......
import { DataQuery } from '@grafana/ui/src/types'; import { DataQuery, DataSourceJsonData } from '@grafana/ui/src/types';
export interface AzureMonitorQuery extends DataQuery { export interface AzureMonitorQuery extends DataQuery {
format: string; format: string;
...@@ -8,6 +8,25 @@ export interface AzureMonitorQuery extends DataQuery { ...@@ -8,6 +8,25 @@ export interface AzureMonitorQuery extends DataQuery {
// appInsights: any; // appInsights: any;
} }
export interface AzureDataSourceJsonData extends DataSourceJsonData {
subscriptionId: string;
cloudName: string;
// monitor
tenantId?: string;
clientId?: string;
// logs
logAnalyticsSubscriptionId?: string;
logAnalyticsTenantId?: string;
logAnalyticsClientId?: string;
azureLogAnalyticsSameAs?: string;
logAnalyticsDefaultWorkspace?: string;
// App Insights
appInsightsAppId?: string;
}
export interface AzureMetricQuery { export interface AzureMetricQuery {
resourceGroup: string; resourceGroup: string;
resourceName: string; resourceName: string;
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
} from '@grafana/ui/src/types'; } from '@grafana/ui/src/types';
import { InputQuery, InputOptions } from './types'; import { InputQuery, InputOptions } from './types';
export class InputDatasource implements DataSourceApi<InputQuery> { export class InputDatasource implements DataSourceApi<InputQuery, InputOptions> {
data: SeriesData[]; data: SeriesData[];
// Filled in by grafana plugin system // Filled in by grafana plugin system
......
...@@ -6,6 +6,6 @@ import { InputQueryEditor } from './InputQueryEditor'; ...@@ -6,6 +6,6 @@ import { InputQueryEditor } from './InputQueryEditor';
import { InputConfigEditor } from './InputConfigEditor'; import { InputConfigEditor } from './InputConfigEditor';
import { InputOptions, InputQuery } from './types'; import { InputOptions, InputQuery } from './types';
export const plugin = new DataSourcePlugin<InputOptions, InputQuery>(InputDatasource) export const plugin = new DataSourcePlugin<InputQuery, InputOptions>(InputDatasource)
.setConfigEditor(InputConfigEditor) .setConfigEditor(InputConfigEditor)
.setQueryEditor(InputQueryEditor); .setQueryEditor(InputQueryEditor);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment