From 9511f89a22c5cbffd3220f5351ff957c979b92c5 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 8 Sep 2016 13:28:41 +0200 Subject: [PATCH] fix(alerting): fixes bug in query conditions --- pkg/services/alerting/conditions/query.go | 4 ++-- pkg/services/alerting/conditions/query_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/services/alerting/conditions/query.go b/pkg/services/alerting/conditions/query.go index ef51e09685c..b8a8e4d0fda 100644 --- a/pkg/services/alerting/conditions/query.go +++ b/pkg/services/alerting/conditions/query.go @@ -55,13 +55,13 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) { }) } - context.Firing = evalMatch - // handle no data scenario if reducedValue == nil { context.NoDataFound = true } } + + context.Firing = len(context.EvalMatches) > 0 } func (c *QueryCondition) executeQuery(context *alerting.EvalContext) (tsdb.TimeSeriesSlice, error) { diff --git a/pkg/services/alerting/conditions/query_test.go b/pkg/services/alerting/conditions/query_test.go index 88891c83096..f0772583e9a 100644 --- a/pkg/services/alerting/conditions/query_test.go +++ b/pkg/services/alerting/conditions/query_test.go @@ -59,6 +59,19 @@ func TestQueryCondition(t *testing.T) { So(ctx.result.Error, ShouldBeNil) So(ctx.result.Firing, ShouldBeFalse) }) + + Convey("Should fire if only first serie matches", func() { + one := float64(120) + two := float64(0) + ctx.series = tsdb.TimeSeriesSlice{ + tsdb.NewTimeSeries("test1", [][2]*float64{{&one, &two}}), + tsdb.NewTimeSeries("test2", [][2]*float64{{&two, &two}}), + } + ctx.exec() + + So(ctx.result.Error, ShouldBeNil) + So(ctx.result.Firing, ShouldBeTrue) + }) }) }) }