feat: /api/webhooks/health endpoint (v7)#543
Merged
greatest0fallt1me merged 1 commit intoJul 26, 2026
Merged
Conversation
Add a focused health probe endpoint for the webhook delivery subsystem. GET /api/webhooks/health probes the two runtime dependencies the webhook pipeline relies on: 1. database — Postgres (SELECT 1), where deliveries & subscriptions live 2. queue — Redis / BullMQ (PING), used by the webhook worker Implementation: - Injectable probe functions for full testability (no real I/O in tests) - Composite status: 'ok' (both pass) or 'down' (any fail) - HTTP 200 when ok, 503 when down - Correlation ID support via x-correlation-id header or auto-generated UUID - Structured pino logging with correlation ID, status, latencies - Error propagation to global errorHandler Tests (28 passing): - HTTP status codes: 200 all-ok, 503 db-down, 503 queue-down, 503 both-down - Response shape: status, correlationId, checkedAt, dependencies - Per-dependency latency and error fields - Correlation ID: header echo, UUID fallback, empty string handling - No authentication required - Error propagation: probeDatabase/probeQueue throws → 500 - Probe call count and parallel execution verification - Default router export validation - Edge cases: error messages, zero latency Closes Predictify-org#435
|
@Paranoa-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Merged via direct push to main (admin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #435
feat:
/api/webhooks/healthendpoint (v7)Summary
Add a focused health probe endpoint for the webhook delivery subsystem at
GET /api/webhooks/health.Motivation
The webhook delivery pipeline depends on two critical runtime dependencies: Postgres (where deliveries and subscriptions are stored) and Redis/BullMQ (the queue used by the webhook worker). While the existing
/api/health/dependenciesprobe covers all four system-wide dependencies, operators need a narrow, webhook-specific health check that isolates just the webhook subsystem's dependencies for targeted alerting and load-balancer routing.Implementation
New file:
src/routes/webhooks/health.tsGET /api/webhooks/healthcreateWebhooksHealthRouter(deps)with injectable probe functions for full testabilitydatabase— Postgres viapool.query("SELECT 1")queue— Redis viaredisConnection.ping()"ok"when both pass,"down"when either fails200when ok,503when downx-correlation-idheader; generates UUID v4 if absent/emptyerrorHandlermiddleware (returns 500)/healthz/dependencieswhich caches for 5s)Modified file:
src/index.tswebhooksHealthRouterfrom./routes/webhooks/healthapp.use("/api/webhooks/health", webhooksHealthRouter)(after/api/webhooks, before/api/users/health)Response shape
{ "status": "ok", "correlationId": "550e8400-e29b-41d4-a716-446655440000", "checkedAt": "2026-07-26T12:00:00.000Z", "dependencies": { "database": { "status": "ok", "latencyMs": 2 }, "queue": { "status": "ok", "latencyMs": 1 } } }When a dependency is down:
{ "status": "down", "correlationId": "...", "checkedAt": "...", "dependencies": { "database": { "status": "down", "latencyMs": 100, "error": "Database unavailable" }, "queue": { "status": "ok", "latencyMs": 1 } } }Tests
New file:
tests/webhooksHealth.test.ts— 28 tests, all passingTest strategy: Injectable probe functions replace all external I/O. No real Postgres or Redis connections. Router mounted on minimal Express app with
errorHandler.Existing test regression check
Ran
healthDependencies.test.tsandhealth.test.ts— both pass with no changes. ThehealthReady.test.tsfailure (Redis connection refused) is pre-existing and unrelated.Checklist