Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 1897d08

Browse files
committed
Handle oversampling cases without panic
Simple check so we don't consolidate (batch/aggFunc) no points
1 parent 03fdc38 commit 1897d08

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

expr/func_summarize.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package expr
22

33
import (
44
"fmt"
5+
"math"
56

67
"github.com/grafana/metrictank/api/models"
78
"github.com/grafana/metrictank/batch"
@@ -93,7 +94,12 @@ func summarizeValues(serie models.Series, aggFunc batch.AggFunc, interval, start
9394
}
9495
}
9596

96-
out = append(out, schema.Point{Val: aggFunc(serie.Datapoints[s:i]), Ts: ts})
97+
aggPoint := schema.Point{Val: math.NaN(), Ts: ts}
98+
if s != i {
99+
aggPoint.Val = aggFunc(serie.Datapoints[s:i])
100+
}
101+
102+
out = append(out, aggPoint)
97103
}
98104

99105
return out

expr/func_summarize_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,8 @@ func TestSummarizeOversampled(t *testing.T) {
191191
// Note that graphite does not accept 10 as default seconds, but dur lib defaults to seconds without units!
192192
testSummarize("Oversampled Identity", input, outputSum[0], "5", "sum", false, t)
193193
testSummarize("Oversampled Identity", input, outputSum[1], "5", "sum", true, t)
194-
//testSummarize("Oversampled Identity", input, outputMax[0], "5", "max", false, t)
195-
//testSummarize("Oversampled Identity", input, outputMax[1], "5", "max", true, t)
196-
_ = outputMax // Max fails because it can't handle 0 terms, sum does not handle the 0 term check
194+
testSummarize("Oversampled Identity", input, outputMax[0], "5", "max", false, t)
195+
testSummarize("Oversampled Identity", input, outputMax[1], "5", "max", true, t)
197196
}
198197

199198
func TestSummarizeNyquistSingleIdentity(t *testing.T) {

0 commit comments

Comments
 (0)