Skip to content

feat: /api/webhooks/health endpoint (v7)#543

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
Paranoa-dev:task/webhooks-health-v7
Jul 26, 2026
Merged

feat: /api/webhooks/health endpoint (v7)#543
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
Paranoa-dev:task/webhooks-health-v7

Conversation

@Paranoa-dev

@Paranoa-dev Paranoa-dev commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Closes #435


feat: /api/webhooks/health endpoint (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/dependencies probe 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.ts

  • Route: GET /api/webhooks/health
  • Pattern: Factory function createWebhooksHealthRouter(deps) with injectable probe functions for full testability
  • Dependencies probed:
    1. database — Postgres via pool.query("SELECT 1")
    2. queue — Redis via redisConnection.ping()
  • Composite status: "ok" when both pass, "down" when either fails
  • HTTP status: 200 when ok, 503 when down
  • Correlation ID: Accepts x-correlation-id header; generates UUID v4 if absent/empty
  • Logging: Structured pino logs with correlation ID, status, per-dependency status, and elapsed time
  • Error handling: Unexpected errors propagate to the global errorHandler middleware (returns 500)
  • No caching: Fresh probe on every call (unlike /healthz/dependencies which caches for 5s)
  • No auth: Returns no sensitive data; restrict at infrastructure level in production

Modified file: src/index.ts

  • Import webhooksHealthRouter from ./routes/webhooks/health
  • Mount at app.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 passing

Category Tests Coverage
HTTP status codes 4 200 all-ok, 503 db-down, 503 queue-down, 503 both-down
Response body — status field 3 Composite status mapping verification
Response shape 7 Top-level fields, dependency entries, latencies, error fields
Correlation ID 4 Header echo, UUID fallback, empty string, uniqueness
Authentication 2 No auth required, ignores Authorization header
Error handling 4 Probe throws → 500, call count verification, parallel execution
Default router 1 Export validation
Edge cases 3 Error messages, zero latency

Test 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.ts and health.test.ts — both pass with no changes. The healthReady.test.ts failure (Redis connection refused) is pre-existing and unrelated.

Checklist

  • Implementation matches the description
  • Tests added and passing (28/28)
  • Lint passing (eslint, no errors)
  • Input validation at boundary (correlation ID handling)
  • Structured logging with correlation IDs
  • No sensitive data exposed
  • Injectable dependencies for testability
  • Documentation and inline comments
  • No breaking changes to existing routes

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
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Merged via direct push to main (admin)

@greatest0fallt1me
greatest0fallt1me merged commit e321baa into Predictify-org:main Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add /api/webhooks/health probe (v7)

2 participants