|
@@ -418,6 +418,38 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
|
|
So(pl.BucketPath, ShouldEqual, "3")
|
|
So(pl.BucketPath, ShouldEqual, "3")
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ Convey("With moving average 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": "moving_avg",
|
|
|
|
|
+ "field": "3",
|
|
|
|
|
+ "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")
|
|
|
|
|
+ So(firstLevel.Aggregation.Aggs, ShouldHaveLength, 1)
|
|
|
|
|
+
|
|
|
|
|
+ movingAvgAgg := firstLevel.Aggregation.Aggs[0]
|
|
|
|
|
+ So(movingAvgAgg.Key, ShouldEqual, "2")
|
|
|
|
|
+ So(movingAvgAgg.Aggregation.Type, ShouldEqual, "moving_avg")
|
|
|
|
|
+ pl := movingAvgAgg.Aggregation.Aggregation.(*es.PipelineAggregation)
|
|
|
|
|
+ So(pl.BucketPath, ShouldEqual, "_count")
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
Convey("With broken moving average", func() {
|
|
Convey("With broken moving average", func() {
|
|
|
c := newFakeClient(5)
|
|
c := newFakeClient(5)
|
|
|
_, err := executeTsdbQuery(c, `{
|
|
_, err := executeTsdbQuery(c, `{
|
|
@@ -483,6 +515,34 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
|
|
So(plAgg.BucketPath, ShouldEqual, "3")
|
|
So(plAgg.BucketPath, ShouldEqual, "3")
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ Convey("With derivative 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": "derivative",
|
|
|
|
|
+ "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")
|
|
|
|
|
+
|
|
|
|
|
+ derivativeAgg := firstLevel.Aggregation.Aggs[0]
|
|
|
|
|
+ So(derivativeAgg.Key, ShouldEqual, "2")
|
|
|
|
|
+ plAgg := derivativeAgg.Aggregation.Aggregation.(*es.PipelineAggregation)
|
|
|
|
|
+ So(plAgg.BucketPath, ShouldEqual, "_count")
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|