From ae7e7e96565055dadfca9fbbcaf42428d37c23ff Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 17 Nov 2015 22:49:46 +0900 Subject: [PATCH] remove getDimensions() --- .../datasource/cloudwatch/datasource.js | 37 ++----------------- .../cloudwatch/specs/datasource_specs.ts | 24 ------------ 2 files changed, 4 insertions(+), 57 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index 9b4bed35e90..7297346b33c 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -112,7 +112,7 @@ function (angular, _) { }); }; - CloudWatchDatasource.prototype.getDimensions = function(region, namespace, metricName, filterDimensions) { + CloudWatchDatasource.prototype.getDimensionValues = function(region, namespace, metricName, dimensionKey, filterDimensions) { var request = { region: templateSrv.replace(region), action: 'ListMetrics', @@ -124,13 +124,8 @@ function (angular, _) { }; return this.awsRequest(request).then(function(result) { - return _.pluck(result.Metrics, 'Dimensions'); - }); - }; - - CloudWatchDatasource.prototype.getDimensionValues = function(region, namespace, metricName, dimensionKey, filterDimensions) { - return this.getDimensions(region, namespace, metricName, filterDimensions).then(function(dimensions) { - return _.chain(dimensions) + return _.chain(result.Metrics) + .pluck('Dimensions') .flatten() .filter(function(dimension) { return dimension.Name === dimensionKey; @@ -212,30 +207,6 @@ function (angular, _) { return this.getDimensionValues(region, namespace, metricName, dimensionKey, dimensions); } - var dimensionsQuery = query.match(/^dimensions\(([^,]+?),\s?([^,]+?),\s?([^,]+?)(,\s?([^)]*))?\)/); - if (dimensionsQuery) { - region = templateSrv.replace(dimensionsQuery[1]); - namespace = templateSrv.replace(dimensionsQuery[2]); - metricName = templateSrv.replace(dimensionsQuery[3]); - dimensionPart = templateSrv.replace(dimensionsQuery[5]); - - dimensions = parseDimensions(dimensionPart); - return this.getDimensions(region, namespace, metricName, dimensions).then(function(result) { - return _.map(result, function(dimensions) { - var values = _.chain(dimensions) - .sortBy(function(dimension) { - return dimension.Name; - }) - .map(function(dimension) { - return dimension.Name + '=' + dimension.Value; - }) - .value().join(','); - - return { text: values }; - }); - }); - } - var ebsVolumeIdsQuery = query.match(/^ebs_volume_ids\(([^,]+?),\s?([^,]+?)\)/); if (ebsVolumeIdsQuery) { region = templateSrv.replace(ebsVolumeIdsQuery[1]); @@ -263,7 +234,7 @@ function (angular, _) { var metricName = 'EstimatedCharges'; var dimensions = {}; - return this.getDimensions(region, namespace, metricName, dimensions).then(function () { + return this.getDimensionValues(region, namespace, metricName, 'ServiceName', dimensions).then(function () { return { status: 'success', message: 'Data source is working', title: 'Success' }; }); }; diff --git a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts index 6c55eab55ca..b97dff5ce3b 100644 --- a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts @@ -146,30 +146,6 @@ describe('CloudWatchDatasource', function() { }); }); - describeMetricFindQuery('dimensions(us-east-1,AWS/EC2,CPUUtilization)', scenario => { - scenario.setup(() => { - scenario.requestResponse = { - Metrics: [ - { - Namespace: 'AWS/EC2', - MetricName: 'CPUUtilization', - Dimensions: [ - { - Name: 'InstanceId', - Value: 'i-12345678' - } - ] - } - ] - }; - }); - - it('should call __ListMetrics and return result', () => { - expect(scenario.result[0].text).to.be('InstanceId=i-12345678'); - expect(scenario.request.data.action).to.be('ListMetrics'); - }); - }); - describeMetricFindQuery('dimension_values(us-east-1,AWS/EC2,CPUUtilization,InstanceId)', scenario => { scenario.setup(() => { scenario.requestResponse = {