* 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.
66 lines
2.4 KiB
Go
66 lines
2.4 KiB
Go
// Alerts: the client half of the operator alert RPCs.
|
|
package staterpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
|
"github.com/samcharles93/archie-core/internal/domain/alert"
|
|
"github.com/samcharles93/archie-core/internal/domain/org"
|
|
)
|
|
|
|
var _ alert.Store = (*Client)(nil)
|
|
|
|
func (c *Client) RaiseAlert(ctx context.Context, in alert.Input) (alert.Alert, error) {
|
|
r, err := c.client.RaiseAlert(ctx, &pb.RaiseAlertRequest{
|
|
OrgId: string(in.Org), Kind: in.Kind, Subject: in.Subject, Severity: string(in.Severity),
|
|
Title: in.Title, Body: in.Body, Link: in.Link, Condition: in.Condition,
|
|
})
|
|
if err != nil {
|
|
return alert.Alert{}, unmapError(err)
|
|
}
|
|
return alertValue(r.GetAlert()), nil
|
|
}
|
|
|
|
func (c *Client) ResolveAlert(ctx context.Context, key alert.Key, _ string) error {
|
|
_, err := c.client.ResolveAlert(ctx, &pb.ResolveAlertRequest{OrgId: string(key.Org), Kind: key.Kind, Subject: key.Subject})
|
|
return unmapError(err)
|
|
}
|
|
|
|
func (c *Client) DismissAlert(ctx context.Context, orgID org.OrgID, id int64, _ string) error {
|
|
_, err := c.client.DismissAlert(ctx, &pb.DismissAlertRequest{OrgId: string(orgID), Id: id})
|
|
return unmapError(err)
|
|
}
|
|
|
|
func (c *Client) ListAlerts(ctx context.Context, orgID org.OrgID, filter alert.Filter) ([]alert.Alert, error) {
|
|
states := make([]string, len(filter.States))
|
|
for i, st := range filter.States {
|
|
states[i] = string(st)
|
|
}
|
|
r, err := c.client.ListAlerts(ctx, &pb.ListAlertsRequest{OrgId: string(orgID), States: states, Limit: int32(filter.Limit)})
|
|
if err != nil {
|
|
return nil, unmapError(err)
|
|
}
|
|
return mapValues(r.GetAlerts(), alertValue), nil
|
|
}
|
|
|
|
func (c *Client) ClaimAlertDeliveries(ctx context.Context, limit int) ([]alert.Due, error) {
|
|
r, err := c.client.ClaimAlertDeliveries(ctx, &pb.ClaimAlertDeliveriesRequest{Limit: int32(limit)})
|
|
if err != nil {
|
|
return nil, unmapError(err)
|
|
}
|
|
return mapValues(r.GetDue(), func(d *pb.DueAlertDelivery) alert.Due {
|
|
delivery := alertDeliveryValue(d.GetDelivery())
|
|
a := alertValue(d.GetAlert())
|
|
delivery.AlertID = a.ID
|
|
return alert.Due{Delivery: delivery, Alert: a, Attempt: d.GetAttempt()}
|
|
}), nil
|
|
}
|
|
|
|
func (c *Client) RecordAlertAttempt(ctx context.Context, o alert.Outcome) error {
|
|
_, err := c.client.RecordAlertAttempt(ctx, &pb.RecordAlertAttemptRequest{
|
|
DeliveryId: o.DeliveryID, Skipped: o.Skipped, StatusCode: int64(o.StatusCode), Error: o.Error,
|
|
})
|
|
return unmapError(err)
|
|
}
|