fix(api): report a page as degraded unless every component is down

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 08:55:39 +01:00
1 parent 4d1db0943e
commit e6c3deb54d
2 files changed
+13 -4

No files matched your search

+10 -2
View File
@@ -98,7 +98,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
} }
names := map[uuid.UUID]string{} names := map[uuid.UUID]string{}
worst := agentapi.PageOperational worst := agentapi.PageOperational
allUnknown := true allUnknown, allDown := true, len(listed) > 0
for _, m := range listed { for _, m := range listed {
name := m.Label name := m.Label
if name == "" { if name == "" {
@@ -119,6 +119,9 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
if comp.Status != agentapi.PageUnknown { if comp.Status != agentapi.PageUnknown {
allUnknown = false allUnknown = false
} }
if comp.Status != agentapi.PageOutage {
allDown = false
}
worst = worse(worst, comp.Status) worst = worse(worst, comp.Status)
if n := len(snap.Sections); n == 0 || snap.Sections[n-1].Name != m.Section { if n := len(snap.Sections); n == 0 || snap.Sections[n-1].Name != m.Section {
snap.Sections = append(snap.Sections, agentapi.Section{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 := &snap.Sections[len(snap.Sections)-1]
last.Components = append(last.Components, comp) 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 snap.Status = worst
if allUnknown { switch {
case allUnknown:
snap.Status = agentapi.PageUnknown snap.Status = agentapi.PageUnknown
case worst == agentapi.PageOutage && !allDown:
snap.Status = agentapi.PageDegraded
} }
for _, i := range incidents { for _, i := range incidents {
snap.Incidents = append(snap.Incidents, agentapi.PageIncident{Component: names[i.MonitorID], StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt}) snap.Incidents = append(snap.Incidents, agentapi.PageIncident{Component: names[i.MonitorID], StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt})
+3 -2
View File
@@ -91,8 +91,9 @@ func TestStatusPages(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Page() failed: %v", err) t.Fatalf("Page() failed: %v", err)
} }
if snap.Status != agentapi.PageOutage || len(snap.Sections) != 2 || snap.Sections[1].Components[0].Name != "Public API" { if snap.Status != agentapi.PageDegraded || len(snap.Sections) != 2 || snap.Sections[1].Components[0].Status != agentapi.PageOutage ||
t.Errorf("snapshot = %+v, want outage with Frontend and Backend sections", snap) 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) raw, _ := json.Marshal(snap)
for _, secret := range []string{up.URL, down.URL, "unexpected status"} { for _, secret := range []string{up.URL, down.URL, "unexpected status"} {