|
|
@@ -1,9 +1,9 @@
|
|
|
-import angular from 'angular';
|
|
|
+import angular, { IQService } from 'angular';
|
|
|
import _ from 'lodash';
|
|
|
import { dateMath } from '@grafana/data';
|
|
|
import kbn from 'app/core/utils/kbn';
|
|
|
import { CloudWatchQuery } from './types';
|
|
|
-import { DataSourceApi, DataQueryRequest, DataSourceInstanceSettings } from '@grafana/ui';
|
|
|
+import { DataSourceApi, DataQueryRequest, DataSourceInstanceSettings, ScopedVars } from '@grafana/ui';
|
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
|
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
|
|
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
|
|
@@ -18,7 +18,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
/** @ngInject */
|
|
|
constructor(
|
|
|
private instanceSettings: DataSourceInstanceSettings,
|
|
|
- private $q,
|
|
|
+ private $q: IQService,
|
|
|
private backendSrv: BackendSrv,
|
|
|
private templateSrv: TemplateSrv,
|
|
|
private timeSrv: TimeSrv
|
|
|
@@ -96,7 +96,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
return this.performTimeSeriesQuery(request);
|
|
|
}
|
|
|
|
|
|
- getPeriod(target, options, now?) {
|
|
|
+ getPeriod(target: any, options: any, now?: number) {
|
|
|
const start = this.convertToCloudWatchTime(options.range.from, false);
|
|
|
const end = this.convertToCloudWatchTime(options.range.to, true);
|
|
|
now = Math.round((now || Date.now()) / 1000);
|
|
|
@@ -142,8 +142,8 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
return period;
|
|
|
}
|
|
|
|
|
|
- performTimeSeriesQuery(request) {
|
|
|
- return this.awsRequest('/api/tsdb/query', request).then(res => {
|
|
|
+ performTimeSeriesQuery(request: any) {
|
|
|
+ return this.awsRequest('/api/tsdb/query', request).then((res: any) => {
|
|
|
const data = [];
|
|
|
|
|
|
if (res.results) {
|
|
|
@@ -165,7 +165,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- transformSuggestDataFromTable(suggestData) {
|
|
|
+ transformSuggestDataFromTable(suggestData: any) {
|
|
|
return _.map(suggestData.results['metricFindQuery'].tables[0].rows, v => {
|
|
|
return {
|
|
|
text: v[0],
|
|
|
@@ -174,7 +174,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- doMetricQueryRequest(subtype, parameters) {
|
|
|
+ doMetricQueryRequest(subtype: any, parameters: any) {
|
|
|
const range = this.timeSrv.timeRange();
|
|
|
return this.awsRequest('/api/tsdb/query', {
|
|
|
from: range.from.valueOf().toString(),
|
|
|
@@ -192,7 +192,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
parameters
|
|
|
),
|
|
|
],
|
|
|
- }).then(r => {
|
|
|
+ }).then((r: any) => {
|
|
|
return this.transformSuggestDataFromTable(r);
|
|
|
});
|
|
|
}
|
|
|
@@ -205,21 +205,27 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
return this.doMetricQueryRequest('namespaces', null);
|
|
|
}
|
|
|
|
|
|
- getMetrics(namespace, region) {
|
|
|
+ getMetrics(namespace: string, region: string) {
|
|
|
return this.doMetricQueryRequest('metrics', {
|
|
|
region: this.templateSrv.replace(this.getActualRegion(region)),
|
|
|
namespace: this.templateSrv.replace(namespace),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- getDimensionKeys(namespace, region) {
|
|
|
+ getDimensionKeys(namespace: string, region: string) {
|
|
|
return this.doMetricQueryRequest('dimension_keys', {
|
|
|
region: this.templateSrv.replace(this.getActualRegion(region)),
|
|
|
namespace: this.templateSrv.replace(namespace),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- getDimensionValues(region, namespace, metricName, dimensionKey, filterDimensions) {
|
|
|
+ getDimensionValues(
|
|
|
+ region: string,
|
|
|
+ namespace: string,
|
|
|
+ metricName: string,
|
|
|
+ dimensionKey: string,
|
|
|
+ filterDimensions: {}
|
|
|
+ ) {
|
|
|
return this.doMetricQueryRequest('dimension_values', {
|
|
|
region: this.templateSrv.replace(this.getActualRegion(region)),
|
|
|
namespace: this.templateSrv.replace(namespace),
|
|
|
@@ -229,14 +235,14 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- getEbsVolumeIds(region, instanceId) {
|
|
|
+ getEbsVolumeIds(region: string, instanceId: string) {
|
|
|
return this.doMetricQueryRequest('ebs_volume_ids', {
|
|
|
region: this.templateSrv.replace(this.getActualRegion(region)),
|
|
|
instanceId: this.templateSrv.replace(instanceId),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- getEc2InstanceAttribute(region, attributeName, filters) {
|
|
|
+ getEc2InstanceAttribute(region: string, attributeName: string, filters: any) {
|
|
|
return this.doMetricQueryRequest('ec2_instance_attribute', {
|
|
|
region: this.templateSrv.replace(this.getActualRegion(region)),
|
|
|
attributeName: this.templateSrv.replace(attributeName),
|
|
|
@@ -244,7 +250,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- getResourceARNs(region, resourceType, tags) {
|
|
|
+ getResourceARNs(region: string, resourceType: string, tags: any) {
|
|
|
return this.doMetricQueryRequest('resource_arns', {
|
|
|
region: this.templateSrv.replace(this.getActualRegion(region)),
|
|
|
resourceType: this.templateSrv.replace(resourceType),
|
|
|
@@ -252,7 +258,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- metricFindQuery(query) {
|
|
|
+ metricFindQuery(query: string) {
|
|
|
let region;
|
|
|
let namespace;
|
|
|
let metricName;
|
|
|
@@ -324,7 +330,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
return this.$q.when([]);
|
|
|
}
|
|
|
|
|
|
- annotationQuery(options) {
|
|
|
+ annotationQuery(options: any) {
|
|
|
const annotation = options.annotation;
|
|
|
const statistics = _.map(annotation.statistics, s => {
|
|
|
return this.templateSrv.replace(s);
|
|
|
@@ -359,7 +365,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
parameters
|
|
|
),
|
|
|
],
|
|
|
- }).then(r => {
|
|
|
+ }).then((r: any) => {
|
|
|
return _.map(r.results['annotationQuery'].tables[0].rows, v => {
|
|
|
return {
|
|
|
annotation: annotation,
|
|
|
@@ -372,7 +378,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- targetContainsTemplate(target) {
|
|
|
+ targetContainsTemplate(target: any) {
|
|
|
return (
|
|
|
this.templateSrv.variableExists(target.region) ||
|
|
|
this.templateSrv.variableExists(target.namespace) ||
|
|
|
@@ -395,14 +401,14 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- awsRequest(url, data) {
|
|
|
+ awsRequest(url: string, data: any) {
|
|
|
const options = {
|
|
|
method: 'POST',
|
|
|
- url: url,
|
|
|
- data: data,
|
|
|
+ url,
|
|
|
+ data,
|
|
|
};
|
|
|
|
|
|
- return this.backendSrv.datasourceRequest(options).then(result => {
|
|
|
+ return this.backendSrv.datasourceRequest(options).then((result: any) => {
|
|
|
return result.data;
|
|
|
});
|
|
|
}
|
|
|
@@ -411,14 +417,14 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
return this.defaultRegion;
|
|
|
}
|
|
|
|
|
|
- getActualRegion(region) {
|
|
|
+ getActualRegion(region: string) {
|
|
|
if (region === 'default' || _.isEmpty(region)) {
|
|
|
return this.getDefaultRegion();
|
|
|
}
|
|
|
return region;
|
|
|
}
|
|
|
|
|
|
- getExpandedVariables(target, dimensionKey, variable, templateSrv) {
|
|
|
+ getExpandedVariables(target: any, dimensionKey: any, variable: any, templateSrv: TemplateSrv) {
|
|
|
/* if the all checkbox is marked we should add all values to the targets */
|
|
|
const allSelected: any = _.find(variable.options, { selected: true, text: 'All' });
|
|
|
const selectedVariables = _.filter(variable.options, v => {
|
|
|
@@ -430,7 +436,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
const currentVariables = !_.isArray(variable.current.value)
|
|
|
? [variable.current]
|
|
|
- : variable.current.value.map(v => {
|
|
|
+ : variable.current.value.map((v: any) => {
|
|
|
return {
|
|
|
text: v,
|
|
|
value: v,
|
|
|
@@ -440,9 +446,9 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
selectedVariables.some((s: any) => {
|
|
|
return s.value === currentVariables[0].value;
|
|
|
}) || currentVariables[0].value === '$__all';
|
|
|
- return (useSelectedVariables ? selectedVariables : currentVariables).map(v => {
|
|
|
+ return (useSelectedVariables ? selectedVariables : currentVariables).map((v: any) => {
|
|
|
const t = angular.copy(target);
|
|
|
- const scopedVar = {};
|
|
|
+ const scopedVar: any = {};
|
|
|
scopedVar[variable.name] = v;
|
|
|
t.refId = target.refId + '_' + v.value;
|
|
|
t.dimensions[dimensionKey] = templateSrv.replace(t.dimensions[dimensionKey], scopedVar);
|
|
|
@@ -455,7 +461,7 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- expandTemplateVariable(targets, scopedVars, templateSrv) {
|
|
|
+ expandTemplateVariable(targets: any, scopedVars: ScopedVars, templateSrv: TemplateSrv) {
|
|
|
// Datasource and template srv logic uber-complected. This should be cleaned up.
|
|
|
return _.chain(targets)
|
|
|
.map(target => {
|
|
|
@@ -480,15 +486,15 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery>
|
|
|
.value();
|
|
|
}
|
|
|
|
|
|
- convertToCloudWatchTime(date, roundUp) {
|
|
|
+ convertToCloudWatchTime(date: any, roundUp: any) {
|
|
|
if (_.isString(date)) {
|
|
|
date = dateMath.parse(date, roundUp);
|
|
|
}
|
|
|
return Math.round(date.valueOf() / 1000);
|
|
|
}
|
|
|
|
|
|
- convertDimensionFormat(dimensions, scopedVars) {
|
|
|
- const convertedDimensions = {};
|
|
|
+ convertDimensionFormat(dimensions: any, scopedVars: ScopedVars) {
|
|
|
+ const convertedDimensions: any = {};
|
|
|
_.each(dimensions, (value, key) => {
|
|
|
convertedDimensions[this.templateSrv.replace(key, scopedVars)] = this.templateSrv.replace(value, scopedVars);
|
|
|
});
|