From 00788b3ed277b38ecd2ec0e679c2b90aca1b843a Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Sat, 30 Nov 2024 02:01:31 +0100 Subject: [PATCH] add parameter absent to every call to SummarizeValues --- pkg/expr/functions/legendValue/function.go | 2 +- pkg/expr/functions/sortBy/function.go | 6 +++--- pkg/expr/functions/summarize/function.go | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/expr/functions/legendValue/function.go b/pkg/expr/functions/legendValue/function.go index 87678614..2b72cd17 100644 --- a/pkg/expr/functions/legendValue/function.go +++ b/pkg/expr/functions/legendValue/function.go @@ -57,7 +57,7 @@ func (f *legendValue) Do(ctx context.Context, e parser.Expr, from, until int32, for _, a := range arg { var values []string for _, method := range methods { - summaryVal, _, err := helper.SummarizeValues(method, a.Values) + summaryVal, _, err := helper.SummarizeValues(method, a.Values, a.IsAbsent) if err != nil { return []*types.MetricData{}, err } diff --git a/pkg/expr/functions/sortBy/function.go b/pkg/expr/functions/sortBy/function.go index 75314537..6c1fe70c 100644 --- a/pkg/expr/functions/sortBy/function.go +++ b/pkg/expr/functions/sortBy/function.go @@ -42,11 +42,11 @@ func (f *sortBy) Do(ctx context.Context, e parser.Expr, from, until int32, value for i, a := range arg { switch e.Target() { case "sortByTotal": - vals[i], _, _ = helper.SummarizeValues("sum", a.Values) + vals[i], _, _ = helper.SummarizeValues("sum", a.Values, a.IsAbsent) case "sortByMaxima": - vals[i], _, _ = helper.SummarizeValues("max", a.Values) + vals[i], _, _ = helper.SummarizeValues("max", a.Values, a.IsAbsent) case "sortByMinima": - min, _, _ := helper.SummarizeValues("min", a.Values) + min, _, _ := helper.SummarizeValues("min", a.Values, a.IsAbsent) vals[i] = 1 / min } } diff --git a/pkg/expr/functions/summarize/function.go b/pkg/expr/functions/summarize/function.go index 46b0004d..f96c2c38 100644 --- a/pkg/expr/functions/summarize/function.go +++ b/pkg/expr/functions/summarize/function.go @@ -117,12 +117,14 @@ func (f *summarize) Do(ctx context.Context, e parser.Expr, from, until int32, va t := arg.StartTime // unadjusted bucketEnd := start + bucketSize values := make([]float64, 0, bucketSize/arg.StepTime) + absent := make([]bool, 0, bucketSize/arg.StepTime) ridx := 0 bucketItems := 0 for i, v := range arg.Values { bucketItems++ if !arg.IsAbsent[i] { values = append(values, v) + absent = append(absent, false) } t += arg.StepTime @@ -132,7 +134,7 @@ func (f *summarize) Do(ctx context.Context, e parser.Expr, from, until int32, va } if t >= bucketEnd { - r.Values[ridx], r.IsAbsent[ridx], err = helper.SummarizeValues(summarizeFunction, values) + r.Values[ridx], r.IsAbsent[ridx], err = helper.SummarizeValues(summarizeFunction, values, absent) if err != nil { return []*types.MetricData{}, err } @@ -140,12 +142,13 @@ func (f *summarize) Do(ctx context.Context, e parser.Expr, from, until int32, va bucketEnd += bucketSize bucketItems = 0 values = values[:0] + absent = absent[:0] } } // last partial bucket if bucketItems > 0 { - r.Values[ridx], r.IsAbsent[ridx], err = helper.SummarizeValues(summarizeFunction, values) + r.Values[ridx], r.IsAbsent[ridx], err = helper.SummarizeValues(summarizeFunction, values, absent) if err != nil { return []*types.MetricData{}, err }