diff --git a/pkg/tsdb/elasticsearch/models.go b/pkg/tsdb/elasticsearch/models.go index 8f34eecf620..c2e2129de8b 100644 --- a/pkg/tsdb/elasticsearch/models.go +++ b/pkg/tsdb/elasticsearch/models.go @@ -48,6 +48,7 @@ var metricAggType = map[string]string{ "moving_fn": "Moving Function", "cumulative_sum": "Cumulative Sum", "derivative": "Derivative", + "serial_diff": "Serial Difference", "bucket_script": "Bucket Script", "raw_document": "Raw Document", } @@ -68,6 +69,7 @@ var pipelineAggType = map[string]string{ "moving_fn": "moving_fn", "cumulative_sum": "cumulative_sum", "derivative": "derivative", + "serial_diff": "serial_diff", "bucket_script": "bucket_script", } diff --git a/pkg/tsdb/elasticsearch/time_series_query_test.go b/pkg/tsdb/elasticsearch/time_series_query_test.go index 48c7a86fb06..d58e83b7e7c 100644 --- a/pkg/tsdb/elasticsearch/time_series_query_test.go +++ b/pkg/tsdb/elasticsearch/time_series_query_test.go @@ -650,6 +650,64 @@ func TestExecuteTimeSeriesQuery(t *testing.T) { So(plAgg.BucketPath, ShouldEqual, "_count") }) + Convey("With serial_diff", func() { + c := newFakeClient(5) + _, err := executeTsdbQuery(c, `{ + "timeField": "@timestamp", + "bucketAggs": [ + { "type": "date_histogram", "field": "@timestamp", "id": "4" } + ], + "metrics": [ + { "id": "3", "type": "sum", "field": "@value" }, + { + "id": "2", + "type": "serial_diff", + "pipelineAgg": "3" + } + ] + }`, from, to, 15*time.Second) + So(err, ShouldBeNil) + sr := c.multisearchRequests[0].Requests[0] + + firstLevel := sr.Aggs[0] + So(firstLevel.Key, ShouldEqual, "4") + So(firstLevel.Aggregation.Type, ShouldEqual, "date_histogram") + + serialDiffAgg := firstLevel.Aggregation.Aggs[1] + So(serialDiffAgg.Key, ShouldEqual, "2") + plAgg := serialDiffAgg.Aggregation.Aggregation.(*es.PipelineAggregation) + So(plAgg.BucketPath, ShouldEqual, "3") + }) + + Convey("With serial_diff doc count", func() { + c := newFakeClient(5) + _, err := executeTsdbQuery(c, `{ + "timeField": "@timestamp", + "bucketAggs": [ + { "type": "date_histogram", "field": "@timestamp", "id": "4" } + ], + "metrics": [ + { "id": "3", "type": "count", "field": "select field" }, + { + "id": "2", + "type": "serial_diff", + "pipelineAgg": "3" + } + ] + }`, from, to, 15*time.Second) + So(err, ShouldBeNil) + sr := c.multisearchRequests[0].Requests[0] + + firstLevel := sr.Aggs[0] + So(firstLevel.Key, ShouldEqual, "4") + So(firstLevel.Aggregation.Type, ShouldEqual, "date_histogram") + + serialDiffAgg := firstLevel.Aggregation.Aggs[0] + So(serialDiffAgg.Key, ShouldEqual, "2") + plAgg := serialDiffAgg.Aggregation.Aggregation.(*es.PipelineAggregation) + So(plAgg.BucketPath, ShouldEqual, "_count") + }) + Convey("With bucket_script", func() { c := newFakeClient(5) _, err := executeTsdbQuery(c, `{ diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx index b8f5619ddec..bebbfddf581 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx @@ -35,6 +35,15 @@ export const SettingsEditor: FunctionComponent = ({ metric, previousMetri