mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(elasticsearch): added pipleline aggregation derivative
This commit is contained in:
parent
2dee9c8d74
commit
b36f644628
@ -37,14 +37,13 @@ function (angular, _, queryDef) {
|
||||
$scope.settingsLinkText = '';
|
||||
$scope.aggDef = _.findWhere($scope.metricAggTypes, {value: $scope.agg.type});
|
||||
|
||||
if (!$scope.agg.field) {
|
||||
$scope.agg.field = 'select field';
|
||||
}
|
||||
|
||||
if (queryDef.isPipelineAgg($scope.agg)) {
|
||||
$scope.agg.pipelineAgg = $scope.agg.pipelineAgg || 'select metric';
|
||||
$scope.agg.field = $scope.agg.pipelineAgg;
|
||||
$scope.settingsLinkText = 'Options';
|
||||
delete $scope.agg.field;
|
||||
} else if (!$scope.agg.field) {
|
||||
$scope.agg.field = 'select field';
|
||||
}
|
||||
|
||||
switch($scope.agg.type) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
define([
|
||||
'./query_def'
|
||||
],
|
||||
function () {
|
||||
function (queryDef) {
|
||||
'use strict';
|
||||
|
||||
function ElasticQueryBuilder(options) {
|
||||
@ -170,9 +171,11 @@ function () {
|
||||
var aggField = {};
|
||||
var metricAgg = null;
|
||||
|
||||
if (metric.type === 'moving_avg') {
|
||||
if (queryDef.isPipelineAgg(metric)) {
|
||||
if (metric.pipelineAgg && /^\d*$/.test(metric.pipelineAgg)) {
|
||||
metricAgg = { buckets_path: metric.pipelineAgg };
|
||||
metricAgg = {
|
||||
buckets_path: metric.pipelineAgg,
|
||||
};
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ function (_) {
|
||||
{text: "Extended Stats", value: 'extended_stats', requiresField: true},
|
||||
{text: "Percentiles", value: 'percentiles', requiresField: true},
|
||||
{text: "Moving Average", value: 'moving_avg', requiresField: false },
|
||||
{text: "Derivative", value: 'derivative', requiresField: false },
|
||||
{text: "Unique Count", value: "cardinality", requiresField: true},
|
||||
{text: "Raw Document", value: "raw_document", requiresField: false}
|
||||
],
|
||||
@ -67,7 +68,7 @@ function (_) {
|
||||
{text: '1d', value: '1d'},
|
||||
],
|
||||
|
||||
pipelineAggs: ['moving_avg'],
|
||||
pipelineAggs: ['moving_avg', 'derivative'],
|
||||
|
||||
isPipelineAgg: function(metric) {
|
||||
if (metric.type) {
|
||||
|
@ -193,13 +193,11 @@ describe('ElasticQueryBuilder', function() {
|
||||
{
|
||||
id: '2',
|
||||
type: 'moving_avg',
|
||||
field: '3',
|
||||
pipelineAgg: '3'
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
type: 'moving_avg',
|
||||
field: '3',
|
||||
pipelineAgg: 'Metric to apply moving average'
|
||||
}
|
||||
],
|
||||
@ -215,4 +213,31 @@ describe('ElasticQueryBuilder', function() {
|
||||
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("3");
|
||||
expect(firstLevel.aggs["4"]).to.be(undefined);
|
||||
});
|
||||
|
||||
it('with derivative', function() {
|
||||
var query = builder.build({
|
||||
metrics: [
|
||||
{
|
||||
id: '3',
|
||||
type: 'sum',
|
||||
field: '@value'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'derivative',
|
||||
pipelineAgg: '3'
|
||||
}
|
||||
],
|
||||
bucketAggs: [
|
||||
{type: 'date_histogram', field: '@timestamp', id: '3'}
|
||||
],
|
||||
});
|
||||
|
||||
var firstLevel = query.aggs["3"];
|
||||
|
||||
expect(firstLevel.aggs["2"]).not.to.be(undefined);
|
||||
expect(firstLevel.aggs["2"].derivative).not.to.be(undefined);
|
||||
expect(firstLevel.aggs["2"].derivative.buckets_path).to.be("3");
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user