mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix mathexp.NoData for ConditionsCmd (#56816)
This commit is contained in:
parent
61fd369b3f
commit
004bb7689d
@ -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()
|
||||
|
@ -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{},
|
||||
|
Loading…
Reference in New Issue
Block a user