Alerting: Fix mathexp.NoData for ConditionsCmd (#56816) (#56820)

(cherry picked from commit 004bb7689d)

Co-authored-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-10-12 12:48:18 -04:00
committed by GitHub
co-authored by George Robinson
parent 1d2037a766
commit e238b9f9c1
2 changed files with 28 additions and 0 deletions
+5
View File
@@ -82,6 +82,11 @@ func (cmd *ConditionsCmd) Execute(_ context.Context, vars mathexp.Vars) (mathexp
var reducedNum mathexp.Number
var name string
switch v := val.(type) {
case mathexp.NoData:
// To keep this code as simple as possible we translate mathexp.NoData into a
// mathexp.Number with a nil value so number.GetFloat64Value() returns nil
reducedNum = mathexp.NewNumber("no data", nil)
reducedNum.SetValue(nil)
case mathexp.Series:
reducedNum = c.Reducer.Reduce(v)
name = v.GetName()
+23
View File
@@ -326,6 +326,29 @@ func TestConditionsCmdExecute(t *testing.T) {
},
{
name: "single query with no data",
vars: mathexp.Vars{
"A": mathexp.Results{
Values: []mathexp.Value{mathexp.NoData{}.New()},
},
},
conditionsCmd: &ConditionsCmd{
Conditions: []condition{
{
InputRefID: "A",
Reducer: reducer("avg"),
Operator: "and",
Evaluator: &thresholdEvaluator{"gt", 1},
},
},
},
resultNumber: func() mathexp.Number {
v := valBasedNumber(nil)
v.SetMeta([]EvalMatch{{Metric: "NoData"}})
return v
},
},
{
name: "single query with no values",
vars: mathexp.Vars{
"A": mathexp.Results{
Values: []mathexp.Value{},