mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(query): requires all that all series are empty to set NoDataFound
This commit is contained in:
parent
9511f89a22
commit
7b9099ef93
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user