* feat(state): durable operator alerts owned by the State Store Alerts dedup on org+kind+subject, resolve themselves when a condition clears, and are raised, resolved, dismissed and listed through the state contract. Task transitions raise needs-human and failed alerts in the same transaction; the store checks service health and prunes closed alerts. Each raise and resolve queues a webhook delivery whose attempts are kept. * feat(notify): deliver operator alerts to the webhook; raise config and release alerts notify.webhook now receives raised and resolved alerts above a severity threshold with HMAC-signed payloads, bounded retry and every attempt recorded on the alert. archied raises model alias, provider and credential-binding alerts from the effective configuration, an update alert from the release channel, and a credential-rejected alert from the egress resolver. The dashboard API lists and dismisses the caller's org's alerts. * feat(ui): alert bell in the top bar and webhook alert settings The bell lists the org's open alerts by severity with dismiss and a link per alert, and refreshes from the event stream. The task settings page gains the webhook severity threshold and signing secret. ui/dist rebuilt.
57 lines
2.4 KiB
SQL
57 lines
2.4 KiB
SQL
-- Operator alerts: things that need a human, one row per (org, kind, subject).
|
|
-- Raising an open alert again bumps the row instead of adding one. A
|
|
-- condition-backed alert resolves when its condition clears; an event alert
|
|
-- stays until dismissed. Deliveries are the outbound notices (the notify
|
|
-- webhook) each raise or resolve owes, with every attempt kept.
|
|
|
|
-- +goose Up
|
|
|
|
CREATE TABLE alerts (
|
|
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
kind text NOT NULL,
|
|
subject text NOT NULL,
|
|
severity text NOT NULL CHECK (severity IN ('info', 'warning', 'action')),
|
|
title text NOT NULL,
|
|
body text NOT NULL DEFAULT '',
|
|
link text NOT NULL DEFAULT '',
|
|
is_condition boolean NOT NULL,
|
|
state text NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'resolved', 'dismissed')),
|
|
first_raised timestamptz NOT NULL,
|
|
last_seen timestamptz NOT NULL,
|
|
count bigint NOT NULL DEFAULT 1,
|
|
closed_by text NOT NULL DEFAULT '',
|
|
closed_at timestamptz,
|
|
UNIQUE (org_id, kind, subject)
|
|
);
|
|
CREATE INDEX idx_alerts_org_state ON alerts (org_id, state, id);
|
|
CREATE INDEX idx_alerts_closed ON alerts (closed_at) WHERE state <> 'open';
|
|
|
|
CREATE TABLE alert_deliveries (
|
|
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
alert_id bigint NOT NULL REFERENCES alerts (id) ON DELETE CASCADE,
|
|
event text NOT NULL CHECK (event IN ('raised', 'resolved')),
|
|
state text NOT NULL DEFAULT 'pending' CHECK (state IN ('pending', 'delivered', 'failed', 'skipped')),
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
next_attempt_at timestamptz NOT NULL DEFAULT now(),
|
|
attempts bigint NOT NULL DEFAULT 0
|
|
);
|
|
CREATE INDEX idx_alert_deliveries_due ON alert_deliveries (next_attempt_at) WHERE state = 'pending';
|
|
CREATE INDEX idx_alert_deliveries_alert ON alert_deliveries (alert_id, id);
|
|
|
|
CREATE TABLE alert_delivery_attempts (
|
|
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
delivery_id bigint NOT NULL REFERENCES alert_deliveries (id) ON DELETE CASCADE,
|
|
attempt bigint NOT NULL,
|
|
at timestamptz NOT NULL DEFAULT now(),
|
|
status_code bigint NOT NULL DEFAULT 0,
|
|
error text NOT NULL DEFAULT ''
|
|
);
|
|
CREATE INDEX idx_alert_delivery_attempts_delivery ON alert_delivery_attempts (delivery_id, id);
|
|
|
|
-- +goose Down
|
|
|
|
DROP TABLE alert_delivery_attempts;
|
|
DROP TABLE alert_deliveries;
|
|
DROP TABLE alerts;
|