fix(webui): make metrics history immune to system-clock changes

Every sample was stamped with time.Now(), so a timezone switch or NTP
step punched a multi-hour gap into the series: old points collapsed to
the left edge, new points bunched at the right, joined by one diagonal.

Stamp rows from a monotonic seqClock instead — seeded once from the wall
clock (or the newest persisted row) and thereafter advanced only by the
monotonic elapsed time between writes. Rebase Downsample/Prune on the
newest sample rather than time.Now() so a clock step just before the
hourly compaction can't drop fresh data.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GofKhuF9xQHaz3UFfncR6D
This commit is contained in:
Mikhail Chusavitin
2026-09-04 10:04:13 +03:00
co-authored by Claude Sonnet 5
parent 4953bb33b2
commit f31971f440
4 changed files with 109 additions and 23 deletions
+2 -3
View File
@@ -393,9 +393,8 @@ func (h *handler) startMetricsCollector() {
h.setLatestMetric(sample)
case <-pruneTicker.C:
if h.metricsDB != nil {
now := time.Now().UTC()
_ = h.metricsDB.Downsample(now.Add(-metricsDownsampleAge), now.Add(-metricsRetainWindow))
_ = h.metricsDB.Prune(now.Add(-metricsRetainWindow))
_ = h.metricsDB.Downsample(metricsDownsampleAge, metricsRetainWindow)
_ = h.metricsDB.Prune(metricsRetainWindow)
}
}
}