Skip to content

Public health check endpoint and /status page - #1174

Open
Klakurka wants to merge 2 commits into
masterfrom
ccr-b62297cf-awgd35-health-checks
Open

Klakurka wants to merge 2 commits into
masterfrom
ccr-b62297cf-awgd35-health-checks

Conversation

@Klakurka

@Klakurka Klakurka commented Dec 3, 2026

Copy link
Copy Markdown
Member

Related to #1063
Related to #769

Description

Adds a public, unauthenticated health check that an uptime monitor such as StatusCake can watch, plus a public /status page that shows the same information.

GET /api/health (also HEAD; reachable as /health too through the existing rewrite) answers 200 when every check passes and 503 when any fails, with a JSON breakdown:

  • database: SELECT 1
  • redis: PING
  • per network (ecash, bitcoincash):
    • chronik: the indexer answers blockchainInfo (one call, no retries); reports tipHeight
    • websocket: the chronik WebSocket that delivers new txs is open
    • ingestion: chronik's tip is at most one block ahead of the newest block delivered over that WebSocket (blocksBehind). This catches the server being up but no longer pulling in new txs (Have the server be able to recover automatically when it's "up" but can't pull in new txs #812). The baseline is set from chronik's tip on the first check after each WS (re)connect, so blocks missed while the WS was down don't keep it failing after a reconnect.

Each check times out after 3s, so a hung dependency can't hang the endpoint (Redis is configured with maxRetriesPerRequest: null and would otherwise queue forever). Results are cached in memory for 10s, and concurrent callers share one run, so frequent polling is cheap. Error details are reduced to timeout / unavailable, with the real error logged server-side, so connection strings and hostnames don't leak. Networks listed in networksUnderMaintenance are skipped and count as healthy. The response has Cache-Control: no-store.

/status (#769) is a small public page, viewable logged in or not, that polls /api/health every 30s and lists Database / Cache / each network as Operational, Outage or Maintenance, with a short reason.

The endpoint is documented in the README under "Health checks and monitoring".

Code changes:

  • services/healthService.ts: checks, timeouts, cache
  • pages/api/health/index.ts: route
  • ChronikBlockchainClient.getHealth() / isWsConnected(), and MultiBlockchainClient.getChronikHealth(). The client now tracks the newest WS block height.
  • utils/timeout.ts: withTimeout helper
  • components/Status, pages/status, and /status added to the public URLs in _app.tsx
  • ping() added to the mocked Redis client used in tests

Test plan

  • make github-test-unit: 20 suites / 424 tests pass.
  • New tests/unittests/healthService.test.ts covers:
    • all healthy gives 200
    • DB failure gives 503, and the error text doesn't leak
    • a Redis hang times out
    • one network's chronik unreachable
    • WS disconnected
    • WS connected but 5 blocks behind
    • one block behind is tolerated
    • maintenance networks are skipped
    • cache reuse, expiry and in-flight sharing
    • the route's status codes and methods
  • New cases in chronikService.test.ts:
    • getHealth reports the tip and WS state
    • the baseline is set on the first check and then follows block messages
    • the baseline resets on WS reconnect
    • a chronik call that never answers times out
    • getHealth fails cleanly while the client isn't initialized
  • ESLint is clean on the changed files. tsc --noEmit reports no new errors in the changed files.
  • Manual check suggested: hit /api/health on staging, stop Redis or block a chronik host, and confirm a 503 with the matching check failing. Open /status logged out.

Remarks

  • Set the StatusCake test to watch https://<host>/api/health and alert on non-2xx.
  • The check runs in the web process, so it reflects that process's chronik subscription (the one that handles mempool txs and triggers). The jobs process isn't covered yet. Its sync progress is still on the admin Sync Status panel, and checking it could be a follow-up.
  • This only detects a stalled WS. It doesn't restart anything. Recovering automatically (Have the server be able to recover automatically when it's "up" but can't pull in new txs #812) would be a separate change, e.g. forcing a WS reconnect when ingestion goes stale.
  • On networks with long gaps between blocks, the ingestion check can't spot a dead WS until chronik's tip has moved two blocks past the last one received. That keeps false alarms away, at the cost of roughly 10–20 minutes of detection latency.

Generated by Claude Code

Add GET/HEAD /api/health, an unauthenticated endpoint for uptime monitors
(e.g. StatusCake). It answers 200 when every check passes and 503 otherwise,
with a per-dependency JSON breakdown:

- database (SELECT 1) and redis (PING)
- per network: chronik reachability (blockchainInfo), chronik WebSocket open,
  and ingestion freshness: chronik's tip must not be more than one block
  ahead of the newest block delivered over the WebSocket, which catches the
  server being up but no longer receiving new txs

Each check times out after 3s, results are cached for 10s with concurrent
callers sharing one run, and errors are reduced to "timeout"/"unavailable"
so nothing internal leaks. Networks under maintenance are skipped.

Also add a public /status page that shows the same report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019G564i2sNiHJYQR95m8zGq
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2003f583-9945-425d-b8af-06f664fc49af
Commits

Reviewing files that changed from the base of the PR and between f9d06f2 and 943802d.

Files selected for processing: 12

  • README.md
  • components/Status/index.tsx
  • components/Status/status.module.css
  • pages/_app.tsx
  • pages/api/health/index.ts
  • pages/status/index.tsx
  • redis/clientInstance.ts
  • services/chronikService.ts
  • services/healthService.ts
  • tests/unittests/chronikService.test.ts
  • tests/unittests/healthService.test.ts
  • utils/timeout.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…ighbouring code

Move the timeout import, the WS ready-state constant and the ChronikHealth
type so they don't touch the same lines as the chronik-down changes, and
reset the WS block height after the connection bookkeeping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019G564i2sNiHJYQR95m8zGq

This branch has not been deployed

No deployments
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.

2 participants