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
+4 -3
View File
@@ -153,11 +153,12 @@ func TestMetricsDBLoadBetweenFiltersWindow(t *testing.T) {
base := time.Unix(1_700_000_000, 0).UTC()
for i := 0; i < 5; i++ {
if err := db.Write(platform.LiveMetricSample{
Timestamp: base.Add(time.Duration(i) * time.Minute),
ts := base.Add(time.Duration(i) * time.Minute)
if err := db.writeAt(ts.Unix(), platform.LiveMetricSample{
Timestamp: ts,
CPULoadPct: float64(i),
}); err != nil {
t.Fatalf("Write(%d): %v", i, err)
t.Fatalf("writeAt(%d): %v", i, err)
}
}