From c29c1691fdf86d68bfc3954f67f51c51385ecc44 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 24 Feb 2022 18:48:56 -0600 Subject: [PATCH] SSE: Fix NoData when some series were no data but others not (#45867) (#45875) Co-authored-by: Santiago (cherry picked from commit a578cf0f7cd25fe80e26a1b23f381c2fa3fb1b41) Co-authored-by: Kyle Brandt --- pkg/expr/classic/classic.go | 4 ++-- pkg/expr/classic/classic_test.go | 25 +++++++++++++++++++++++++ pkg/expr/classic/reduce_test.go | 6 ++++++ 3 files changed, 33 insertions(+), 2 deletions(-) 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"),