Commit bc328cbe by Torkel Ödegaard

feat(plugins): upgraded Cloudwatch to new plugin schema

parent 7ae81a21
declare var Datasource: any;
export default Datasource;
...@@ -4,24 +4,19 @@ define([ ...@@ -4,24 +4,19 @@ define([
'moment', 'moment',
'app/core/utils/datemath', 'app/core/utils/datemath',
'./query_ctrl', './query_ctrl',
'./directives',
], ],
function (angular, _, moment, dateMath) { function (angular, _, moment, dateMath) {
'use strict'; 'use strict';
var module = angular.module('grafana.services'); /** @ngInject */
function CloudWatchDatasource(instanceSettings, $q, backendSrv, templateSrv) {
module.factory('CloudWatchDatasource', function($q, backendSrv, templateSrv) {
function CloudWatchDatasource(datasource) {
this.type = 'cloudwatch'; this.type = 'cloudwatch';
this.name = datasource.name; this.name = instanceSettings.name;
this.supportMetrics = true; this.supportMetrics = true;
this.proxyUrl = datasource.url; this.proxyUrl = instanceSettings.url;
this.defaultRegion = datasource.jsonData.defaultRegion; this.defaultRegion = instanceSettings.jsonData.defaultRegion;
}
CloudWatchDatasource.prototype.query = function(options) { this.query = function(options) {
var start = convertToCloudWatchTime(options.range.from, false); var start = convertToCloudWatchTime(options.range.from, false);
var end = convertToCloudWatchTime(options.range.to, true); var end = convertToCloudWatchTime(options.range.to, true);
...@@ -72,7 +67,7 @@ function (angular, _, moment, dateMath) { ...@@ -72,7 +67,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.performTimeSeriesQuery = function(query, start, end) { this.performTimeSeriesQuery = function(query, start, end) {
return this.awsRequest({ return this.awsRequest({
region: query.region, region: query.region,
action: 'GetMetricStatistics', action: 'GetMetricStatistics',
...@@ -88,15 +83,15 @@ function (angular, _, moment, dateMath) { ...@@ -88,15 +83,15 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.getRegions = function() { this.getRegions = function() {
return this.awsRequest({action: '__GetRegions'}); return this.awsRequest({action: '__GetRegions'});
}; };
CloudWatchDatasource.prototype.getNamespaces = function() { this.getNamespaces = function() {
return this.awsRequest({action: '__GetNamespaces'}); return this.awsRequest({action: '__GetNamespaces'});
}; };
CloudWatchDatasource.prototype.getMetrics = function(namespace) { this.getMetrics = function(namespace) {
return this.awsRequest({ return this.awsRequest({
action: '__GetMetrics', action: '__GetMetrics',
parameters: { parameters: {
...@@ -105,7 +100,7 @@ function (angular, _, moment, dateMath) { ...@@ -105,7 +100,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.getDimensionKeys = function(namespace) { this.getDimensionKeys = function(namespace) {
return this.awsRequest({ return this.awsRequest({
action: '__GetDimensions', action: '__GetDimensions',
parameters: { parameters: {
...@@ -114,7 +109,7 @@ function (angular, _, moment, dateMath) { ...@@ -114,7 +109,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.getDimensionValues = function(region, namespace, metricName, dimensionKey, filterDimensions) { this.getDimensionValues = function(region, namespace, metricName, dimensionKey, filterDimensions) {
var request = { var request = {
region: templateSrv.replace(region), region: templateSrv.replace(region),
action: 'ListMetrics', action: 'ListMetrics',
...@@ -141,7 +136,7 @@ function (angular, _, moment, dateMath) { ...@@ -141,7 +136,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.performEC2DescribeInstances = function(region, filters, instanceIds) { this.performEC2DescribeInstances = function(region, filters, instanceIds) {
return this.awsRequest({ return this.awsRequest({
region: region, region: region,
action: 'DescribeInstances', action: 'DescribeInstances',
...@@ -149,7 +144,7 @@ function (angular, _, moment, dateMath) { ...@@ -149,7 +144,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.metricFindQuery = function(query) { this.metricFindQuery = function(query) {
var region; var region;
var namespace; var namespace;
var metricName; var metricName;
...@@ -210,7 +205,7 @@ function (angular, _, moment, dateMath) { ...@@ -210,7 +205,7 @@ function (angular, _, moment, dateMath) {
return $q.when([]); return $q.when([]);
}; };
CloudWatchDatasource.prototype.performDescribeAlarmsForMetric = function(region, namespace, metricName, dimensions, statistic, period) { this.performDescribeAlarmsForMetric = function(region, namespace, metricName, dimensions, statistic, period) {
return this.awsRequest({ return this.awsRequest({
region: region, region: region,
action: 'DescribeAlarmsForMetric', action: 'DescribeAlarmsForMetric',
...@@ -218,7 +213,7 @@ function (angular, _, moment, dateMath) { ...@@ -218,7 +213,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.performDescribeAlarmHistory = function(region, alarmName, startDate, endDate) { this.performDescribeAlarmHistory = function(region, alarmName, startDate, endDate) {
return this.awsRequest({ return this.awsRequest({
region: region, region: region,
action: 'DescribeAlarmHistory', action: 'DescribeAlarmHistory',
...@@ -226,7 +221,7 @@ function (angular, _, moment, dateMath) { ...@@ -226,7 +221,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.annotationQuery = function(options) { this.annotationQuery = function(options) {
var annotation = options.annotation; var annotation = options.annotation;
var region = templateSrv.replace(annotation.region); var region = templateSrv.replace(annotation.region);
var namespace = templateSrv.replace(annotation.namespace); var namespace = templateSrv.replace(annotation.namespace);
...@@ -278,7 +273,7 @@ function (angular, _, moment, dateMath) { ...@@ -278,7 +273,7 @@ function (angular, _, moment, dateMath) {
return d.promise; return d.promise;
}; };
CloudWatchDatasource.prototype.testDatasource = function() { this.testDatasource = function() {
/* use billing metrics for test */ /* use billing metrics for test */
var region = this.defaultRegion; var region = this.defaultRegion;
var namespace = 'AWS/Billing'; var namespace = 'AWS/Billing';
...@@ -290,7 +285,7 @@ function (angular, _, moment, dateMath) { ...@@ -290,7 +285,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.awsRequest = function(data) { this.awsRequest = function(data) {
var options = { var options = {
method: 'POST', method: 'POST',
url: this.proxyUrl, url: this.proxyUrl,
...@@ -302,7 +297,7 @@ function (angular, _, moment, dateMath) { ...@@ -302,7 +297,7 @@ function (angular, _, moment, dateMath) {
}); });
}; };
CloudWatchDatasource.prototype.getDefaultRegion = function() { this.getDefaultRegion = function() {
return this.defaultRegion; return this.defaultRegion;
}; };
...@@ -361,7 +356,7 @@ function (angular, _, moment, dateMath) { ...@@ -361,7 +356,7 @@ function (angular, _, moment, dateMath) {
}); });
} }
return CloudWatchDatasource; }
});
return CloudWatchDatasource;
}); });
define([ define([
'angular', 'angular',
'./datasource',
'./query_parameter_ctrl', './query_parameter_ctrl',
], ],
function (angular) { function (angular, CloudWatchDatasource) {
'use strict'; 'use strict';
var module = angular.module('grafana.directives'); var module = angular.module('grafana.directives');
...@@ -28,4 +29,11 @@ function (angular) { ...@@ -28,4 +29,11 @@ function (angular) {
}; };
}); });
module.directive('datasourceCustomSettingsViewCloudwatch', function() {
return {templateUrl: 'app/plugins/datasource/cloudwatch/partials/edit_view.html'};
});
return {
Datasource: CloudWatchDatasource
};
}); });
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
"name": "CloudWatch", "name": "CloudWatch",
"id": "cloudwatch", "id": "cloudwatch",
"serviceName": "CloudWatchDatasource", "module": "app/plugins/datasource/cloudwatch/module",
"module": "app/plugins/datasource/cloudwatch/datasource",
"partials": { "partials": {
"config": "app/plugins/datasource/cloudwatch/partials/config.html", "config": "app/plugins/datasource/cloudwatch/partials/config.html",
......
...@@ -3,25 +3,25 @@ import "../datasource"; ...@@ -3,25 +3,25 @@ import "../datasource";
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common'; import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
import moment from 'moment'; import moment from 'moment';
import helpers from 'test/specs/helpers'; import helpers from 'test/specs/helpers';
import Datasource from "../datasource";
describe('CloudWatchDatasource', function() { describe('CloudWatchDatasource', function() {
var ctx = new helpers.ServiceTestContext(); var ctx = new helpers.ServiceTestContext();
var instanceSettings = {
jsonData: {defaultRegion: 'us-east-1', access: 'proxy'},
};
beforeEach(angularMocks.module('grafana.core')); beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services')); beforeEach(angularMocks.module('grafana.services'));
beforeEach(angularMocks.module('grafana.controllers')); beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(ctx.providePhase(['templateSrv', 'backendSrv'])); beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
beforeEach(ctx.createService('CloudWatchDatasource'));
beforeEach(function() { beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
ctx.ds = new ctx.service({ ctx.$q = $q;
jsonData: { ctx.$httpBackend = $httpBackend;
defaultRegion: 'us-east-1', ctx.$rootScope = $rootScope;
access: 'proxy' ctx.ds = $injector.instantiate(Datasource, {instanceSettings: instanceSettings});
} }));
});
});
describe('When performing CloudWatch query', function() { describe('When performing CloudWatch query', function() {
var requestParams; var requestParams;
......
define([
'angular',
'./bucket_agg',
'./metric_agg',
],
function (angular) {
'use strict';
var module = angular.module('grafana.directives');
module.directive('metricQueryEditorElasticsearch', function() {
return {controller: 'ElasticQueryCtrl', templateUrl: 'app/plugins/datasource/elasticsearch/partials/query.editor.html'};
});
module.directive('metricQueryOptionsElasticsearch', function() {
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/query.options.html'};
});
module.directive('annotationsQueryEditorElasticsearch', function() {
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/annotations.editor.html'};
});
module.directive('datasourceCustomSettingsViewElasticsearch', function() {
return {templateUrl: 'app/plugins/datasource/elasticsearch/partials/config.html'};
});
module.directive('elasticMetricAgg', function() {
return {
templateUrl: 'app/plugins/datasource/elasticsearch/partials/metric_agg.html',
controller: 'ElasticMetricAggCtrl',
restrict: 'E',
scope: {
target: "=",
index: "=",
onChange: "&",
getFields: "&",
esVersion: '='
}
};
});
module.directive('elasticBucketAgg', function() {
return {
templateUrl: 'app/plugins/datasource/elasticsearch/partials/bucket_agg.html',
controller: 'ElasticBucketAggCtrl',
restrict: 'E',
scope: {
target: "=",
index: "=",
onChange: "&",
getFields: "&",
}
};
});
});
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