Commit f5eb54e5 by carl bergquist

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

parent 56c3dd36
......@@ -30,6 +30,7 @@ function (angular) {
index: "=",
onChange: "&",
getFields: "&",
esVersion: '='
}
};
});
......
......@@ -11,7 +11,7 @@ function (angular, _, queryDef) {
module.controller('ElasticMetricAggCtrl', function($scope, uiSegmentSrv, $q, $rootScope) {
var metricAggs = $scope.target.metrics;
$scope.metricAggTypes = queryDef.metricAggTypes;
$scope.metricAggTypes = queryDef.getMetricAggTypes($scope.esVersion);
$scope.extendedStats = queryDef.extendedStats;
$scope.pipelineAggOptions = [];
......
......@@ -65,7 +65,8 @@
<elastic-metric-agg
target="target" index="$index"
get-fields="getFields($fieldType)"
on-change="queryUpdated()">
on-change="queryUpdated()"
es-version="esVersion">
</elastic-metric-agg>
</div>
......
......@@ -7,6 +7,7 @@ function (angular) {
var module = angular.module('grafana.controllers');
module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv) {
$scope.esVersion = $scope.datasource.esVersion;
$scope.init = function() {
var target = $scope.target;
......
......@@ -14,8 +14,8 @@ function (_) {
{text: "Extended Stats", value: 'extended_stats', 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: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true },
{text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true },
{text: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true, minVersion: 2},
{text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true, minVersion: 2 },
{text: "Raw Document", value: "raw_document", requiresField: false}
],
......@@ -76,6 +76,16 @@ function (_) {
'derivative': []
},
getMetricAggTypes: function(esVersion) {
return _.filter(this.metricAggTypes, function(f) {
if (f.minVersion) {
return f.minVersion <= esVersion;
} else {
return true;
}
});
},
getPipelineOptions: function(metric) {
if (!this.isPipelineAgg(metric.type)) {
return [];
......
......@@ -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