feat(api): add queue_health monitoring endpoint - #2756
Conversation
Expose GET /queue_health that audits every pgmq queue for unread stale messages, stuck retries, backlog depth, and archive ramp-up, returning 503 with per-queue reasons when unhealthy (same pattern as /replication). Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 36 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds queue health computation for PGMQ queues, including cron-aware thresholds, metrics, authorization, JSON reporting, Supabase Edge Function wiring, and a Cloudflare ChangesQueue health monitoring
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant CloudflareAPI
participant QueueHealthApp
participant AdminRPC
participant Postgres
Caller->>CloudflareAPI: GET /queue_health
CloudflareAPI->>QueueHealthApp: Route request
QueueHealthApp->>AdminRPC: Check is_platform_admin
AdminRPC-->>QueueHealthApp: Authorization result
QueueHealthApp->>Postgres: Load queues, schedules, and queue metrics
Postgres-->>QueueHealthApp: Queue data and metrics
QueueHealthApp-->>CloudflareAPI: JSON health report
CloudflareAPI-->>Caller: HTTP response
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_42d13ce5-b35c-4ef3-873d-71235f2605b4) |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
supabase/config.toml (1)
443-449: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winRemove the duplicate
[functions.queue_health]table
supabase/config.tomldefines[functions.queue_health]twice. TOML treats duplicate table headers as invalid, so this should be left as a single entry and the duplicate block removed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@supabase/config.toml` around lines 443 - 449, Remove the duplicate [functions.queue_health] table from supabase/config.toml, keeping one definition with its existing verify_jwt and import_map settings unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@supabase/functions/_backend/public/queue_health.ts`:
- Around line 390-454: Reduce repeated database load in the queue health
aggregation around the queue and archive count queries by adding a short-TTL
cache or equivalent sampling strategy for health results, while preserving
current values and threshold behavior. Ensure queue enumeration is bounded or
paged if the registered queue count can grow without limit, and apply the same
protection to both the queue scan and archive scan paths.
- Around line 499-501: Update the overall status calculation near unhealthy and
overallStatus so an empty queues list is not classified as unhealthy or returned
as a 503; preserve the existing failure behavior when unhealthy queues exist,
and represent the no-queues condition with a distinct status or reason using the
surrounding queue health response flow.
In `@tests/queue-health.unit.test.ts`:
- Around line 102-165: Add a dedicated test within the evaluateQueueHealth suite
for the queue_depth_exceeded branch by providing metrics with queue_count
greater than thresholds.queue_depth_threshold. Assert the result is unhealthy,
includes queue_depth_exceeded in reasons, and verifies the corresponding reason
detail if the existing branch exposes one.
---
Outside diff comments:
In `@supabase/config.toml`:
- Around line 443-449: Remove the duplicate [functions.queue_health] table from
supabase/config.toml, keeping one definition with its existing verify_jwt and
import_map settings unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5ca9e34b-dd15-4246-9801-d6f700edbc2b
📒 Files selected for processing (5)
cloudflare_workers/api/index.tssupabase/config.tomlsupabase/functions/_backend/public/queue_health.tssupabase/functions/queue_health/index.tstests/queue-health.unit.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
Treat an empty pgmq registry as healthy with no_queues_registered, and add unit coverage for the queue_depth_exceeded criterion. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_cc9cc345-4cf6-4af2-b6ee-076560673101) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped; usage limit reached), so the required automated review signal is unavailable. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_ea75370e-9112-4dd6-981e-2ea66e8b230b) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped; usage limit reached), so the required automated review signal is unavailable. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped; usage limit reached), and this new admin monitoring endpoint exceeds the low-risk approval threshold. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
Extract shared validatePlatformAdminOrApiSecret used by /replication and /queue_health to clear SonarCloud duplicated-lines gate, and alias SQL count union types. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_04ea234f-3139-4d0c-bb21-943d9f49770b) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped; usage limit reached), and this new admin monitoring endpoint exceeds the low-risk approval threshold. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped; usage limit reached), so the required automated review signal is unavailable. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver
Validate queue names inside fetchQueueMetrics, honor weekly/monthly cron cadence markers, give archive cleanup a 1-day grace window, and mark unknown registration state as null on error responses. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_0bae6f48-23a9-4fe0-a9d4-060542d2bfdc) |
There was a problem hiding this comment.
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped; usage limit reached), and this new admin monitoring endpoint exceeds the low-risk approval threshold. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Risk: medium. Not approving: Cursor Bugbot did not complete successfully (check skipped; usage limit reached), so the required automated review signal is unavailable. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.
Sent by Cursor Approval Agent: Pull Request Approver
|





Summary (AI generated)
GET /queue_healthto audit every pgmq queue and return200/okor503/ko, matching the/replicationmonitoring pattern.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.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)
tests/queue-health.unit.test.ts)GET /queue_healthwithapisecretagainst a healthy environment and expect HTTP 200 +status: "ok"read_ct/ old archive row and expect HTTP 503 with matchingreasonsandreason_detailsGenerated with AI
Summary by CodeRabbit
New Features
GET /queue_healthendpoint for authorized administrators to check the health of message queues.Tests