Skip to content

Commit

Permalink
execution: fix min/max aggregators (#335)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <[email protected]>
  • Loading branch information
MichaHoffmann authored Nov 29, 2023
1 parent 6675f2d commit f3dcefe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
30 changes: 30 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2817,6 +2817,36 @@ func TestInstantQuery(t *testing.T) {
queryTime time.Time
sortByLabels bool // if true, the series in the result between the old and new engine should be sorted before compared
}{
{
name: "fuzz - min with NaN",
load: `load 30s
http_requests_total{pod="nginx-1", route="/"} 124.00+1.00x40
http_requests_total{pod="nginx-2", route="/"} 0+0.29x40`,
query: "min by (route, pod) (sqrt(-http_requests_total))",
},
{
name: "fuzz - min with Inf",
load: `load 30s
http_requests_total{pod="nginx-1", route="/"} 483.00+6035.00x40
http_requests_total{pod="nginx-2", route="/"} 2+47.14x40`,
query: `
min without () (
(
{__name__="http_requests_total"} @ start() offset -2m40s
^
{__name__="http_requests_total"} @ start() offset -2m49s
)
)`,
},
/*
This is a known issue, we lose the signed 0 in the sum because we add to a
default element. Prometheus assigns the first element to the sum and preserves
the sign.
{
name: "fuzz - signed zero",
query: `1/sum(-(absent(X)-1))`,
},
*/
{
name: "sum_over_time with subquery",
load: `load 10s
Expand Down
10 changes: 2 additions & 8 deletions execution/aggregate/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ type genericAcc struct {
zeroVal float64
value float64
hasValue bool
skipNaNs bool

aggregate func(float64, float64) float64
vectorAggregate func([]float64, []*histogram.FloatHistogram) float64
Expand Down Expand Up @@ -115,17 +114,15 @@ func groupVecAggregate(_ []float64, _ []*histogram.FloatHistogram) float64 {

func newMaxAcc() *genericAcc {
return &genericAcc{
skipNaNs: true,
zeroVal: math.MinInt64,
zeroVal: math.Inf(-1),
aggregate: maxAggregate,
vectorAggregate: maxVecAggregate,
}
}

func newMinAcc() *genericAcc {
return &genericAcc{
skipNaNs: true,
zeroVal: math.MaxInt64,
zeroVal: math.Inf(+1),
aggregate: minAggregate,
vectorAggregate: minVecAggregate,
}
Expand All @@ -140,9 +137,6 @@ func newGroupAcc() *genericAcc {
}

func (g *genericAcc) Add(v float64, _ *histogram.FloatHistogram) {
if g.skipNaNs && math.IsNaN(v) {
return
}
if !g.hasValue {
g.value = g.aggregate(g.zeroVal, v)
g.hasValue = true
Expand Down

0 comments on commit f3dcefe

Please sign in to comment.