Skip to content

Commit

Permalink
add parameter absent to every call to SummarizeValues
Browse files Browse the repository at this point in the history
  • Loading branch information
spacefreak86 committed Nov 30, 2024
1 parent 62ec9ab commit 00788b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/expr/functions/legendValue/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/expr/functions/sortBy/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/expr/functions/summarize/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -132,20 +134,21 @@ 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
}
ridx++
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
}
Expand Down

0 comments on commit 00788b3

Please sign in to comment.