feat(web): add month and year ranges, data-aware range buttons and region history
Ranges grow to 30d, 90d, 180d and 1y, read from the aggregates, and the SLA table to 180d and 1y. Ranges and SLA windows less than half covered by data are shown disabled. Monitor pages chart each region separately with its share of successful checks. Bars align to TimescaleDB's bucket origin so multi-day buckets match. Closes #61 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
24147ec31d
commit
7a085e22d0
9 files changed
+1368
-857
No files matched your search
@@ -47,3 +47,30 @@ func TestRanges(t *testing.T) {
|
||||
t.Error("unknown range does not fall back to the default")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlignBucketMatchesTimescale(t *testing.T) {
|
||||
// Reference values from TimescaleDB:
|
||||
// time_bucket('2 days', '2026-01-02 12:00Z') = 2026-01-02 00:00Z,
|
||||
// time_bucket('7 days', '2026-01-02 12:00Z') = 2025-12-29 00:00Z.
|
||||
ts := time.Date(2026, 1, 2, 12, 0, 0, 0, time.UTC)
|
||||
if got, want := AlignBucket(ts, 48*time.Hour), time.Date(2026, 1, 2, 0, 0, 0, 0, time.UTC); !got.Equal(want) {
|
||||
t.Errorf("AlignBucket(2 days) = %v, want %v", got, want)
|
||||
}
|
||||
if got, want := AlignBucket(ts, 7*24*time.Hour), time.Date(2025, 12, 29, 0, 0, 0, 0, time.UTC); !got.Equal(want) {
|
||||
t.Errorf("AlignBucket(7 days) = %v, want %v", got, want)
|
||||
}
|
||||
h := time.Date(2026, 1, 2, 12, 34, 0, 0, time.UTC)
|
||||
if got := AlignBucket(h, time.Hour); !got.Equal(h.Truncate(time.Hour)) {
|
||||
t.Errorf("AlignBucket(1h) = %v, want %v", got, h.Truncate(time.Hour))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasEnoughData(t *testing.T) {
|
||||
now := time.Now()
|
||||
if HasEnoughData(time.Time{}, now, time.Hour) {
|
||||
t.Error("no data counts as enough")
|
||||
}
|
||||
if !HasEnoughData(now.Add(-31*time.Minute), now, time.Hour) || HasEnoughData(now.Add(-29*time.Minute), now, time.Hour) {
|
||||
t.Error("half-window threshold wrong for 1h")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user