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

(cloudwatch) expand multi select template variable

Mitsuhiro Tanda 9 лет назад
Родитель
Сommit
490141da82
1 измененных файлов с 31 добавлено и 0 удалено
  1. 31 0
      public/app/plugins/datasource/cloudwatch/datasource.js

+ 31 - 0
public/app/plugins/datasource/cloudwatch/datasource.js

@@ -23,6 +23,7 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) {
 
       var queries = [];
       options = angular.copy(options);
+      options.targets = this.expandTemplateVariable(options.targets);
       _.each(options.targets, function(target) {
         if (target.hide || !target.namespace || !target.metricName || _.isEmpty(target.statistics)) {
           return;
@@ -337,6 +338,36 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) {
       });
     }
 
+    this.expandTemplateVariable = function(targets) {
+      return _.chain(targets)
+      .map(function(target) {
+        var dimensionKey = null;
+        var variableName = null;
+        _.each(target.dimensions, function(v, k) {
+          if (templateSrv.variableExists(v)) {
+            dimensionKey = k;
+            variableName = v;
+          }
+        });
+        if (dimensionKey) {
+          var variable = _.find(templateSrv.variables, function(variable) {
+            return templateSrv.containsVariable(variableName, variable.name);
+          });
+          return _.chain(variable.options)
+          .filter(function(v) {
+            return v.selected;
+          })
+          .map(function(v) {
+            var t = angular.copy(target);
+            t.dimensions[dimensionKey] = v.value;
+            return t;
+          }).value();
+        } else {
+          return [target];
+        }
+      }).flatten().value();
+    };
+
     this.convertToCloudWatchTime = function(date, roundUp) {
       if (_.isString(date)) {
         date = dateMath.parse(date, roundUp);