Browse Source

changes implementation direction

moving average will now be based on another metric
instead of having moving average on itself
carl bergquist 10 năm trước cách đây
mục cha
commit
ad79df9b74

+ 13 - 8
public/app/plugins/datasource/elasticsearch/metric_agg.js

@@ -13,6 +13,7 @@ function (angular, _, queryDef) {
 
     $scope.metricAggTypes = queryDef.metricAggTypes;
     $scope.extendedStats = queryDef.extendedStats;
+    $scope.mavgSourceOptions = [];
 
     $scope.init = function() {
       $scope.agg = metricAggs[$scope.index];
@@ -22,6 +23,7 @@ function (angular, _, queryDef) {
     $rootScope.onAppEvent('elastic-query-updated', function() {
       $scope.index = _.indexOf(metricAggs, $scope.agg);
       $scope.validateModel();
+      $scope.updateMovingAverageOptions();
     }, $scope);
 
     $scope.validateModel = function() {
@@ -36,7 +38,8 @@ function (angular, _, queryDef) {
 
       switch($scope.agg.type) {
         case 'moving_avg': {
-          $scope.agg.aggregation = $scope.agg.aggregation || 'sum';
+          $scope.agg.mavgSource = $scope.agg.mavgSource || '';
+          $scope.settingsLinkText = 'Moving average options';
           break;
         }
         case 'percentiles': {
@@ -69,6 +72,11 @@ function (angular, _, queryDef) {
 
     $scope.toggleOptions = function() {
       $scope.showOptions = !$scope.showOptions;
+      $scope.updateMovingAverageOptions();
+    };
+
+    $scope.onChangeInternal = function() {
+      $scope.onChange();
     };
 
     $scope.onTypeChange = function() {
@@ -82,13 +90,6 @@ function (angular, _, queryDef) {
       return $scope.getFields({$fieldType: 'number'});
     };
 
-    $scope.getMetrics = function() {
-      var aggs = [{ text: 'Sum', type: 'sum'}, { text: 'Average', type: 'avg'}];
-
-      return $q.when(aggs)
-        .then(uiSegmentSrv.transformToSegments(false));
-    };
-
     $scope.addMetricAgg = function() {
       var addIndex = metricAggs.length;
 
@@ -100,6 +101,10 @@ function (angular, _, queryDef) {
       $scope.onChange();
     };
 
+    $scope.updateMovingAverageOptions = function() {
+      $scope.mvagSourceOptions = queryDef.getMovingAverageSourceOptions($scope.target);
+    };
+
     $scope.removeMetricAgg = function() {
       metricAggs.splice($scope.index, 1);
       $scope.onChange();

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

@@ -9,9 +9,6 @@
 		<li ng-if="aggDef.requiresField">
 			<metric-segment-model property="agg.field" get-options="getFieldsInternal()" on-change="onChange()" css-class="tight-form-item-xxlarge"></metric-segment-model>
 		</li>
-		<li ng-if="aggDef.requiresBucketsPath">
-			<metric-segment-model property="agg.aggregation" get-options="getMetrics()" on-change="onChange()" css-class="tight-form-item-xxlarge"></metric-segment-model>
-		</li>
 		<li class="tight-form-item last" ng-if="settingsLinkText">
 			<a ng-click="toggleOptions()">{{settingsLinkText}}</a>
 		</li>
@@ -30,6 +27,17 @@
 
 <div class="tight-form" ng-if="showOptions">
 	<div class="tight-form-inner-box">
+		<div class="tight-form last" ng-if="agg.type === 'moving_avg'">
+			<ul class="tight-form-list">
+				<li class="tight-form-item">
+					Based on
+				</li>
+				<li>
+					<metric-segment-model property="agg.mavgSource" options="mavgSourceOptions" on-change="onChangeInternal()" css-class="last"></metric-segment-model>
+				</li>
+			</ul>
+			<div class="clearfix"></div>
+		</div>
 		<div class="tight-form last" ng-if="agg.type === 'percentiles'">
 			<ul class="tight-form-list">
 				<li class="tight-form-item">

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

@@ -169,14 +169,9 @@ function () {
 
       var aggField = {};
       var metricAgg = null;
-      if (metric.type === 'moving_avg') {
-        var subBucket = metric.id + "_mavg";
-
-        var af = {};
-        af[metric.aggregation] = {field: metric.field};
-        nestedAggs.aggs[subBucket] = af;
 
-        metricAgg = { buckets_path: subBucket };
+      if (metric.type === 'moving_avg') {
+        metricAgg = {buckets_path: "1"};
       } else {
         metricAgg = {field: metric.field};
       }

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

@@ -13,7 +13,7 @@ function (_) {
       {text: "Min",  value: 'min', requiresField: true},
       {text: "Extended Stats",  value: 'extended_stats', requiresField: true},
       {text: "Percentiles",  value: 'percentiles', requiresField: true},
-      {text: "Moving Avg",  value: 'moving_avg', requiresField: false, requiresBucketsPath: true},
+      {text: "Moving Avg",  value: 'moving_avg', requiresField: false },
       {text: "Unique Count", value: "cardinality", requiresField: true},
       {text: "Raw Document", value: "raw_document", requiresField: false}
     ],