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 -2
View File
@@ -969,8 +969,8 @@ func TestTaskChartSVGUsesTaskTimeWindow(t *testing.T) {
{Timestamp: base.Add(-1 * time.Minute), PowerW: 300},
}
for _, sample := range samples {
if err := db.Write(sample); err != nil {
t.Fatalf("Write: %v", err)
if err := db.writeAt(sample.Timestamp.Unix(), sample); err != nil {
t.Fatalf("writeAt: %v", err)
}
}
_ = db.Close()