feat(console): set an incident's status right in the incident list
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 12m19s
ci / test (pull_request) Successful in 12m58s
ci / build (pull_request) Successful in 15m32s
ci / image (pull_request) Successful in 4m29s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 12m19s
ci / test (pull_request) Successful in 12m58s
ci / build (pull_request) Successful in 15m32s
ci / image (pull_request) Successful in 4m29s
Each row of the incident list offers "Set status" to those who may write the monitor's incidents: a status (built-in or own, the next one preselected), an optional message and whether it shows on status pages. An update may now just change the status, without a message. 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
2409a919c3
commit
437b6e934f
9 files changed
+1966
-1693
No files matched your search
@@ -136,7 +136,7 @@ var endpoints = []endpoint{
|
||||
{method: "PATCH", path: "/api/v1/org/incidents/:id", tag: "Monitors", summary: "Name an incident", perm: "incidents.write",
|
||||
description: "The title status pages show; empty shows the monitor's name.", req: incidentTitleRequest{}, status: http.StatusNoContent},
|
||||
{method: "POST", path: "/api/v1/org/incidents/:id/updates", tag: "Monitors", summary: "Post an update with a status", perm: "incidents.write",
|
||||
description: "`status` is a built-in status or the `id` of one of the organization's own. `message` is Markdown. `public` (default true) shows it on status pages; false keeps it an internal note. The update's status becomes the incident's.",
|
||||
description: "`status` is a built-in status or the `id` of one of the organization's own. `message` is Markdown and may be empty to just change the status. `public` (default true) shows it on status pages; false keeps it an internal note. The update's status becomes the incident's.",
|
||||
req: incidentUpdateRequest{}, resp: incidentUpdateView{}, status: http.StatusCreated},
|
||||
{method: "DELETE", path: "/api/v1/org/incidents/:id/updates/:update", tag: "Monitors", summary: "Delete an update", perm: "incidents.write",
|
||||
status: http.StatusNoContent},
|
||||
|
||||
@@ -909,12 +909,16 @@ func (s *Server) incidentsView(c *gin.Context, p *principal, page web.Page, me w
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v := web.IncidentsView{Rows: make([]web.IncidentRow, len(rows)), Pager: pager(c, info)}
|
||||
v := web.IncidentsView{Rows: make([]web.IncidentRow, len(rows)), Pager: pager(c, info), Custom: d.statuses.list()}
|
||||
for i, r := range rows {
|
||||
v.Rows[i] = d.incidentRow(store.Incident{
|
||||
inc := store.Incident{
|
||||
ID: r.ID, OrgID: r.OrgID, MonitorID: r.MonitorID, StartedAt: r.StartedAt, ResolvedAt: r.ResolvedAt, Cause: r.Cause,
|
||||
Title: r.Title, Status: r.Status, StatusID: r.StatusID,
|
||||
}, r.MonitorName)
|
||||
}
|
||||
v.Rows[i] = d.incidentRow(inc, r.MonitorName)
|
||||
// Whoever may write the monitor's incidents sets the status here.
|
||||
v.Rows[i].CanWrite = canInGroup(p, authz.IncidentsWrite, d.tree, d.byID[r.MonitorID].GroupID)
|
||||
v.Rows[i].NextStatus = nextIncidentStatus(inc)
|
||||
}
|
||||
if monitor != nil {
|
||||
if m, ok := d.byID[*monitor]; ok {
|
||||
|
||||
@@ -47,6 +47,16 @@ func (cs customStatuses) info(key *string, id *uuid.UUID) web.IncidentStatusInfo
|
||||
return web.IncidentStatusInfo{Key: *key}
|
||||
}
|
||||
|
||||
// list returns the statuses for a form, by name.
|
||||
func (cs customStatuses) list() []web.CustomIncidentStatus {
|
||||
out := make([]web.CustomIncidentStatus, 0, len(cs))
|
||||
for _, st := range cs {
|
||||
out = append(out, web.CustomIncidentStatus{ID: st.ID.String(), Name: st.Name, Color: st.Color})
|
||||
}
|
||||
slices.SortFunc(out, func(a, b web.CustomIncidentStatus) int { return strings.Compare(a.Name, b.Name) })
|
||||
return out
|
||||
}
|
||||
|
||||
// of is what an incident shows: resolved once its monitor recovered,
|
||||
// otherwise the status of its latest update, empty before one.
|
||||
func (cs customStatuses) of(i store.Incident) web.IncidentStatusInfo {
|
||||
@@ -207,14 +217,16 @@ func (s *Server) setIncidentTitle(c *gin.Context) {
|
||||
|
||||
type incidentUpdateRequest struct {
|
||||
// Status is a built-in status or the ID of a custom one.
|
||||
Status string `json:"status" binding:"required"`
|
||||
Message string `json:"message" binding:"required,max=5000"`
|
||||
Status string `json:"status" binding:"required"`
|
||||
// Message is Markdown; empty just changes the status.
|
||||
Message string `json:"message" binding:"max=5000"`
|
||||
// Public shows the update on status pages; otherwise it is an internal
|
||||
// note. Defaults to public.
|
||||
Public *bool `json:"public"`
|
||||
}
|
||||
|
||||
// addIncidentUpdate tells what is going on: a status and a message.
|
||||
// addIncidentUpdate tells what is going on: a status and, usually, a
|
||||
// message.
|
||||
func (s *Server) addIncidentUpdate(c *gin.Context) {
|
||||
var req incidentUpdateRequest
|
||||
if !bind(c, &req) {
|
||||
@@ -233,7 +245,7 @@ func (s *Server) addIncidentUpdate(c *gin.Context) {
|
||||
}
|
||||
key, statusID = "custom", &id
|
||||
}
|
||||
if (statusID == nil && !slices.Contains(web.IncidentStatuses, key)) || req.Message == "" {
|
||||
if statusID == nil && !slices.Contains(web.IncidentStatuses, key) {
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_input")
|
||||
return
|
||||
}
|
||||
@@ -345,10 +357,7 @@ func (s *Server) incidentDetailView(c *gin.Context, p *principal, page web.Page,
|
||||
v.Timeline = append(v.Timeline, x.e)
|
||||
}
|
||||
v.NextStatus = nextIncidentStatus(inc)
|
||||
for _, st := range d.statuses {
|
||||
v.Custom = append(v.Custom, web.CustomIncidentStatus{ID: st.ID.String(), Name: st.Name, Color: st.Color})
|
||||
}
|
||||
slices.SortFunc(v.Custom, func(a, b web.CustomIncidentStatus) int { return strings.Compare(a.Name, b.Name) })
|
||||
v.Custom = d.statuses.list()
|
||||
return web.IncidentDetailPage(page, me, v), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -45,13 +45,8 @@ func TestIncidentUpdates(t *testing.T) {
|
||||
}
|
||||
|
||||
// Updates with a status, public or internal, and a title.
|
||||
for _, bad := range []map[string]any{
|
||||
{"status": "panicking", "message": "x"},
|
||||
{"status": "investigating", "message": " "},
|
||||
} {
|
||||
st, body := owner.do("POST", base+"/updates", bad)
|
||||
expect(t, "invalid update", st, body, http.StatusUnprocessableEntity, "invalid_input")
|
||||
}
|
||||
st, body := owner.do("POST", base+"/updates", map[string]any{"status": "panicking", "message": "x"})
|
||||
expect(t, "invalid status", st, body, http.StatusUnprocessableEntity, "invalid_input")
|
||||
if st, body := owner.do("POST", base+"/updates", map[string]any{"status": "investigating", "message": "We are **looking** into it."}); st != http.StatusCreated {
|
||||
t.Fatalf("post update = %d %v", st, body)
|
||||
}
|
||||
@@ -95,12 +90,26 @@ func TestIncidentUpdates(t *testing.T) {
|
||||
if st, _ := viewer.do("GET", base, nil); st != http.StatusOK {
|
||||
t.Errorf("viewer reads incident = %d", st)
|
||||
}
|
||||
st, body := viewer.do("POST", base+"/updates", map[string]any{"status": "monitoring", "message": "x"})
|
||||
st, body = viewer.do("POST", base+"/updates", map[string]any{"status": "monitoring", "message": "x"})
|
||||
expect(t, "viewer posts update", st, body, http.StatusForbidden, "forbidden")
|
||||
// The incident list sets the status right there, for writers only.
|
||||
if _, _, html := owner.page("/incidents"); !strings.Contains(html, "Set status") || !strings.Contains(html, `data-api="/org/incidents/`+incident.String()+`/updates"`) {
|
||||
t.Error("the incident list lacks the set-status button")
|
||||
}
|
||||
if _, _, html := viewer.page("/incidents"); strings.Contains(html, "Set status") {
|
||||
t.Error("the viewer is offered setting the status")
|
||||
}
|
||||
if _, _, html := viewer.page("/incidents/" + incident.String()); strings.Contains(html, "Post update") {
|
||||
t.Error("the viewer is offered the update form")
|
||||
}
|
||||
|
||||
// A status change needs no message.
|
||||
_, quick := owner.do("POST", base+"/updates", map[string]any{"status": "monitoring", "message": "", "public": true})
|
||||
if quick["status"] != "monitoring" || status() != "monitoring" {
|
||||
t.Errorf("status-only update = %v", quick)
|
||||
}
|
||||
owner.do("DELETE", base+"/updates/"+quick["id"].(string), nil)
|
||||
|
||||
// Deleting an update falls back to the previous status; the monitor
|
||||
// recovering resolves the incident whatever was said.
|
||||
if st, _ := owner.do("DELETE", base+"/updates/"+note["id"].(string), nil); st != http.StatusNoContent || status() != "investigating" {
|
||||
|
||||
Reference in new issue
Block a user