syntax = "proto3"; package state.v1; import "google/protobuf/timestamp.proto"; // Operator alerts (internal/domain/alert). A caller acting for a principal // reads, dismisses and raises only in that principal's org; a request org is // ignored for it. A service acting for no one names the org itself. // RaiseAlert and ResolveAlert are idempotent, so a periodic check can call // them every tick. ClaimAlertDeliveries and RecordAlertAttempt serve the // outbound webhook and refuse a caller scoped to an org. service AlertService { rpc RaiseAlert(RaiseAlertRequest) returns (RaiseAlertResponse); rpc ResolveAlert(ResolveAlertRequest) returns (ResolveAlertResponse); rpc DismissAlert(DismissAlertRequest) returns (DismissAlertResponse); rpc ListAlerts(ListAlertsRequest) returns (ListAlertsResponse); rpc ClaimAlertDeliveries(ClaimAlertDeliveriesRequest) returns (ClaimAlertDeliveriesResponse); rpc RecordAlertAttempt(RecordAlertAttemptRequest) returns (RecordAlertAttemptResponse); } // Alert mirrors internal/domain/alert.Alert. Severity is info, warning or // action; state is open, resolved or dismissed. message Alert { int64 id = 1; string org_id = 2; string kind = 3; string subject = 4; string severity = 5; string title = 6; string body = 7; string link = 8; bool condition = 9; string state = 10; google.protobuf.Timestamp first_raised = 11; google.protobuf.Timestamp last_seen = 12; int64 count = 13; string closed_by = 14; google.protobuf.Timestamp closed_at = 15; repeated AlertDelivery deliveries = 16; } // AlertDelivery is one outbound notice an alert owed. Event is raised or // resolved; state is pending, delivered, failed or skipped. message AlertDelivery { int64 id = 1; string event = 2; string state = 3; google.protobuf.Timestamp created_at = 4; repeated AlertAttempt attempts = 5; } message AlertAttempt { int64 n = 1; google.protobuf.Timestamp at = 2; int64 status_code = 3; string error = 4; } message RaiseAlertRequest { string org_id = 1; string kind = 2; string subject = 3; string severity = 4; string title = 5; string body = 6; string link = 7; // condition is true when the raiser resolves the alert itself once the // condition clears; an event alert stays until dismissed. bool condition = 8; } message RaiseAlertResponse { Alert alert = 1; } message ResolveAlertRequest { string org_id = 1; string kind = 2; string subject = 3; } message ResolveAlertResponse {} message DismissAlertRequest { string org_id = 1; int64 id = 2; } message DismissAlertResponse {} message ListAlertsRequest { string org_id = 1; // states defaults to open. repeated string states = 2; int32 limit = 3; } message ListAlertsResponse { repeated Alert alerts = 1; } message ClaimAlertDeliveriesRequest { int32 limit = 1; } message DueAlertDelivery { AlertDelivery delivery = 1; Alert alert = 2; // attempt is the number of this try, counting from one. int64 attempt = 3; } message ClaimAlertDeliveriesResponse { repeated DueAlertDelivery due = 1; } message RecordAlertAttemptRequest { int64 delivery_id = 1; bool skipped = 2; int64 status_code = 3; // error is empty on success. string error = 4; } message RecordAlertAttemptResponse {}