Просмотр исходного кода

fix CloudWatch dimension value suggestion

Mitsuhiro Tanda 10 лет назад
Родитель
Сommit
ef4bec1c6d

+ 15 - 8
public/app/plugins/datasource/cloudwatch/datasource.js

@@ -124,13 +124,7 @@ function (angular, _) {
       };
       };
 
 
       return this.awsRequest(request).then(function(result) {
       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?([^,]+?)\)/);
       var ebsVolumeIdsQuery = query.match(/^ebs_volume_ids\(([^,]+?),\s?([^,]+?)\)/);

+ 17 - 2
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([]); }
       if (segment.type === 'operator') { return $q.when([]); }
 
 
       var target = $scope.target;
       var target = $scope.target;
@@ -88,7 +88,22 @@ function (angular, _) {
         query = $scope.datasource.getDimensionValues(target.region, target.namespace, target.metricName, {});
         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') {
         if (segment.type === 'key') {
           results.splice(0, 0, angular.copy($scope.removeDimSegment));
           results.splice(0, 0, angular.copy($scope.removeDimSegment));
         }
         }

+ 1 - 1
public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts

@@ -165,7 +165,7 @@ describe('CloudWatchDatasource', function() {
     });
     });
 
 
     it('should call __ListMetrics and return result', () => {
     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');
       expect(scenario.request.data.action).to.be('ListMetrics');
     });
     });
   });
   });