ingest.proto 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. syntax = "proto3";
  2. package broadannounce.v1;
  3. option go_package = "git3.techno-world.net/lrosales/broad-announce/gen/go/broadannounce/v1;broadannouncev1";
  4. // Ingest is the gRPC service for first-party, high-volume alert sources.
  5. // It runs on a dedicated port (default :9090) inside the tenant's VPC;
  6. // external webhook sources continue to use HTTP POST on :8800.
  7. service Ingest {
  8. // StreamAlerts is a bidirectional stream: the client sends zero or more
  9. // Alerts, the server sends exactly one Ack for each Alert received.
  10. //
  11. // Flow:
  12. // 1. Client opens stream (auth metadata required on the call)
  13. // 2. Client streams Alerts; server processes each concurrently
  14. // 3. Server streams back Acks as they are ready (order not guaranteed)
  15. // 4. Client reads Acks and adjusts send rate accordingly
  16. //
  17. // Backpressure: if the server's in-flight buffer (256 msgs) fills up,
  18. // it sends Error.RATE_LIMITED with retry_after_ms > 0. The client MUST
  19. // honour that delay before resuming.
  20. rpc StreamAlerts(stream Alert) returns (stream Ack);
  21. }
  22. // Alert is what a first-party service sends to BroadAnnounce.
  23. message Alert {
  24. string company_id = 1; // required; maps to sources.company_id
  25. string source_id = 2; // required; maps to sources.source_id
  26. string severity = 3; // "info" | "warning" | "critical" | "inminent_colapse"
  27. string category = 4; // arbitrary category tag
  28. string title = 5; // pre-localized alert title
  29. string body = 6; // pre-localized alert body
  30. map<string, string> data = 7; // arbitrary key-value metadata
  31. string dedupe_key = 8; // opaque string; if set, dedupe applies within the window
  32. int64 client_ts_ms = 9; // Unix-ms timestamp set by the client; used for skew detection
  33. }
  34. // Ack is what the server sends back after processing an Alert.
  35. message Ack {
  36. // alert_id is an opaque server-assigned identifier for the alert.
  37. // It may be empty if the alert was rejected before NATS publish.
  38. string alert_id = 1;
  39. // dedupe_key echoes back the client's dedupe_key.
  40. string dedupe_key = 2;
  41. // dedupe_count is 1 on first arrival; >1 when the server collapsed a
  42. // burst of identical dedupe_keys within the dedupe window.
  43. uint32 dedupe_count = 3;
  44. // accepted_at_ms is the server-side Unix-ms timestamp at which the alert
  45. // was accepted (i.e. after all protection layers passed).
  46. int64 accepted_at_ms = 4;
  47. // result is the processing outcome.
  48. oneof result {
  49. Ok ok = 10; // alert accepted
  50. Error error = 11; // alert rejected or rate-limited
  51. }
  52. }
  53. // Ok is returned when an Alert was accepted.
  54. message Ok {}
  55. // Error is returned when an Alert was rejected.
  56. message Error {
  57. // Code classifies the error so the client can act programmatically.
  58. enum Code {
  59. UNKNOWN = 0; // catch-all; include message
  60. UNAUTHENTICATED = 1; // API key missing or invalid
  61. RATE_LIMITED = 2; // per-source or per-company rate limit hit
  62. INVALID = 3; // schema validation failed;修复 check message
  63. INTERNAL = 4; // server-side error; do not retry immediately
  64. }
  65. Code code = 1;
  66. string message = 2; // human-readable; never parse this
  67. // retry_after_ms is non-zero when Code == RATE_LIMITED.
  68. // The client MUST wait at least this long before sending the next message.
  69. // A value of 0 means "do not retry" (permanent failure).
  70. int32 retry_after_ms = 3;
  71. }