Alerting: Add tests that check current No Data behaviour with two conditions (#58650)

This commit is contained in:
George Robinson 2022-11-18 09:04:43 +00:00 committed by GitHub
parent fef1e1d5bc
commit 48c34d310c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -473,6 +473,131 @@ func TestConditionsCmd(t *testing.T) {
})
return newResults(v)
},
}, {
name: "two queries with two conditions using and operator and first is No Data",
vars: mathexp.Vars{
"A": mathexp.Results{
Values: []mathexp.Value{mathexp.NoData{}.New()},
},
"B": mathexp.Results{
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
},
},
cmd: &ConditionsCmd{
Conditions: []condition{
{
InputRefID: "A",
Reducer: reducer("min"),
Operator: "and",
Evaluator: &thresholdEvaluator{"gt", 1},
},
{
InputRefID: "B",
Reducer: reducer("min"),
Operator: "and",
Evaluator: &thresholdEvaluator{"gt", 1},
},
},
},
expected: func() mathexp.Results {
v := newNumber(ptr.Float64(0))
v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: ptr.Float64(5)}})
return newResults(v)
},
}, {
// TODO: NoData behavior is different if the last condition is no data
name: "two queries with two conditions using and operator and last is No Data",
vars: mathexp.Vars{
"A": mathexp.Results{
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
},
"B": mathexp.Results{
Values: []mathexp.Value{mathexp.NoData{}.New()},
},
},
cmd: &ConditionsCmd{
Conditions: []condition{
{
InputRefID: "A",
Reducer: reducer("min"),
Operator: "and",
Evaluator: &thresholdEvaluator{"gt", 1},
},
{
InputRefID: "B",
Reducer: reducer("min"),
Operator: "and",
Evaluator: &thresholdEvaluator{"gt", 1},
},
},
},
expected: func() mathexp.Results {
v := newNumber(nil)
v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}, {Metric: "NoData"}})
return newResults(v)
},
}, {
name: "two queries with two conditions using or operator and first is No Data",
vars: mathexp.Vars{
"A": mathexp.Results{
Values: []mathexp.Value{mathexp.NoData{}.New()},
},
"B": mathexp.Results{
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
},
},
cmd: &ConditionsCmd{
Conditions: []condition{
{
InputRefID: "A",
Reducer: reducer("min"),
Operator: "or",
Evaluator: &thresholdEvaluator{"gt", 1},
},
{
InputRefID: "B",
Reducer: reducer("min"),
Operator: "or",
Evaluator: &thresholdEvaluator{"gt", 1},
},
},
},
expected: func() mathexp.Results {
v := newNumber(nil)
v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: ptr.Float64(5)}})
return newResults(v)
},
}, {
name: "two queries with two conditions using or operator and last is No Data",
vars: mathexp.Vars{
"A": mathexp.Results{
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
},
"B": mathexp.Results{
Values: []mathexp.Value{mathexp.NoData{}.New()},
},
},
cmd: &ConditionsCmd{
Conditions: []condition{
{
InputRefID: "A",
Reducer: reducer("min"),
Operator: "or",
Evaluator: &thresholdEvaluator{"gt", 1},
},
{
InputRefID: "B",
Reducer: reducer("min"),
Operator: "or",
Evaluator: &thresholdEvaluator{"gt", 1},
},
},
},
expected: func() mathexp.Results {
v := newNumber(nil)
v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}, {Metric: "NoData"}})
return newResults(v)
},
}}
for _, tt := range tests {