fix(query): requires all that all series are empty to set NoDataFound

This commit is contained in:
bergquist 2016-09-08 14:33:10 +02:00
parent 9511f89a22
commit 7b9099ef93
2 changed files with 29 additions and 1 deletions

View File

@ -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
}

View File

@ -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)
})
})
})
})
}