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

refactor es pipeline aggregation variables to match ES

carl bergquist 10 лет назад
Родитель
Сommit
8e18f2c5d2

+ 5 - 1
public/app/plugins/datasource/elasticsearch/elastic_response.js

@@ -199,7 +199,11 @@ function (_, queryDef) {
 
     if (series.field && series.metric === 'moving_avg') {
       var appliedAgg = _.findWhere(target.metrics, { id: series.field });
-      metricName += ' ' + queryDef.describeMetric(appliedAgg);
+      if (appliedAgg) {
+        metricName += ' ' + queryDef.describeMetric(appliedAgg);
+      } else {
+        metricName = 'Unset';
+      }
     } else if (series.field) {
       metricName += ' ' + series.field;
     }

+ 3 - 3
public/app/plugins/datasource/elasticsearch/metric_agg.js

@@ -22,7 +22,7 @@ function (angular, _, queryDef) {
     };
 
     $scope.updateMavgOptions = function() {
-      $scope.mavgOptions = queryDef.getMovingAverageSourceOptions($scope.target);
+      $scope.mavgOptions = queryDef.getMovingAverageOptions($scope.target);
     };
 
     $rootScope.onAppEvent('elastic-query-updated', function() {
@@ -43,9 +43,9 @@ function (angular, _, queryDef) {
 
       switch($scope.agg.type) {
         case 'moving_avg': {
-          $scope.agg.mavgSource = $scope.agg.mavgSource || 'Metric to apply moving average';
+          $scope.agg.pipelineAgg = $scope.agg.pipelineAgg || 'Metric to apply moving average';
           $scope.settingsLinkText = 'Moving average options';
-          $scope.agg.field = $scope.agg.mavgSource;
+          $scope.agg.field = $scope.agg.pipelineAgg;
           break;
         }
         case 'percentiles': {

+ 1 - 1
public/app/plugins/datasource/elasticsearch/partials/metricAgg.html

@@ -33,7 +33,7 @@
 					Based on
 				</li>
 				<li>
-					<metric-segment-model property="agg.mavgSource" options="mavgOptions" on-change="onChangeInternal()" css-class="last"></metric-segment-model>
+					<metric-segment-model property="agg.pipelineAgg" options="mavgOptions" on-change="onChangeInternal()" css-class="last"></metric-segment-model>
 				</li>
 			</ul>
 			<div class="clearfix"></div>

+ 2 - 2
public/app/plugins/datasource/elasticsearch/query_builder.js

@@ -171,8 +171,8 @@ function () {
       var metricAgg = null;
 
       if (metric.type === 'moving_avg') {
-        if (metric.mavgSource && /^\d*$/.test(metric.mavgSource)) {
-          metricAgg = { buckets_path: metric.mavgSource };
+        if (metric.pipelineAgg && /^\d*$/.test(metric.pipelineAgg)) {
+          metricAgg = { buckets_path: metric.pipelineAgg };
         } else {
           continue;
         }

+ 11 - 1
public/app/plugins/datasource/elasticsearch/query_def.js

@@ -67,7 +67,17 @@ function (_) {
       {text: '1d', value: '1d'},
     ],
 
-    getMovingAverageSourceOptions: function(targets) {
+    pipelineAggs: ['moving_avg'],
+
+    isPipelineAgg: function(metric) {
+      if (metric.type) {
+        return this.pipelineAggs.indexOf(metric.type) > -1;
+      }
+
+      return false;
+    },
+
+    getMovingAverageOptions: function(targets) {
       var self = this;
       var result = [];
       _.each(targets.metrics, function(metric) {

+ 3 - 3
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts

@@ -167,7 +167,7 @@ describe('ElasticQueryBuilder', function() {
           id: '2',
           type: 'moving_avg',
           field: '3',
-          mavgSource: '3'
+          pipelineAgg: '3'
         }
       ],
       bucketAggs: [
@@ -194,13 +194,13 @@ describe('ElasticQueryBuilder', function() {
                   id: '2',
                   type: 'moving_avg',
                   field: '3',
-                  mavgSource: '3'
+                  pipelineAgg: '3'
               },
               {
                   id: '4',
                   type: 'moving_avg',
                   field: '3',
-                  mavgSource: 'Metric to apply moving average'
+                  pipelineAgg: 'Metric to apply moving average'
               }
           ],
           bucketAggs: [

+ 45 - 25
public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts

@@ -8,41 +8,61 @@ declare var QueryDef: any;
 
 describe('ElasticQueryDef', function() {
 
-  describe('with zero targets', function() {
-    var response = QueryDef.getMovingAverageSourceOptions([]);
+  describe('getMovingAverageOptions', function() {
+    describe('with zero targets', function() {
+      var response = QueryDef.getMovingAverageOptions([]);
 
-    it('should return zero', function() {
-      expect(response.length).to.be(0);
+      it('should return zero', function() {
+        expect(response.length).to.be(0);
+      });
     });
-  });
 
-  describe('with count and sum targets', function() {
-    var targets = {
-      metrics: [
-        { type: 'count', field: '@value' },
-        { type: 'sum', field: '@value' }
-      ]
-    };
+    describe('with count and sum targets', function() {
+      var targets = {
+        metrics: [
+          { type: 'count', field: '@value' },
+          { type: 'sum', field: '@value' }
+        ]
+      };
 
-    var response = QueryDef.getMovingAverageSourceOptions(targets);
+      var response = QueryDef.getMovingAverageOptions(targets);
 
-    it('should return zero', function() {
-      expect(response.length).to.be(2);
+      it('should return zero', function() {
+        expect(response.length).to.be(2);
+      });
+    });
+
+    describe('with count and moving average targets', function() {
+      var targets = {
+        metrics: [
+          { type: 'count', field: '@value' },
+          { type: 'moving_avg', field: '@value' }
+        ]
+      };
+
+      var response = QueryDef.getMovingAverageOptions(targets);
+
+      it('should return zero', function() {
+        expect(response.length).to.be(1);
+      });
     });
   });
 
-  describe('with count and moving average targets', function() {
-    var targets = {
-      metrics: [
-        { type: 'count', field: '@value' },
-        { type: 'moving_avg', field: '@value' }
-      ]
-    };
+  describe('isPipelineMetric', function() {
+    describe('moving_avg', function() {
+      var result = QueryDef.isPipelineAgg({ type: 'moving_avg' });
+
+      it('is pipe line metric', function() {
+        expect(result).to.be(true);
+      });
+    });
 
-    var response = QueryDef.getMovingAverageSourceOptions(targets);
+    describe('count', function() {
+      var result = QueryDef.isPipelineAgg({ type: 'count' });
 
-    it('should return zero', function() {
-      expect(response.length).to.be(1);
+      it('is not pipe line metric', function() {
+        expect(result).to.be(false);
+      });
     });
   });
 });