From 7b9099ef9333fae3a2f40dd5b9609eec7ece6b6e Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 8 Sep 2016 14:33:10 +0200 Subject: [PATCH] fix(query): requires all that all series are empty to set NoDataFound --- pkg/services/alerting/conditions/query.go | 4 ++- .../alerting/conditions/query_test.go | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/services/alerting/conditions/query.go b/pkg/services/alerting/conditions/query.go index b8a8e4d0fda..dd39453ae42 100644 --- a/pkg/services/alerting/conditions/query.go +++ b/pkg/services/alerting/conditions/query.go @@ -38,6 +38,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) { return } + emptySerieCount := 0 for _, series := range seriesList { reducedValue := c.Reducer.Reduce(series) evalMatch := c.Evaluator.Eval(reducedValue) @@ -57,10 +58,11 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) { // handle no data scenario if reducedValue == nil { - context.NoDataFound = true + emptySerieCount++ } } + context.NoDataFound = emptySerieCount == len(seriesList) context.Firing = len(context.EvalMatches) > 0 } diff --git a/pkg/services/alerting/conditions/query_test.go b/pkg/services/alerting/conditions/query_test.go index f0772583e9a..f78ac17db2b 100644 --- a/pkg/services/alerting/conditions/query_test.go +++ b/pkg/services/alerting/conditions/query_test.go @@ -72,6 +72,32 @@ func TestQueryCondition(t *testing.T) { So(ctx.result.Error, ShouldBeNil) So(ctx.result.Firing, ShouldBeTrue) }) + + Convey("Empty series", func() { + Convey("Should set NoDataFound both series are empty", func() { + ctx.series = tsdb.TimeSeriesSlice{ + tsdb.NewTimeSeries("test1", [][2]*float64{}), + tsdb.NewTimeSeries("test2", [][2]*float64{}), + } + ctx.exec() + + So(ctx.result.Error, ShouldBeNil) + So(ctx.result.NoDataFound, ShouldBeTrue) + }) + + Convey("Should not set NoDataFound if one serie is empty", func() { + one := float64(120) + two := float64(0) + ctx.series = tsdb.TimeSeriesSlice{ + tsdb.NewTimeSeries("test1", [][2]*float64{}), + tsdb.NewTimeSeries("test2", [][2]*float64{{&one, &two}}), + } + ctx.exec() + + So(ctx.result.Error, ShouldBeNil) + So(ctx.result.NoDataFound, ShouldBeFalse) + }) + }) }) }) }