feat: incident updates with a status, public or internal
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m54s
ci / test (pull_request) Successful in 12m15s
ci / build (pull_request) Successful in 11m0s
ci / image (pull_request) Successful in 4m23s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m54s
ci / test (pull_request) Successful in 12m15s
ci / build (pull_request) Successful in 11m0s
ci / image (pull_request) Successful in 4m23s
Outages open and close with their monitor; now people can say what is going on. An incident gets an optional title and updates, each with a status (investigating, identified, monitoring, resolved) and a Markdown message, shown on status pages or kept as an internal note. The incident shows the latest update's status, resolved once its monitor recovered. The console lists title and status and has a page per incident with its timeline (outage, updates, recovery) and, for incidents.write in the monitor's group, forms to post updates and set the title. Status pages show title, status and public updates. API: GET/PATCH /org/incidents/:id, POST and DELETE /org/incidents/:id/updates; the incident list carries title and status; the organization export includes the updates. 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
6f0cf59406
commit
43a04e99b1
27 files changed
+2753
-908
No files matched your search
@@ -12,6 +12,44 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addIncidentUpdate = `-- name: AddIncidentUpdate :one
|
||||
INSERT INTO incident_updates (org_id, incident_id, status, message, public, author_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, org_id, incident_id, status, message, public, author_id, created_at
|
||||
`
|
||||
|
||||
type AddIncidentUpdateParams struct {
|
||||
OrgID uuid.UUID
|
||||
IncidentID uuid.UUID
|
||||
Status string
|
||||
Message string
|
||||
Public bool
|
||||
AuthorID *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) AddIncidentUpdate(ctx context.Context, arg AddIncidentUpdateParams) (IncidentUpdate, error) {
|
||||
row := q.db.QueryRow(ctx, addIncidentUpdate,
|
||||
arg.OrgID,
|
||||
arg.IncidentID,
|
||||
arg.Status,
|
||||
arg.Message,
|
||||
arg.Public,
|
||||
arg.AuthorID,
|
||||
)
|
||||
var i IncidentUpdate
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.IncidentID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.Public,
|
||||
&i.AuthorID,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const claimNotifications = `-- name: ClaimNotifications :many
|
||||
UPDATE notifications SET next_attempt_at = now() + interval '5 minutes'
|
||||
WHERE id IN (
|
||||
@@ -94,6 +132,23 @@ func (q *Queries) DeleteChannel(ctx context.Context, id uuid.UUID) (int64, error
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const deleteIncidentUpdate = `-- name: DeleteIncidentUpdate :execrows
|
||||
DELETE FROM incident_updates WHERE id = $1 AND incident_id = $2
|
||||
`
|
||||
|
||||
type DeleteIncidentUpdateParams struct {
|
||||
ID uuid.UUID
|
||||
IncidentID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteIncidentUpdate(ctx context.Context, arg DeleteIncidentUpdateParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteIncidentUpdate, arg.ID, arg.IncidentID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const enqueueNotification = `-- name: EnqueueNotification :exec
|
||||
INSERT INTO notifications (org_id, channel_id, incident_id, event)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
@@ -137,8 +192,45 @@ func (q *Queries) GetChannel(ctx context.Context, id uuid.UUID) (NotificationCha
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getIncident = `-- name: GetIncident :one
|
||||
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, i.title, i.status, m.name AS monitor_name, m.group_id AS monitor_group_id
|
||||
FROM incidents i JOIN monitors m ON m.id = i.monitor_id
|
||||
WHERE i.id = $1
|
||||
`
|
||||
|
||||
type GetIncidentRow struct {
|
||||
ID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
MonitorID uuid.UUID
|
||||
StartedAt time.Time
|
||||
ResolvedAt *time.Time
|
||||
Cause []byte
|
||||
Title string
|
||||
Status *string
|
||||
MonitorName string
|
||||
MonitorGroupID *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow, error) {
|
||||
row := q.db.QueryRow(ctx, getIncident, id)
|
||||
var i GetIncidentRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.MonitorID,
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.MonitorName,
|
||||
&i.MonitorGroupID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const incidentsForMonitors = `-- name: IncidentsForMonitors :many
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status FROM incidents
|
||||
WHERE monitor_id = ANY ($1::uuid[]) AND (resolved_at IS NULL OR resolved_at > $2)
|
||||
ORDER BY started_at DESC
|
||||
LIMIT 50
|
||||
@@ -165,6 +257,8 @@ func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMoni
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -241,8 +335,58 @@ func (q *Queries) ListChannels(ctx context.Context) ([]NotificationChannel, erro
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listIncidentUpdates = `-- name: ListIncidentUpdates :many
|
||||
SELECT u.id, u.org_id, u.incident_id, u.status, u.message, u.public, u.author_id, u.created_at, coalesce(nullif(usr.display_name, ''), usr.email::text, '')::text AS author_name
|
||||
FROM incident_updates u LEFT JOIN users usr ON usr.id = u.author_id
|
||||
WHERE u.incident_id = $1
|
||||
ORDER BY u.created_at DESC, u.id DESC
|
||||
`
|
||||
|
||||
type ListIncidentUpdatesRow struct {
|
||||
ID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
IncidentID uuid.UUID
|
||||
Status string
|
||||
Message string
|
||||
Public bool
|
||||
AuthorID *uuid.UUID
|
||||
CreatedAt time.Time
|
||||
AuthorName string
|
||||
}
|
||||
|
||||
// Newest first, with the author's name.
|
||||
func (q *Queries) ListIncidentUpdates(ctx context.Context, incidentID uuid.UUID) ([]ListIncidentUpdatesRow, error) {
|
||||
rows, err := q.db.Query(ctx, listIncidentUpdates, incidentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListIncidentUpdatesRow{}
|
||||
for rows.Next() {
|
||||
var i ListIncidentUpdatesRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.IncidentID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.Public,
|
||||
&i.AuthorID,
|
||||
&i.CreatedAt,
|
||||
&i.AuthorName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listIncidents = `-- name: ListIncidents :many
|
||||
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, m.name AS monitor_name
|
||||
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, i.title, i.status, m.name AS monitor_name
|
||||
FROM incidents i
|
||||
JOIN monitors m ON m.id = i.monitor_id
|
||||
WHERE ($1::uuid IS NULL OR i.monitor_id = $1)
|
||||
@@ -271,6 +415,8 @@ type ListIncidentsRow struct {
|
||||
StartedAt time.Time
|
||||
ResolvedAt *time.Time
|
||||
Cause []byte
|
||||
Title string
|
||||
Status *string
|
||||
MonitorName string
|
||||
}
|
||||
|
||||
@@ -299,6 +445,8 @@ func (q *Queries) ListIncidents(ctx context.Context, arg ListIncidentsParams) ([
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.MonitorName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -416,7 +564,7 @@ const openIncident = `-- name: OpenIncident :one
|
||||
INSERT INTO incidents (org_id, monitor_id, started_at, cause)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (monitor_id) WHERE resolved_at IS NULL DO NOTHING
|
||||
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause
|
||||
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause, title, status
|
||||
`
|
||||
|
||||
type OpenIncidentParams struct {
|
||||
@@ -441,12 +589,14 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const openIncidents = `-- name: OpenIncidents :many
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents WHERE resolved_at IS NULL
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status FROM incidents WHERE resolved_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
||||
@@ -465,6 +615,8 @@ func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -476,10 +628,62 @@ func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const publicIncidentUpdates = `-- name: PublicIncidentUpdates :many
|
||||
SELECT incident_id, status, message, created_at FROM incident_updates
|
||||
WHERE incident_id = ANY($1::uuid[]) AND public
|
||||
ORDER BY created_at DESC, id DESC
|
||||
`
|
||||
|
||||
type PublicIncidentUpdatesRow struct {
|
||||
IncidentID uuid.UUID
|
||||
Status string
|
||||
Message string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// The public updates of incidents shown on a status page, newest first.
|
||||
func (q *Queries) PublicIncidentUpdates(ctx context.Context, ids []uuid.UUID) ([]PublicIncidentUpdatesRow, error) {
|
||||
rows, err := q.db.Query(ctx, publicIncidentUpdates, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []PublicIncidentUpdatesRow{}
|
||||
for rows.Next() {
|
||||
var i PublicIncidentUpdatesRow
|
||||
if err := rows.Scan(
|
||||
&i.IncidentID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const refreshIncidentStatus = `-- name: RefreshIncidentStatus :exec
|
||||
UPDATE incidents SET status = (
|
||||
SELECT u.status FROM incident_updates u WHERE u.incident_id = incidents.id
|
||||
ORDER BY u.created_at DESC, u.id DESC LIMIT 1
|
||||
) WHERE incidents.id = $1
|
||||
`
|
||||
|
||||
// The incident shows the status of its latest update.
|
||||
func (q *Queries) RefreshIncidentStatus(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, refreshIncidentStatus, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const resolveIncident = `-- name: ResolveIncident :one
|
||||
UPDATE incidents SET resolved_at = $1
|
||||
WHERE monitor_id = $2 AND resolved_at IS NULL
|
||||
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause
|
||||
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause, title, status
|
||||
`
|
||||
|
||||
type ResolveIncidentParams struct {
|
||||
@@ -497,10 +701,29 @@ func (q *Queries) ResolveIncident(ctx context.Context, arg ResolveIncidentParams
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const setIncidentTitle = `-- name: SetIncidentTitle :execrows
|
||||
UPDATE incidents SET title = $1 WHERE id = $2
|
||||
`
|
||||
|
||||
type SetIncidentTitleParams struct {
|
||||
Title string
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) SetIncidentTitle(ctx context.Context, arg SetIncidentTitleParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setIncidentTitle, arg.Title, arg.ID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateChannel = `-- name: UpdateChannel :one
|
||||
UPDATE notification_channels SET name = $2, config = $3, enabled = $4, updated_at = now()
|
||||
WHERE id = $1
|
||||
|
||||
Reference in new issue
Block a user