Browse Source

fix(alerting): dont log null series

closes #6025
bergquist 9 years ago
parent
commit
77783c02cd

+ 5 - 5
pkg/services/alerting/conditions/query.go

@@ -43,6 +43,11 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) {
 		reducedValue := c.Reducer.Reduce(series)
 		reducedValue := c.Reducer.Reduce(series)
 		evalMatch := c.Evaluator.Eval(reducedValue)
 		evalMatch := c.Evaluator.Eval(reducedValue)
 
 
+		if reducedValue == nil {
+			emptySerieCount++
+			continue
+		}
+
 		if context.IsTestRun {
 		if context.IsTestRun {
 			context.Logs = append(context.Logs, &alerting.ResultLogEntry{
 			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),
 				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,
 				Value:  *reducedValue,
 			})
 			})
 		}
 		}
-
-		// handle no data scenario
-		if reducedValue == nil {
-			emptySerieCount++
-		}
 	}
 	}
 
 
 	context.NoDataFound = emptySerieCount == len(seriesList)
 	context.NoDataFound = emptySerieCount == len(seriesList)

+ 12 - 0
pkg/services/alerting/conditions/query_test.go

@@ -85,6 +85,18 @@ func TestQueryCondition(t *testing.T) {
 					So(ctx.result.NoDataFound, ShouldBeTrue)
 					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() {
 				Convey("Should not set NoDataFound if one serie is empty", func() {
 					one := float64(120)
 					one := float64(120)
 					two := float64(0)
 					two := float64(0)

+ 3 - 2
pkg/services/alerting/scheduler.go

@@ -35,8 +35,9 @@ func (s *SchedulerImpl) Update(rules []*Rule) {
 		}
 		}
 
 
 		job.Rule = 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
 		jobs[rule.Id] = job
 	}
 	}