Pin fine/coarse mergeDump to the 1min/5min boundary, fixes sparkline

This commit is contained in:
2026-03-25 18:14:20 +01:00
parent d0fb34160f
commit 6c3a28c9ce

View File

@@ -58,8 +58,8 @@ func Backfill(ctx context.Context, collectorAddrs []string, cache *Cache) {
for range collectorAddrs {
r := <-ch
mergeDump(r.fine, fineByTS)
mergeDump(r.coarse, coarseByTS)
mergeDump(r.fine, fineByTS, time.Minute)
mergeDump(r.coarse, coarseByTS, 5*time.Minute)
}
mergeStart := time.Now()
@@ -114,9 +114,10 @@ func dumpCollector(ctx context.Context, addr string) (fine, coarse []st.Snapshot
// mergeDump adds all snapshots from one collector's dump into the per-timestamp
// accumulator map. Multiple collectors' entries for the same timestamp are summed.
func mergeDump(snaps []st.Snapshot, byTS map[int64]map[string]int64) {
// granularity should match the ring bucket size (time.Minute for fine, 5*time.Minute for coarse).
func mergeDump(snaps []st.Snapshot, byTS map[int64]map[string]int64, granularity time.Duration) {
for _, snap := range snaps {
ts := snap.Timestamp.Unix()
ts := snap.Timestamp.Truncate(granularity).Unix()
m := byTS[ts]
if m == nil {
m = make(map[string]int64, len(snap.Entries))