feat: maintenance windows and Markdown descriptions
Monitors and groups get one-off or recurring maintenance. While it is in progress, failures neither open incidents nor alert, so the SLA is not affected; successes still resolve earlier incidents. The console shows monitors under maintenance and lists windows on a new page and on monitor pages. Status pages announce maintenance in progress and planned for the next two weeks and mark affected components; the occurrences are part of the snapshot and evaluated when the page is shown, so this also works from cache during an API outage. Maintenance and status page descriptions are rendered as Markdown. Closes #71 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
259b3b8e05
commit
43b0a35f20
28 files changed
+3918
-894
No files matched your search
+57
-30
@@ -52,6 +52,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
open []store.Incident
|
||||
daily []store.DailyBucketsForMonitorsRow
|
||||
incidents []store.Incident
|
||||
planned map[uuid.UUID][]store.MaintenanceWindow
|
||||
)
|
||||
now := time.Now()
|
||||
err := s.db.Tx(ctx, tenant.Org(page.OrgID, uuid.Nil), func(q *store.Queries) error {
|
||||
@@ -77,6 +78,9 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
if incidents, err = q.IncidentsForMonitors(ctx, store.IncidentsForMonitorsParams{Ids: ids, Since: ptr(now.Add(-incidentLookback))}); err != nil {
|
||||
return err
|
||||
}
|
||||
if planned, err = maintenanceFor(ctx, q, ids); err != nil {
|
||||
return err
|
||||
}
|
||||
docs, err := q.LegalDocuments(ctx, &page.OrgID)
|
||||
snap.Legal = mergeLegal(docs)
|
||||
return err
|
||||
@@ -101,8 +105,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
days[d.MonitorID] = append(days[d.MonitorID], web.Bucket{Start: d.Bucket, Total: d.Total, OK: d.OkCount})
|
||||
}
|
||||
names := map[uuid.UUID]string{}
|
||||
worst := agentapi.PageOperational
|
||||
allUnknown, allDown := true, len(listed) > 0
|
||||
var states []string
|
||||
for _, m := range listed {
|
||||
name := m.Label
|
||||
if name == "" {
|
||||
@@ -120,44 +123,21 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
default:
|
||||
comp.Status = agentapi.PageOperational
|
||||
}
|
||||
if comp.Status != agentapi.PageUnknown {
|
||||
allUnknown = false
|
||||
}
|
||||
if comp.Status != agentapi.PageOutage {
|
||||
allDown = false
|
||||
}
|
||||
worst = worse(worst, comp.Status)
|
||||
states = append(states, 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})
|
||||
}
|
||||
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
|
||||
switch {
|
||||
case allUnknown:
|
||||
snap.Status = agentapi.PageUnknown
|
||||
case worst == agentapi.PageOutage && !allDown:
|
||||
snap.Status = agentapi.PageDegraded
|
||||
}
|
||||
snap.Status = agentapi.Summarize(states)
|
||||
snap.Maintenance = pageMaintenance(planned, names, now)
|
||||
for _, i := range incidents {
|
||||
snap.Incidents = append(snap.Incidents, agentapi.PageIncident{Component: names[i.MonitorID], StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt})
|
||||
}
|
||||
return snap, nil
|
||||
}
|
||||
|
||||
// worse returns the more severe state; unknown components do not make the
|
||||
// whole page look broken.
|
||||
func worse(a, b string) string {
|
||||
rank := map[string]int{agentapi.PageOperational: 0, agentapi.PageUnknown: 0, agentapi.PageDegraded: 1, agentapi.PageOutage: 2}
|
||||
if rank[b] > rank[a] {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func dayHistory(buckets []web.Bucket, now time.Time) []agentapi.Day {
|
||||
byDay := map[string]web.Bucket{}
|
||||
for _, b := range buckets {
|
||||
@@ -214,7 +194,7 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
type statusPageRequest struct {
|
||||
Slug string `json:"slug" binding:"required,max=63"`
|
||||
Title string `json:"title" binding:"required,max=200"`
|
||||
Description string `json:"description" binding:"max=2000"`
|
||||
Description string `json:"description" binding:"max=10000"`
|
||||
Published bool `json:"published"`
|
||||
Theme agentapi.Theme `json:"theme"`
|
||||
}
|
||||
@@ -568,5 +548,52 @@ func (s *Server) exportStatusPage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
c.Header("Content-Disposition", `attachment; filename="`+row.Slug+`.html"`)
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(snap, web.PublicAssets{InlineCSS: css}))
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(snap.WithMaintenance(time.Now()), web.PublicAssets{InlineCSS: css, Now: time.Now()}))
|
||||
}
|
||||
|
||||
// pageMaintenance lists the occurrences affecting the page's components
|
||||
// from an hour ago, so a snapshot cached just before still knows about
|
||||
// maintenance in progress, to two weeks ahead.
|
||||
func pageMaintenance(planned map[uuid.UUID][]store.MaintenanceWindow, names map[uuid.UUID]string, now time.Time) []agentapi.PageMaintenance {
|
||||
// Occurrences are matched by instant: time.Time values of the same
|
||||
// instant differ as map keys when their locations were loaded apart.
|
||||
type key struct {
|
||||
window uuid.UUID
|
||||
start int64
|
||||
}
|
||||
byKey := map[key]*agentapi.PageMaintenance{}
|
||||
var order []key
|
||||
for monitor, ws := range planned {
|
||||
name, listed := names[monitor]
|
||||
if !listed {
|
||||
continue
|
||||
}
|
||||
for _, w := range ws {
|
||||
for _, occ := range ruleOf(w).Occurrences(now.Add(-time.Hour), now.Add(upcomingHorizon)) {
|
||||
k := key{w.ID, occ.Start.UnixNano()}
|
||||
m, ok := byKey[k]
|
||||
if !ok {
|
||||
m = &agentapi.PageMaintenance{Title: w.Title, Description: w.Description, Start: occ.Start, End: occ.End}
|
||||
byKey[k] = m
|
||||
order = append(order, k)
|
||||
}
|
||||
if !slices.Contains(m.Components, name) {
|
||||
m.Components = append(m.Components, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out := make([]agentapi.PageMaintenance, 0, len(order))
|
||||
for _, k := range order {
|
||||
m := *byKey[k]
|
||||
slices.Sort(m.Components)
|
||||
out = append(out, m)
|
||||
}
|
||||
slices.SortFunc(out, func(a, b agentapi.PageMaintenance) int {
|
||||
if c := a.Start.Compare(b.Start); c != 0 {
|
||||
return c
|
||||
}
|
||||
return strings.Compare(a.Title, b.Title)
|
||||
})
|
||||
return out
|
||||
}
|
||||
Reference in new issue
Block a user