diff --git a/pkg/expr/classic/classic.go b/pkg/expr/classic/classic.go index 830d1ba1f1c..3ac96cbd8c4 100644 --- a/pkg/expr/classic/classic.go +++ b/pkg/expr/classic/classic.go @@ -129,7 +129,7 @@ func (ccc *ConditionsCmd) Execute(ctx context.Context, vars mathexp.Vars) (mathe } thisCondFiring := firingCount > 0 - thisCondNoData := nilReducedCount > 0 + thisCondNoData := len(querySeriesSet.Values) == nilReducedCount if i == 0 { firing = thisCondFiring @@ -144,7 +144,7 @@ func (ccc *ConditionsCmd) Execute(ctx context.Context, vars mathexp.Vars) (mathe noDataFound = noDataFound && thisCondNoData } - if len(querySeriesSet.Values) == nilReducedCount { + if thisCondNoData { matches = append(matches, EvalMatch{ Metric: "NoData", }) diff --git a/pkg/expr/classic/classic_test.go b/pkg/expr/classic/classic_test.go index 5e96826f1d8..623ae19f3bc 100644 --- a/pkg/expr/classic/classic_test.go +++ b/pkg/expr/classic/classic_test.go @@ -169,6 +169,31 @@ func TestConditionsCmdExecute(t *testing.T) { return v }, }, + { + name: "single query and single condition - empty series and not empty series", + vars: mathexp.Vars{ + "A": mathexp.Results{ + Values: []mathexp.Value{ + valBasedSeries(), + valBasedSeries(ptr.Float64(3)), + }, + }, + }, + conditionsCmd: &ConditionsCmd{ + Conditions: []condition{ + { + QueryRefID: "A", + Reducer: classicReducer("avg"), + Operator: "and", + Evaluator: &thresholdEvaluator{Type: "gt", Threshold: .5}, + }, + }}, + resultNumber: func() mathexp.Number { + v := valBasedNumber(ptr.Float64(1)) + v.SetMeta([]EvalMatch{{Value: ptr.Float64(3)}}) + return v + }, + }, { name: "single query and two conditions", vars: mathexp.Vars{ diff --git a/pkg/expr/classic/reduce_test.go b/pkg/expr/classic/reduce_test.go index 50871dd61cd..ea2bc7cbbb3 100644 --- a/pkg/expr/classic/reduce_test.go +++ b/pkg/expr/classic/reduce_test.go @@ -102,6 +102,12 @@ func TestReducer(t *testing.T) { inputSeries: valBasedSeries(nil, nil, ptr.Float64(3), ptr.Float64(4)), expectedNumber: valBasedNumber(ptr.Float64(2)), }, + { + name: "count_non_null with mixed null/real values", + reducer: classicReducer("count_non_null"), + inputSeries: valBasedSeries(nil, nil, ptr.Float64(3), ptr.Float64(4)), + expectedNumber: valBasedNumber(ptr.Float64(2)), + }, { name: "count_non_null with no values", reducer: classicReducer("count_non_null"),