Skip to content

Add health check endpoint that reports database connectivity and Stellar network status #32

Description

@Cjay-Cyber-2

Description

Implement a GET /health endpoint that returns the overall health of the API, including database connectivity (Prisma) and Stellar Horizon network status. This is crucial for monitoring and deployment (e.g., Kubernetes liveness probes). The endpoint should be fast, lightweight, and not require authentication. It should attempt a simple query to the database (e.g., SELECT 1 via Prisma) and a ping to Horizon, then return a JSON response with status 'ok' or 'degraded'.

Context & Requirements

  • The API is deployed as a public service; a health check endpoint is standard for operational readiness.
  • The endpoint must be accessible without authentication (open to all).
  • Database check: use prisma.$queryRawUnsafe('SELECT 1') to verify the connection is alive.
  • Stellar check: call HorizonServer.loadAccount('G...') with a known public key (e.g., the testnet friendbot address) or use a simple ping to Horizon server (e.g., GET / on the Horizon server). Use the existing stellarService or a direct Axios/fetch.
  • Response format: { status: 'ok', database: { connected: true }, stellar: { reachable: true, network: 'testnet' }, timestamp: '...' }.
  • If either check fails, return HTTP 503 with status 'degraded' and details.
  • Timeout for each check: 5 seconds (to avoid hanging).

Acceptance Criteria

  • GET /health returns 200 with status 'ok' when both DB and Stellar are reachable.
  • Returns 503 with status 'degraded' if DB or Stellar is unreachable.
  • Response includes individual component statuses.
  • No authentication required.
  • Timeout of 5 seconds per check.
  • Tests exist that mock failures and verify correct HTTP status and response body.

Implementation Guidance

  • File: src/routes/health.ts – create a new route file.
  • Register the route in src/index.ts (likely with app.register(import('./routes/health'))).
  • Use prisma.$queryRawUnsafe('SELECT 1') for DB check.
  • For Stellar check, use fetch('https://horizon-testnet.stellar.org/') (get the base URL from config).
  • Use Promise.allSettled to run both checks concurrently; if any fails, overall status is 'degraded'.
  • Set timeout with AbortController or Promise.race with a timeout.
  • Return appropriate HTTP status code based on overall health.

Testing & Validation

  • Write unit tests for the health check function (mock Prisma and fetch).
  • Integration tests: call the endpoint and verify response structure.
  • Test with simulated DB failure (mock reject) and verify 503.
  • Run npm test.

Submission Guidelines

  • Branch from main with name feat/health-check.
  • PR includes new route file and registration.
  • Closes #.
  • Assign yourself before starting.

Wave complexity: Trivial (100 points)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programcomplexity: trivialDrips Wave — small, well-bounded taskdrips-waveTracked in a Drips Wave programenhancementNew feature or requestops

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions