feat: proper push monitor lifecycle — PENDING, LATE, DOWN states
Push monitors no longer lie about status: - PENDING stays until first heartbeat (no auto-promote to UP) - LATE state (amber) when overdue but within grace period - DOWN only after grace period expires - Grace period = interval/2, minimum 60s RecordHeartbeat now handles all transitions: - PENDING → UP (first heartbeat, logged) - LATE → UP (late arrival, logged) - DOWN → UP (recovery, alert + state change persisted) TUI updates: - LATE rendered in amber/warning color - Status bar shows LATE count separately - Tab badge shows ⚠ for late monitors - Sort order: DOWN > LATE > UP > PENDING > PAUSED - Detail panel shows error for LATE monitors Inspired by Healthchecks.io state machine (new/up/grace/down).
This commit is contained in:
@@ -537,7 +537,7 @@ func TestCheckPush_DeadlineMissed(t *testing.T) {
|
||||
site := models.Site{
|
||||
ID: 1, Name: "push", Type: "push", Status: "UP",
|
||||
Interval: 10, MaxRetries: 0,
|
||||
LastCheck: time.Now().Add(-20 * time.Second),
|
||||
LastCheck: time.Now().Add(-120 * time.Second),
|
||||
}
|
||||
injectSite(e, site)
|
||||
|
||||
@@ -549,6 +549,24 @@ func TestCheckPush_DeadlineMissed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckPush_OverdueBecomesLate(t *testing.T) {
|
||||
ms := newMockStore()
|
||||
e := newTestEngine(ms)
|
||||
site := models.Site{
|
||||
ID: 1, Name: "push", Type: "push", Status: "UP",
|
||||
Interval: 300,
|
||||
LastCheck: time.Now().Add(-310 * time.Second),
|
||||
}
|
||||
injectSite(e, site)
|
||||
|
||||
e.checkPush(site)
|
||||
|
||||
s, _ := getSite(e, 1)
|
||||
if s.Status != "LATE" {
|
||||
t.Errorf("expected LATE when overdue but within grace, got %s", s.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckPush_WithinDeadline(t *testing.T) {
|
||||
ms := newMockStore()
|
||||
e := newTestEngine(ms)
|
||||
@@ -566,20 +584,20 @@ func TestCheckPush_WithinDeadline(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckPush_PendingToUp(t *testing.T) {
|
||||
func TestCheckPush_PendingStaysPending(t *testing.T) {
|
||||
ms := newMockStore()
|
||||
e := newTestEngine(ms)
|
||||
site := models.Site{
|
||||
ID: 1, Name: "push", Type: "push", Status: "PENDING",
|
||||
Interval: 60, LastCheck: time.Now(),
|
||||
Interval: 60,
|
||||
}
|
||||
injectSite(e, site)
|
||||
|
||||
e.checkPush(site)
|
||||
|
||||
s, _ := getSite(e, 1)
|
||||
if s.Status != "UP" {
|
||||
t.Errorf("expected UP, got %s", s.Status)
|
||||
if s.Status != "PENDING" {
|
||||
t.Errorf("expected PENDING to stay until first heartbeat, got %s", s.Status)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user