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
@@ -176,8 +176,47 @@ func (q *Queries) OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDail
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const orgIncidentUpdatesExport = `-- name: OrgIncidentUpdatesExport :many
|
||||
SELECT incident_id, status, message, public, created_at FROM incident_updates
|
||||
WHERE org_id = $1 ORDER BY created_at
|
||||
`
|
||||
|
||||
type OrgIncidentUpdatesExportRow struct {
|
||||
IncidentID uuid.UUID
|
||||
Status string
|
||||
Message string
|
||||
Public bool
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) OrgIncidentUpdatesExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentUpdatesExportRow, error) {
|
||||
rows, err := q.db.Query(ctx, orgIncidentUpdatesExport, orgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []OrgIncidentUpdatesExportRow{}
|
||||
for rows.Next() {
|
||||
var i OrgIncidentUpdatesExportRow
|
||||
if err := rows.Scan(
|
||||
&i.IncidentID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.Public,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const orgIncidentsExport = `-- name: OrgIncidentsExport :many
|
||||
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause
|
||||
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause, i.title, i.status
|
||||
FROM incidents i LEFT JOIN monitors m ON m.id = i.monitor_id
|
||||
WHERE i.org_id = $1 ORDER BY i.started_at
|
||||
`
|
||||
@@ -189,6 +228,8 @@ type OrgIncidentsExportRow struct {
|
||||
StartedAt time.Time
|
||||
ResolvedAt *time.Time
|
||||
Cause []byte
|
||||
Title string
|
||||
Status *string
|
||||
}
|
||||
|
||||
func (q *Queries) OrgIncidentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentsExportRow, error) {
|
||||
@@ -207,6 +248,8 @@ func (q *Queries) OrgIncidentsExport(ctx context.Context, orgID uuid.UUID) ([]Or
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -160,6 +160,19 @@ type Incident struct {
|
||||
StartedAt time.Time
|
||||
ResolvedAt *time.Time
|
||||
Cause []byte
|
||||
Title string
|
||||
Status *string
|
||||
}
|
||||
|
||||
type IncidentUpdate struct {
|
||||
ID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
IncidentID uuid.UUID
|
||||
Status string
|
||||
Message string
|
||||
Public bool
|
||||
AuthorID *uuid.UUID
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Invitation struct {
|
||||
|
||||
@@ -16,6 +16,7 @@ type Querier interface {
|
||||
AcceptLegal(ctx context.Context, arg AcceptLegalParams) error
|
||||
AcceptedLegalVersions(ctx context.Context, userID uuid.UUID) ([]AcceptedLegalVersionsRow, error)
|
||||
AddAlertGroupChannel(ctx context.Context, arg AddAlertGroupChannelParams) (int64, error)
|
||||
AddIncidentUpdate(ctx context.Context, arg AddIncidentUpdateParams) (IncidentUpdate, error)
|
||||
AddMaintenanceTarget(ctx context.Context, arg AddMaintenanceTargetParams) error
|
||||
AddMembership(ctx context.Context, arg AddMembershipParams) error
|
||||
AddMonitorAlertGroup(ctx context.Context, arg AddMonitorAlertGroupParams) (int64, error)
|
||||
@@ -88,6 +89,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)
|
||||
DeleteIncidentUpdate(ctx context.Context, arg DeleteIncidentUpdateParams) (int64, error)
|
||||
DeleteInvitation(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteInvitationsForEmail(ctx context.Context, email string) error
|
||||
DeleteLegalDocument(ctx context.Context, arg DeleteLegalDocumentParams) error
|
||||
@@ -141,6 +143,7 @@ type Querier interface {
|
||||
GetEvidence(ctx context.Context, arg GetEvidenceParams) (CheckEvidence, error)
|
||||
GetGroup(ctx context.Context, id uuid.UUID) (MonitorGroup, error)
|
||||
GetIdentity(ctx context.Context, arg GetIdentityParams) (UserIdentity, error)
|
||||
GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow, error)
|
||||
GetInvitation(ctx context.Context, id uuid.UUID) (Invitation, error)
|
||||
GetInvitationByHash(ctx context.Context, tokenHash []byte) (GetInvitationByHashRow, error)
|
||||
GetMaintenance(ctx context.Context, id uuid.UUID) (MaintenanceWindow, error)
|
||||
@@ -202,6 +205,8 @@ 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)
|
||||
// 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
|
||||
// one monitor.
|
||||
ListIncidents(ctx context.Context, arg ListIncidentsParams) ([]ListIncidentsRow, error)
|
||||
@@ -267,10 +272,13 @@ type Querier interface {
|
||||
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
|
||||
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
|
||||
OrgIDBySlug(ctx context.Context, slug string) (uuid.UUID, error)
|
||||
OrgIncidentUpdatesExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentUpdatesExportRow, error)
|
||||
OrgIncidentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentsExportRow, error)
|
||||
OrgMembersExport(ctx context.Context, orgID uuid.UUID) ([]OrgMembersExportRow, error)
|
||||
// Organizations user owns, with their member and owner counts.
|
||||
OwnedOrgs(ctx context.Context, userID uuid.UUID) ([]OwnedOrgsRow, error)
|
||||
// The public updates of incidents shown on a status page, newest first.
|
||||
PublicIncidentUpdates(ctx context.Context, ids []uuid.UUID) ([]PublicIncidentUpdatesRow, error)
|
||||
// Resolved and long silent alerts are history the monitors' results keep.
|
||||
PurgeAlertmanagerAlerts(ctx context.Context, updatedAt time.Time) (int64, error)
|
||||
PurgeAuditEvents(ctx context.Context, argTime time.Time) (int64, error)
|
||||
@@ -290,6 +298,8 @@ type Querier interface {
|
||||
RangeBucketsDaily(ctx context.Context, arg RangeBucketsDailyParams) ([]RangeBucketsDailyRow, error)
|
||||
// The hourly aggregate rebucketed by width, for ranges of days.
|
||||
RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourlyParams) ([]RangeBucketsHourlyRow, error)
|
||||
// The incident shows the status of its latest update.
|
||||
RefreshIncidentStatus(ctx context.Context, id uuid.UUID) error
|
||||
// One monitor's raw results per region.
|
||||
RegionBuckets(ctx context.Context, arg RegionBucketsParams) ([]RegionBucketsRow, error)
|
||||
RegionBucketsDaily(ctx context.Context, arg RegionBucketsDailyParams) ([]RegionBucketsDailyRow, error)
|
||||
@@ -311,6 +321,7 @@ type Querier interface {
|
||||
ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error)
|
||||
ScrubAuditEmail(ctx context.Context, email string) error
|
||||
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
|
||||
SetIncidentTitle(ctx context.Context, arg SetIncidentTitleParams) (int64, error)
|
||||
SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error
|
||||
SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error)
|
||||
SetOwner(ctx context.Context, arg SetOwnerParams) (int64, error)
|
||||
|
||||
@@ -66,10 +66,14 @@ FROM role_assignments ra JOIN roles r ON r.id = ra.role_id
|
||||
WHERE ra.org_id = $1;
|
||||
|
||||
-- name: OrgIncidentsExport :many
|
||||
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause
|
||||
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause, i.title, i.status
|
||||
FROM incidents i LEFT JOIN monitors m ON m.id = i.monitor_id
|
||||
WHERE i.org_id = $1 ORDER BY i.started_at;
|
||||
|
||||
-- name: OrgIncidentUpdatesExport :many
|
||||
SELECT incident_id, status, message, public, created_at FROM incident_updates
|
||||
WHERE org_id = $1 ORDER BY created_at;
|
||||
|
||||
-- name: OrgAuditExport :many
|
||||
SELECT e.time, e.action, coalesce(u.email::text, '')::text AS actor, e.target_id, e.details, e.status,
|
||||
coalesce(host(e.ip), '')::text AS ip
|
||||
|
||||
@@ -96,3 +96,39 @@ LIMIT 50;
|
||||
-- Incidents overlapping the time since $1, for SLA calculation.
|
||||
SELECT monitor_id, started_at, resolved_at FROM incidents
|
||||
WHERE resolved_at IS NULL OR resolved_at > $1;
|
||||
|
||||
-- name: GetIncident :one
|
||||
SELECT i.*, 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;
|
||||
|
||||
-- name: SetIncidentTitle :execrows
|
||||
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)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteIncidentUpdate :execrows
|
||||
DELETE FROM incident_updates WHERE id = sqlc.arg(id) AND incident_id = sqlc.arg(incident_id);
|
||||
|
||||
-- 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
|
||||
ORDER BY u.created_at DESC, u.id DESC LIMIT 1
|
||||
) WHERE incidents.id = $1;
|
||||
|
||||
-- name: ListIncidentUpdates :many
|
||||
-- Newest first, with the author's name.
|
||||
SELECT u.*, 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;
|
||||
|
||||
-- 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
|
||||
WHERE incident_id = ANY(sqlc.arg(ids)::uuid[]) AND public
|
||||
ORDER BY created_at DESC, id DESC;
|
||||
Reference in new issue
Block a user