feat: own incident statuses with a color; incidents before maintenance
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 9m38s
ci / test (pull_request) Successful in 14m21s
ci / build (pull_request) Successful in 16m36s
ci / image (pull_request) Successful in 3m37s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 9m38s
ci / test (pull_request) Successful in 14m21s
ci / build (pull_request) Successful in 16m36s
ci / image (pull_request) Successful in 3m37s
Organizations add statuses of their own, with a name and a color, next to the built-in ones (Settings, incident statuses; API under /org/incident-statuses, managed with org.manage). Updates pick them by ID; the console and status pages show them in their color. Renaming or recoloring carries into the history; a status in use cannot be deleted (409 status_in_use). API responses give status "custom" with status_id, status_name and status_color. Status pages now list recent incidents before planned maintenance. 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
43a04e99b1
commit
2409a919c3
26 files changed
+1257
-238
No files matched your search
+111
-13
@@ -13,15 +13,16 @@ import (
|
||||
)
|
||||
|
||||
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
|
||||
INSERT INTO incident_updates (org_id, incident_id, status, status_id, message, public, author_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, org_id, incident_id, status, message, public, author_id, created_at, status_id
|
||||
`
|
||||
|
||||
type AddIncidentUpdateParams struct {
|
||||
OrgID uuid.UUID
|
||||
IncidentID uuid.UUID
|
||||
Status string
|
||||
StatusID *uuid.UUID
|
||||
Message string
|
||||
Public bool
|
||||
AuthorID *uuid.UUID
|
||||
@@ -32,6 +33,7 @@ func (q *Queries) AddIncidentUpdate(ctx context.Context, arg AddIncidentUpdatePa
|
||||
arg.OrgID,
|
||||
arg.IncidentID,
|
||||
arg.Status,
|
||||
arg.StatusID,
|
||||
arg.Message,
|
||||
arg.Public,
|
||||
arg.AuthorID,
|
||||
@@ -46,6 +48,7 @@ func (q *Queries) AddIncidentUpdate(ctx context.Context, arg AddIncidentUpdatePa
|
||||
&i.Public,
|
||||
&i.AuthorID,
|
||||
&i.CreatedAt,
|
||||
&i.StatusID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -120,6 +123,29 @@ func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (N
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createIncidentStatus = `-- name: CreateIncidentStatus :one
|
||||
INSERT INTO incident_statuses (org_id, name, color) VALUES ($1, $2, $3) RETURNING id, org_id, name, color, created_at
|
||||
`
|
||||
|
||||
type CreateIncidentStatusParams struct {
|
||||
OrgID uuid.UUID
|
||||
Name string
|
||||
Color string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateIncidentStatus(ctx context.Context, arg CreateIncidentStatusParams) (IncidentStatus, error) {
|
||||
row := q.db.QueryRow(ctx, createIncidentStatus, arg.OrgID, arg.Name, arg.Color)
|
||||
var i IncidentStatus
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteChannel = `-- name: DeleteChannel :execrows
|
||||
DELETE FROM notification_channels WHERE id = $1
|
||||
`
|
||||
@@ -132,6 +158,18 @@ func (q *Queries) DeleteChannel(ctx context.Context, id uuid.UUID) (int64, error
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const deleteIncidentStatus = `-- name: DeleteIncidentStatus :execrows
|
||||
DELETE FROM incident_statuses WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteIncidentStatus(ctx context.Context, id uuid.UUID) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteIncidentStatus, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const deleteIncidentUpdate = `-- name: DeleteIncidentUpdate :execrows
|
||||
DELETE FROM incident_updates WHERE id = $1 AND incident_id = $2
|
||||
`
|
||||
@@ -193,7 +231,7 @@ func (q *Queries) GetChannel(ctx context.Context, id uuid.UUID) (NotificationCha
|
||||
}
|
||||
|
||||
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
|
||||
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, i.title, i.status, i.status_id, 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
|
||||
`
|
||||
@@ -207,6 +245,7 @@ type GetIncidentRow struct {
|
||||
Cause []byte
|
||||
Title string
|
||||
Status *string
|
||||
StatusID *uuid.UUID
|
||||
MonitorName string
|
||||
MonitorGroupID *uuid.UUID
|
||||
}
|
||||
@@ -223,6 +262,7 @@ func (q *Queries) GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.StatusID,
|
||||
&i.MonitorName,
|
||||
&i.MonitorGroupID,
|
||||
)
|
||||
@@ -230,7 +270,7 @@ func (q *Queries) GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow
|
||||
}
|
||||
|
||||
const incidentsForMonitors = `-- name: IncidentsForMonitors :many
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status FROM incidents
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents
|
||||
WHERE monitor_id = ANY ($1::uuid[]) AND (resolved_at IS NULL OR resolved_at > $2)
|
||||
ORDER BY started_at DESC
|
||||
LIMIT 50
|
||||
@@ -259,6 +299,7 @@ func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMoni
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.StatusID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -335,8 +376,38 @@ func (q *Queries) ListChannels(ctx context.Context) ([]NotificationChannel, erro
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listIncidentStatuses = `-- name: ListIncidentStatuses :many
|
||||
SELECT id, org_id, name, color, created_at FROM incident_statuses ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListIncidentStatuses(ctx context.Context) ([]IncidentStatus, error) {
|
||||
rows, err := q.db.Query(ctx, listIncidentStatuses)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []IncidentStatus{}
|
||||
for rows.Next() {
|
||||
var i IncidentStatus
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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
|
||||
SELECT u.id, u.org_id, u.incident_id, u.status, u.message, u.public, u.author_id, u.created_at, u.status_id, 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
|
||||
@@ -351,6 +422,7 @@ type ListIncidentUpdatesRow struct {
|
||||
Public bool
|
||||
AuthorID *uuid.UUID
|
||||
CreatedAt time.Time
|
||||
StatusID *uuid.UUID
|
||||
AuthorName string
|
||||
}
|
||||
|
||||
@@ -373,6 +445,7 @@ func (q *Queries) ListIncidentUpdates(ctx context.Context, incidentID uuid.UUID)
|
||||
&i.Public,
|
||||
&i.AuthorID,
|
||||
&i.CreatedAt,
|
||||
&i.StatusID,
|
||||
&i.AuthorName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -386,7 +459,7 @@ func (q *Queries) ListIncidentUpdates(ctx context.Context, incidentID uuid.UUID)
|
||||
}
|
||||
|
||||
const listIncidents = `-- name: ListIncidents :many
|
||||
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
|
||||
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, i.title, i.status, i.status_id, 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)
|
||||
@@ -417,6 +490,7 @@ type ListIncidentsRow struct {
|
||||
Cause []byte
|
||||
Title string
|
||||
Status *string
|
||||
StatusID *uuid.UUID
|
||||
MonitorName string
|
||||
}
|
||||
|
||||
@@ -447,6 +521,7 @@ func (q *Queries) ListIncidents(ctx context.Context, arg ListIncidentsParams) ([
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.StatusID,
|
||||
&i.MonitorName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -564,7 +639,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, title, status
|
||||
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id
|
||||
`
|
||||
|
||||
type OpenIncidentParams struct {
|
||||
@@ -591,12 +666,13 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.StatusID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const openIncidents = `-- name: OpenIncidents :many
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status FROM incidents WHERE resolved_at IS NULL
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents WHERE resolved_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
||||
@@ -617,6 +693,7 @@ func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.StatusID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -629,7 +706,7 @@ func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
||||
}
|
||||
|
||||
const publicIncidentUpdates = `-- name: PublicIncidentUpdates :many
|
||||
SELECT incident_id, status, message, created_at FROM incident_updates
|
||||
SELECT incident_id, status, status_id, message, created_at FROM incident_updates
|
||||
WHERE incident_id = ANY($1::uuid[]) AND public
|
||||
ORDER BY created_at DESC, id DESC
|
||||
`
|
||||
@@ -637,6 +714,7 @@ ORDER BY created_at DESC, id DESC
|
||||
type PublicIncidentUpdatesRow struct {
|
||||
IncidentID uuid.UUID
|
||||
Status string
|
||||
StatusID *uuid.UUID
|
||||
Message string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -654,6 +732,7 @@ func (q *Queries) PublicIncidentUpdates(ctx context.Context, ids []uuid.UUID) ([
|
||||
if err := rows.Scan(
|
||||
&i.IncidentID,
|
||||
&i.Status,
|
||||
&i.StatusID,
|
||||
&i.Message,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
@@ -668,8 +747,8 @@ func (q *Queries) PublicIncidentUpdates(ctx context.Context, ids []uuid.UUID) ([
|
||||
}
|
||||
|
||||
const refreshIncidentStatus = `-- name: RefreshIncidentStatus :exec
|
||||
UPDATE incidents SET status = (
|
||||
SELECT u.status FROM incident_updates u WHERE u.incident_id = incidents.id
|
||||
UPDATE incidents SET (status, status_id) = (
|
||||
SELECT u.status, u.status_id 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
|
||||
`
|
||||
@@ -683,7 +762,7 @@ func (q *Queries) RefreshIncidentStatus(ctx context.Context, id uuid.UUID) error
|
||||
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, title, status
|
||||
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id
|
||||
`
|
||||
|
||||
type ResolveIncidentParams struct {
|
||||
@@ -703,6 +782,7 @@ func (q *Queries) ResolveIncident(ctx context.Context, arg ResolveIncidentParams
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.StatusID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -757,3 +837,21 @@ func (q *Queries) UpdateChannel(ctx context.Context, arg UpdateChannelParams) (N
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateIncidentStatus = `-- name: UpdateIncidentStatus :execrows
|
||||
UPDATE incident_statuses SET name = $1, color = $2 WHERE id = $3
|
||||
`
|
||||
|
||||
type UpdateIncidentStatusParams struct {
|
||||
Name string
|
||||
Color string
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateIncidentStatus(ctx context.Context, arg UpdateIncidentStatusParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateIncidentStatus, arg.Name, arg.Color, arg.ID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
@@ -162,6 +162,15 @@ type Incident struct {
|
||||
Cause []byte
|
||||
Title string
|
||||
Status *string
|
||||
StatusID *uuid.UUID
|
||||
}
|
||||
|
||||
type IncidentStatus struct {
|
||||
ID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
Name string
|
||||
Color string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type IncidentUpdate struct {
|
||||
@@ -173,6 +182,7 @@ type IncidentUpdate struct {
|
||||
Public bool
|
||||
AuthorID *uuid.UUID
|
||||
CreatedAt time.Time
|
||||
StatusID *uuid.UUID
|
||||
}
|
||||
|
||||
type Invitation struct {
|
||||
|
||||
@@ -65,6 +65,7 @@ type Querier interface {
|
||||
CreateChannel(ctx context.Context, arg CreateChannelParams) (NotificationChannel, error)
|
||||
CreateGroup(ctx context.Context, arg CreateGroupParams) (MonitorGroup, error)
|
||||
CreateIdentity(ctx context.Context, arg CreateIdentityParams) error
|
||||
CreateIncidentStatus(ctx context.Context, arg CreateIncidentStatusParams) (IncidentStatus, error)
|
||||
CreateInvitation(ctx context.Context, arg CreateInvitationParams) (Invitation, error)
|
||||
CreateMaintenance(ctx context.Context, arg CreateMaintenanceParams) (MaintenanceWindow, error)
|
||||
CreateMonitor(ctx context.Context, arg CreateMonitorParams) (Monitor, error)
|
||||
@@ -89,6 +90,7 @@ type Querier interface {
|
||||
DeleteAssignmentsForResource(ctx context.Context, arg DeleteAssignmentsForResourceParams) error
|
||||
DeleteChannel(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteGroup(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteIncidentStatus(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteIncidentUpdate(ctx context.Context, arg DeleteIncidentUpdateParams) (int64, error)
|
||||
DeleteInvitation(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteInvitationsForEmail(ctx context.Context, email string) error
|
||||
@@ -205,6 +207,7 @@ type Querier interface {
|
||||
// Newest first, a page from a keyset cursor (see paging.go).
|
||||
ListEvidence(ctx context.Context, arg ListEvidenceParams) ([]ListEvidenceRow, error)
|
||||
ListGroups(ctx context.Context) ([]MonitorGroup, error)
|
||||
ListIncidentStatuses(ctx context.Context) ([]IncidentStatus, error)
|
||||
// Newest first, with the author's name.
|
||||
ListIncidentUpdates(ctx context.Context, incidentID uuid.UUID) ([]ListIncidentUpdatesRow, error)
|
||||
// Newest first, a page from a keyset cursor (see paging.go); optionally of
|
||||
@@ -355,6 +358,7 @@ type Querier interface {
|
||||
UpdateAlertGroup(ctx context.Context, arg UpdateAlertGroupParams) (AlertGroup, error)
|
||||
UpdateChannel(ctx context.Context, arg UpdateChannelParams) (NotificationChannel, error)
|
||||
UpdateGroup(ctx context.Context, arg UpdateGroupParams) (MonitorGroup, error)
|
||||
UpdateIncidentStatus(ctx context.Context, arg UpdateIncidentStatusParams) (int64, error)
|
||||
UpdateMaintenance(ctx context.Context, arg UpdateMaintenanceParams) (MaintenanceWindow, error)
|
||||
UpdateMonitor(ctx context.Context, arg UpdateMonitorParams) (Monitor, error)
|
||||
UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams) (Org, error)
|
||||
|
||||
@@ -106,8 +106,8 @@ WHERE i.id = $1;
|
||||
UPDATE incidents SET title = sqlc.arg(title) WHERE id = sqlc.arg(id);
|
||||
|
||||
-- name: AddIncidentUpdate :one
|
||||
INSERT INTO incident_updates (org_id, incident_id, status, message, public, author_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
INSERT INTO incident_updates (org_id, incident_id, status, status_id, message, public, author_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteIncidentUpdate :execrows
|
||||
@@ -115,8 +115,8 @@ DELETE FROM incident_updates WHERE id = sqlc.arg(id) AND incident_id = sqlc.arg(
|
||||
|
||||
-- name: RefreshIncidentStatus :exec
|
||||
-- The incident shows the status of its latest update.
|
||||
UPDATE incidents SET status = (
|
||||
SELECT u.status FROM incident_updates u WHERE u.incident_id = incidents.id
|
||||
UPDATE incidents SET (status, status_id) = (
|
||||
SELECT u.status, u.status_id 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;
|
||||
|
||||
@@ -129,6 +129,18 @@ ORDER BY u.created_at DESC, u.id DESC;
|
||||
|
||||
-- name: PublicIncidentUpdates :many
|
||||
-- The public updates of incidents shown on a status page, newest first.
|
||||
SELECT incident_id, status, message, created_at FROM incident_updates
|
||||
SELECT incident_id, status, status_id, message, created_at FROM incident_updates
|
||||
WHERE incident_id = ANY(sqlc.arg(ids)::uuid[]) AND public
|
||||
ORDER BY created_at DESC, id DESC;
|
||||
|
||||
-- name: ListIncidentStatuses :many
|
||||
SELECT * FROM incident_statuses ORDER BY name;
|
||||
|
||||
-- name: CreateIncidentStatus :one
|
||||
INSERT INTO incident_statuses (org_id, name, color) VALUES ($1, $2, $3) RETURNING *;
|
||||
|
||||
-- name: UpdateIncidentStatus :execrows
|
||||
UPDATE incident_statuses SET name = sqlc.arg(name), color = sqlc.arg(color) WHERE id = sqlc.arg(id);
|
||||
|
||||
-- name: DeleteIncidentStatus :execrows
|
||||
DELETE FROM incident_statuses WHERE id = $1;
|
||||
Reference in new issue
Block a user