diff --git a/pkg/services/alerting/conditions/query.go b/pkg/services/alerting/conditions/query.go index dd39453ae42..f966985f132 100644 --- a/pkg/services/alerting/conditions/query.go +++ b/pkg/services/alerting/conditions/query.go @@ -43,6 +43,11 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) { reducedValue := c.Reducer.Reduce(series) evalMatch := c.Evaluator.Eval(reducedValue) + if reducedValue == nil { + emptySerieCount++ + continue + } + if context.IsTestRun { context.Logs = append(context.Logs, &alerting.ResultLogEntry{ Message: fmt.Sprintf("Condition[%d]: Eval: %v, Metric: %s, Value: %1.3f", c.Index, evalMatch, series.Name, *reducedValue), @@ -55,11 +60,6 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) { Value: *reducedValue, }) } - - // handle no data scenario - if reducedValue == nil { - emptySerieCount++ - } } context.NoDataFound = emptySerieCount == len(seriesList) diff --git a/pkg/services/alerting/conditions/query_test.go b/pkg/services/alerting/conditions/query_test.go index f78ac17db2b..983e75c4c1b 100644 --- a/pkg/services/alerting/conditions/query_test.go +++ b/pkg/services/alerting/conditions/query_test.go @@ -85,6 +85,18 @@ func TestQueryCondition(t *testing.T) { So(ctx.result.NoDataFound, ShouldBeTrue) }) + Convey("Should set NoDataFound both series contains null", func() { + one := float64(120) + ctx.series = tsdb.TimeSeriesSlice{ + tsdb.NewTimeSeries("test1", [][2]*float64{{nil, &one}}), + tsdb.NewTimeSeries("test2", [][2]*float64{{nil, &one}}), + } + 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) diff --git a/pkg/services/alerting/scheduler.go b/pkg/services/alerting/scheduler.go index 6701ad6eb6c..9d20796f3dc 100644 --- a/pkg/services/alerting/scheduler.go +++ b/pkg/services/alerting/scheduler.go @@ -35,8 +35,9 @@ func (s *SchedulerImpl) Update(rules []*Rule) { } job.Rule = rule - job.Offset = ((rule.Frequency * 1000) / int64(len(rules))) * int64(i) - job.Offset = int64(math.Floor(float64(job.Offset) / 1000)) + + offset := ((rule.Frequency * 1000) / int64(len(rules))) * int64(i) + job.Offset = int64(math.Floor(float64(offset) / 1000)) jobs[rule.Id] = job }