feat(api): add queue_health monitoring endpoint
Merged
RI
3mo ago+792+792+012345678901234567890123456789-50-50-01234567890123456789
Summary (AI generated)
- Added
GET /queue_healthto audit every pgmq queue and return200/okor503/ko, matching the/replicationmonitoring pattern. - Health criteria cover unread stale messages (
read_ct=0past cron-derived threshold), stuck retries (read_ct > 5), queue depth, stale archives (>2 days), recent archive ramp-up, and missing queue/archive tables. - Response includes thresholds, human-readable healthy/unhealthy criteria, per-queue metrics, reasons, and reason details for each failure.
- Wired through Supabase function
queue_health, Cloudflare API route, and unit tests for evaluation helpers.
Motivation (AI generated)
Operators need a single monitorable endpoint that proves queues are being consumed and archives are not silently growing. Without this, stuck unread work and archive ramp-up are hard to catch before they impact processing latency or database size.
Business Impact (AI generated)
Faster detection of queue consumer failures reduces update/webhook/cron processing delays and avoids archive/storage growth incidents that can pressure production Postgres.
Test Plan (AI generated)
- Unit tests for queue health criteria and cron interval derivation (
tests/queue-health.unit.test.ts) - Call
GET /queue_healthwithapisecretagainst a healthy environment and expect HTTP 200 +status: "ok" - Seed a stale unread message / stuck
read_ct/ old archive row and expect HTTP 503 with matchingreasonsandreason_details - Confirm non-admin JWT gets 403 and missing auth gets 401
Generated with AI


Summary by CodeRabbit
-
New Features
- Added a new
GET /queue_healthendpoint for authorized administrators to check the health of message queues. - Returns an overall status summary (healthy vs. unhealthy) with per-queue findings across backlog, unread staleness, stuck reads, and archive delays.
- Includes configurable access behavior to reach the endpoint without JWT verification.
- Added a new
-
Tests
- Added unit tests covering queue name validation, schedule/interval parsing, threshold handling, and health evaluation scenarios.