Show similar earlier incidents and let notes be marked as the fix
The incident view gets a "Seen before" section from the server's new /similar endpoint; an older server without it just shows nothing. C adds a note as the resolution note, alongside c for a plain note. Needs the server release that adds /similar. Claude-Session: https://claude.ai/code/session_01MMados3BD1oSjevHxbmVqU
This commit is contained in:
+16
-3
@@ -276,6 +276,18 @@ func (c *Client) GetIncidentTimeline(id int64) ([]IncidentEvent, error) {
|
||||
return events, c.do(req, &events)
|
||||
}
|
||||
|
||||
// GetSimilarIncidents lists earlier resolved incidents that look like this one
|
||||
// and have notes. Servers before the similar-incidents endpoint answer 404; the
|
||||
// caller treats any error as "nothing to show".
|
||||
func (c *Client) GetSimilarIncidents(id int64) ([]SimilarIncident, error) {
|
||||
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/incidents/%d/similar", id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var similar []SimilarIncident
|
||||
return similar, c.do(req, &similar)
|
||||
}
|
||||
|
||||
func (c *Client) AcknowledgeIncident(id int64) (*Incident, error) {
|
||||
req, err := c.newRequest(http.MethodPost, fmt.Sprintf("/api/incidents/%d/acknowledge", id))
|
||||
if err != nil {
|
||||
@@ -357,10 +369,11 @@ func (c *Client) UnarchiveIncident(id int64) error {
|
||||
return c.do(req, nil)
|
||||
}
|
||||
|
||||
// AddNote appends a note to the incident's timeline.
|
||||
func (c *Client) AddNote(incidentID int64, content string) (*IncidentEvent, error) {
|
||||
// AddNote appends a note to the incident's timeline. pinned files it as the
|
||||
// resolution note: what fixed the incident, shown on similar ones later.
|
||||
func (c *Client) AddNote(incidentID int64, content string, pinned bool) (*IncidentEvent, error) {
|
||||
req, err := c.newRequestWithBody(http.MethodPost,
|
||||
fmt.Sprintf("/api/incidents/%d/notes", incidentID), map[string]string{"content": content})
|
||||
fmt.Sprintf("/api/incidents/%d/notes", incidentID), map[string]any{"content": content, "pinned": pinned})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -165,8 +165,10 @@ func TestClient_IncidentEndpoints(t *testing.T) {
|
||||
http.MethodPost, "/api/incidents/7/archive", ""},
|
||||
{"unarchive", func(c *Client) error { return c.UnarchiveIncident(7) },
|
||||
http.MethodDelete, "/api/incidents/7/archive", ""},
|
||||
{"add note", func(c *Client) error { _, err := c.AddNote(7, "hi"); return err },
|
||||
{"add note", func(c *Client) error { _, err := c.AddNote(7, "hi", false); return err },
|
||||
http.MethodPost, "/api/incidents/7/notes", ""},
|
||||
{"similar", func(c *Client) error { _, err := c.GetSimilarIncidents(7); return err },
|
||||
http.MethodGet, "/api/incidents/7/similar", `[]`},
|
||||
{"delete note", func(c *Client) error { return c.DeleteNote(7, 12) },
|
||||
http.MethodDelete, "/api/incidents/7/notes/12", ""},
|
||||
{"stats", func(c *Client) error { _, err := c.GetIncidentStats(); return err },
|
||||
|
||||
@@ -108,6 +108,10 @@ const (
|
||||
EventResolved = "resolved"
|
||||
EventNote = "note"
|
||||
|
||||
// A note marked as what fixed the incident. The server leads similar
|
||||
// incidents with these.
|
||||
EventResolutionNote = "resolution_note"
|
||||
|
||||
// Written when a team's dead man's switch stops reporting.
|
||||
EventDeadmanSilent = "deadman_silent"
|
||||
|
||||
@@ -249,3 +253,15 @@ type APIKey struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
LastUsedAt *time.Time `json:"last_used_at"`
|
||||
}
|
||||
|
||||
// SimilarIncident is an earlier, resolved incident with the same signature
|
||||
// (alert name plus stable group labels) as the one being viewed. ResolutionNotes
|
||||
// are its "what fixed it" notes; NoteCount counts its plain notes.
|
||||
type SimilarIncident struct {
|
||||
ID int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
TriggeredAt time.Time `json:"triggered_at"`
|
||||
ResolvedAt time.Time `json:"resolved_at"`
|
||||
NoteCount int `json:"note_count"`
|
||||
ResolutionNotes []IncidentEvent `json:"resolution_notes"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user