Skip to content

Commit 48c34d3

Browse files
Alerting: Add tests that check current No Data behaviour with two conditions (grafana#58650)
1 parent fef1e1d commit 48c34d3

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

Diff for: pkg/expr/classic/classic_test.go

+125
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,131 @@ func TestConditionsCmd(t *testing.T) {
473473
})
474474
return newResults(v)
475475
},
476+
}, {
477+
name: "two queries with two conditions using and operator and first is No Data",
478+
vars: mathexp.Vars{
479+
"A": mathexp.Results{
480+
Values: []mathexp.Value{mathexp.NoData{}.New()},
481+
},
482+
"B": mathexp.Results{
483+
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
484+
},
485+
},
486+
cmd: &ConditionsCmd{
487+
Conditions: []condition{
488+
{
489+
InputRefID: "A",
490+
Reducer: reducer("min"),
491+
Operator: "and",
492+
Evaluator: &thresholdEvaluator{"gt", 1},
493+
},
494+
{
495+
InputRefID: "B",
496+
Reducer: reducer("min"),
497+
Operator: "and",
498+
Evaluator: &thresholdEvaluator{"gt", 1},
499+
},
500+
},
501+
},
502+
expected: func() mathexp.Results {
503+
v := newNumber(ptr.Float64(0))
504+
v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: ptr.Float64(5)}})
505+
return newResults(v)
506+
},
507+
}, {
508+
// TODO: NoData behavior is different if the last condition is no data
509+
name: "two queries with two conditions using and operator and last is No Data",
510+
vars: mathexp.Vars{
511+
"A": mathexp.Results{
512+
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
513+
},
514+
"B": mathexp.Results{
515+
Values: []mathexp.Value{mathexp.NoData{}.New()},
516+
},
517+
},
518+
cmd: &ConditionsCmd{
519+
Conditions: []condition{
520+
{
521+
InputRefID: "A",
522+
Reducer: reducer("min"),
523+
Operator: "and",
524+
Evaluator: &thresholdEvaluator{"gt", 1},
525+
},
526+
{
527+
InputRefID: "B",
528+
Reducer: reducer("min"),
529+
Operator: "and",
530+
Evaluator: &thresholdEvaluator{"gt", 1},
531+
},
532+
},
533+
},
534+
expected: func() mathexp.Results {
535+
v := newNumber(nil)
536+
v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}, {Metric: "NoData"}})
537+
return newResults(v)
538+
},
539+
}, {
540+
name: "two queries with two conditions using or operator and first is No Data",
541+
vars: mathexp.Vars{
542+
"A": mathexp.Results{
543+
Values: []mathexp.Value{mathexp.NoData{}.New()},
544+
},
545+
"B": mathexp.Results{
546+
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
547+
},
548+
},
549+
cmd: &ConditionsCmd{
550+
Conditions: []condition{
551+
{
552+
InputRefID: "A",
553+
Reducer: reducer("min"),
554+
Operator: "or",
555+
Evaluator: &thresholdEvaluator{"gt", 1},
556+
},
557+
{
558+
InputRefID: "B",
559+
Reducer: reducer("min"),
560+
Operator: "or",
561+
Evaluator: &thresholdEvaluator{"gt", 1},
562+
},
563+
},
564+
},
565+
expected: func() mathexp.Results {
566+
v := newNumber(nil)
567+
v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: ptr.Float64(5)}})
568+
return newResults(v)
569+
},
570+
}, {
571+
name: "two queries with two conditions using or operator and last is No Data",
572+
vars: mathexp.Vars{
573+
"A": mathexp.Results{
574+
Values: []mathexp.Value{newSeries(ptr.Float64(5))},
575+
},
576+
"B": mathexp.Results{
577+
Values: []mathexp.Value{mathexp.NoData{}.New()},
578+
},
579+
},
580+
cmd: &ConditionsCmd{
581+
Conditions: []condition{
582+
{
583+
InputRefID: "A",
584+
Reducer: reducer("min"),
585+
Operator: "or",
586+
Evaluator: &thresholdEvaluator{"gt", 1},
587+
},
588+
{
589+
InputRefID: "B",
590+
Reducer: reducer("min"),
591+
Operator: "or",
592+
Evaluator: &thresholdEvaluator{"gt", 1},
593+
},
594+
},
595+
},
596+
expected: func() mathexp.Results {
597+
v := newNumber(nil)
598+
v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}, {Metric: "NoData"}})
599+
return newResults(v)
600+
},
476601
}}
477602

478603
for _, tt := range tests {

0 commit comments

Comments
 (0)