Commit f5eb54e5 by carl bergquist

feat(elasticsearch): only show pipeline agg for es version >= 2

parent 56c3dd36
...@@ -30,6 +30,7 @@ function (angular) { ...@@ -30,6 +30,7 @@ function (angular) {
index: "=", index: "=",
onChange: "&", onChange: "&",
getFields: "&", getFields: "&",
esVersion: '='
} }
}; };
}); });
......
...@@ -11,7 +11,7 @@ function (angular, _, queryDef) { ...@@ -11,7 +11,7 @@ function (angular, _, queryDef) {
module.controller('ElasticMetricAggCtrl', function($scope, uiSegmentSrv, $q, $rootScope) { module.controller('ElasticMetricAggCtrl', function($scope, uiSegmentSrv, $q, $rootScope) {
var metricAggs = $scope.target.metrics; var metricAggs = $scope.target.metrics;
$scope.metricAggTypes = queryDef.metricAggTypes; $scope.metricAggTypes = queryDef.getMetricAggTypes($scope.esVersion);
$scope.extendedStats = queryDef.extendedStats; $scope.extendedStats = queryDef.extendedStats;
$scope.pipelineAggOptions = []; $scope.pipelineAggOptions = [];
......
...@@ -65,7 +65,8 @@ ...@@ -65,7 +65,8 @@
<elastic-metric-agg <elastic-metric-agg
target="target" index="$index" target="target" index="$index"
get-fields="getFields($fieldType)" get-fields="getFields($fieldType)"
on-change="queryUpdated()"> on-change="queryUpdated()"
es-version="esVersion">
</elastic-metric-agg> </elastic-metric-agg>
</div> </div>
......
...@@ -7,6 +7,7 @@ function (angular) { ...@@ -7,6 +7,7 @@ function (angular) {
var module = angular.module('grafana.controllers'); var module = angular.module('grafana.controllers');
module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv) { module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv) {
$scope.esVersion = $scope.datasource.esVersion;
$scope.init = function() { $scope.init = function() {
var target = $scope.target; var target = $scope.target;
......
...@@ -14,8 +14,8 @@ function (_) { ...@@ -14,8 +14,8 @@ function (_) {
{text: "Extended Stats", value: 'extended_stats', requiresField: true, supportsMissing: true, supportsInlineScript: true}, {text: "Extended Stats", value: 'extended_stats', requiresField: true, supportsMissing: true, supportsInlineScript: true},
{text: "Percentiles", value: 'percentiles', requiresField: true, supportsMissing: true, supportsInlineScript: true}, {text: "Percentiles", value: 'percentiles', requiresField: true, supportsMissing: true, supportsInlineScript: true},
{text: "Unique Count", value: "cardinality", requiresField: true, supportsMissing: true}, {text: "Unique Count", value: "cardinality", requiresField: true, supportsMissing: true},
{text: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true }, {text: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true, minVersion: 2},
{text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true }, {text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true, minVersion: 2 },
{text: "Raw Document", value: "raw_document", requiresField: false} {text: "Raw Document", value: "raw_document", requiresField: false}
], ],
...@@ -76,6 +76,16 @@ function (_) { ...@@ -76,6 +76,16 @@ function (_) {
'derivative': [] 'derivative': []
}, },
getMetricAggTypes: function(esVersion) {
return _.filter(this.metricAggTypes, function(f) {
if (f.minVersion) {
return f.minVersion <= esVersion;
} else {
return true;
}
});
},
getPipelineOptions: function(metric) { getPipelineOptions: function(metric) {
if (!this.isPipelineAgg(metric.type)) { if (!this.isPipelineAgg(metric.type)) {
return []; return [];
......
...@@ -79,4 +79,24 @@ describe('ElasticQueryDef', function() { ...@@ -79,4 +79,24 @@ describe('ElasticQueryDef', function() {
}); });
}); });
}); });
describe('pipeline aggs depending on esverison', function() {
describe('using esversion undefined', function() {
it('should not get pipeline aggs', function() {
expect(QueryDef.getMetricAggTypes(undefined).length).to.be(9);
});
});
describe('using esversion 1', function() {
it('should not get pipeline aggs', function() {
expect(QueryDef.getMetricAggTypes(1).length).to.be(9);
});
});
describe('using esversion 2', function() {
it('should get pipeline aggs', function() {
expect(QueryDef.getMetricAggTypes(2).length).to.be(11);
});
});
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment