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

This commit is contained in:
carl bergquist 2015-12-14 15:08:34 +01:00
parent 56c3dd3652
commit f5eb54e595
6 changed files with 37 additions and 4 deletions

View File

@ -30,6 +30,7 @@ function (angular) {
index: "=",
onChange: "&",
getFields: "&",
esVersion: '='
}
};
});

View File

@ -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 = [];

View File

@ -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>

View File

@ -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;

View File

@ -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 [];

View File

@ -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);
});
});
});
});