diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index eef2d77f5e2..d4c622eac55 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -124,13 +124,7 @@ function (angular, _) { }; return this.awsRequest(request).then(function(result) { - return _.chain(result.Metrics).map(function(metric) { - return _.pluck(metric.Dimensions, 'Value'); - }).flatten().uniq().sortBy(function(name) { - return name; - }).map(function(value) { - return {value: value, text: value}; - }).value(); + return _.pluck(result.Metrics, 'Dimensions'); }); }; @@ -191,7 +185,20 @@ function (angular, _) { }); } - return this.getDimensionValues(region, namespace, metricName, dimensions); + return this.getDimensionValues(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?([^,]+?)\)/); diff --git a/public/app/plugins/datasource/cloudwatch/query_ctrl.js b/public/app/plugins/datasource/cloudwatch/query_ctrl.js index 3869a5ec715..7bcc73b4323 100644 --- a/public/app/plugins/datasource/cloudwatch/query_ctrl.js +++ b/public/app/plugins/datasource/cloudwatch/query_ctrl.js @@ -76,7 +76,7 @@ function (angular, _) { } }; - $scope.getDimSegments = function(segment) { + $scope.getDimSegments = function(segment, $index) { if (segment.type === 'operator') { return $q.when([]); } var target = $scope.target; @@ -88,7 +88,22 @@ function (angular, _) { query = $scope.datasource.getDimensionValues(target.region, target.namespace, target.metricName, {}); } - return query.then($scope.transformToSegments(true)).then(function(results) { + return query.then(function(results) { + if (segment.type === 'value') { + results = _.chain(results) + .flatten(true) + .filter(function(dimension) { + return dimension.Name === templateSrv.replace($scope.dimSegments[$index-2].value); + }) + .pluck('Value') + .uniq() + .map(function(value) { + return {value: value, text: value}; + }) + .value(); + } + return $scope.transformToSegments(true)(results); + }).then(function(results) { if (segment.type === 'key') { results.splice(0, 0, angular.copy($scope.removeDimSegment)); } diff --git a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts index 4714a642d30..a6d4330a37e 100644 --- a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts @@ -165,7 +165,7 @@ describe('CloudWatchDatasource', function() { }); it('should call __ListMetrics and return result', () => { - expect(scenario.result[0].text).to.be('i-12345678'); + expect(scenario.result[0].text).to.be('InstanceId=i-12345678'); expect(scenario.request.data.action).to.be('ListMetrics'); }); });