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

Commit 3ac0933

Browse files
committed
newRequestContext: simpler computation of rc.From
1 parent 29c96ec commit 3ac0933

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

api/dataprocessor.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,7 @@ func newRequestContext(ctx context.Context, req *models.Req, consolidator consol
756756
// but because we eventually want to consolidate into a point with ts=60, we also need the points that will be fix-adjusted to 40 and 50.
757757
// so From needs to be lowered by 20 to become 35 (or 31 if adjusted).
758758

759-
remainder := alignBackward(rc.From, req.ArchInterval) % req.OutInterval // (60-10) % 30 = 20
760-
761-
if rc.From > remainder {
762-
rc.From -= remainder
763-
} else {
764-
// in case someone's requesting stupidly low timestamps like from=15, we don't want to get negative timestamps and run into trouble.
765-
// so in this - very rare - case, we basically adjust into the future instead of to the past.
766-
rc.From = rc.From + req.OutInterval - remainder
767-
}
759+
rc.From = util.Subuint32(alignForward(rc.From, req.OutInterval), req.AggNum*req.ArchInterval) + 1
768760

769761
// 2) `to` adjustment.
770762
// if the series has some excess at the end, it may aggregate into a bucket with a timestamp out of the desired range.

util/overflow.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package util
2+
3+
import "math"
4+
5+
func Adduint32(a, b uint32) uint32 {
6+
if a > math.MaxInt32-b {
7+
return math.MaxInt32
8+
}
9+
return a + b
10+
}
11+
12+
func Subuint32(a, b uint32) uint32 {
13+
if a < b {
14+
return 0
15+
}
16+
return a - b
17+
}

0 commit comments

Comments
 (0)