mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Add tests that check current No Data behaviour with two conditions (#58650)
This commit is contained in:
parent
fef1e1d5bc
commit
48c34d310c
@ -473,6 +473,131 @@ func TestConditionsCmd(t *testing.T) {
|
|||||||
})
|
})
|
||||||
return newResults(v)
|
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 {
|
for _, tt := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user