From e6c3deb54d49d1330c15576770994500e352c5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Sun, 22 Nov 2026 08:55:39 +0100 Subject: [PATCH] fix(api): report a page as degraded unless every component is down Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- internal/api/statuspages.go | 12 ++++++++++-- internal/api/statuspages_test.go | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/api/statuspages.go b/internal/api/statuspages.go index d3714fb..3d86bd8 100644 --- a/internal/api/statuspages.go +++ b/internal/api/statuspages.go @@ -98,7 +98,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen } names := map[uuid.UUID]string{} worst := agentapi.PageOperational - allUnknown := true + allUnknown, allDown := true, len(listed) > 0 for _, m := range listed { name := m.Label if name == "" { @@ -119,6 +119,9 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen if comp.Status != agentapi.PageUnknown { allUnknown = false } + if comp.Status != agentapi.PageOutage { + allDown = false + } worst = worse(worst, comp.Status) if n := len(snap.Sections); n == 0 || snap.Sections[n-1].Name != m.Section { snap.Sections = append(snap.Sections, agentapi.Section{Name: m.Section}) @@ -126,9 +129,14 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen last := &snap.Sections[len(snap.Sections)-1] last.Components = append(last.Components, comp) } + // A single failed component is a partial problem; only a complete + // failure is reported as an outage of the whole page. snap.Status = worst - if allUnknown { + switch { + case allUnknown: snap.Status = agentapi.PageUnknown + case worst == agentapi.PageOutage && !allDown: + snap.Status = agentapi.PageDegraded } for _, i := range incidents { snap.Incidents = append(snap.Incidents, agentapi.PageIncident{Component: names[i.MonitorID], StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt}) diff --git a/internal/api/statuspages_test.go b/internal/api/statuspages_test.go index b3a64b1..646a012 100644 --- a/internal/api/statuspages_test.go +++ b/internal/api/statuspages_test.go @@ -91,8 +91,9 @@ func TestStatusPages(t *testing.T) { if err != nil { t.Fatalf("Page() failed: %v", err) } - if snap.Status != agentapi.PageOutage || len(snap.Sections) != 2 || snap.Sections[1].Components[0].Name != "Public API" { - t.Errorf("snapshot = %+v, want outage with Frontend and Backend sections", snap) + if snap.Status != agentapi.PageDegraded || len(snap.Sections) != 2 || snap.Sections[1].Components[0].Status != agentapi.PageOutage || + snap.Sections[1].Components[0].Name != "Public API" { + t.Errorf("snapshot = %+v, want degraded page with the Public API in outage", snap) } raw, _ := json.Marshal(snap) for _, secret := range []string{up.URL, down.URL, "unexpected status"} {