feat(backend): expand health checks with liveness, readiness, dependency probes (#353) - #460
Open
prissca wants to merge 1 commit into
Open
Conversation
…ncy probes (Epta-Node#353) - GET /health/live: alias for GET /health's process-only liveness check (same handler, matches the issue's requested route name). - GET /health/ready: extended from checking only the tasks/payments DBs to also checking the job queue DB, the Venice AI and Stellar Horizon providers, and (if attached) the WebSocket stream server — {tasks, payments, queue, venice, horizon, websocket}. Fails (500) when any dependency is down. The one exception: a WebSocket probe that was never registered reports "unknown" (a valid configuration — the stream layer may simply not be attached, per the existing convention in services/metrics.ts) and does not by itself fail readiness; a probe that *is* attached and reports not-listening does fail it, same as every other dependency. - MetricsService.getWebSocketStatus(): a small new public method exposing the existing (private) checkWebSocket() probe, so /health/ready can read live WebSocket status without a full dashboard collection. - New HEALTH_PROBE_TIMEOUT_MS config field (default 5000ms) — the configurable threshold the issue asks for, used by both /health/deep's and /health/ready's provider timeouts (previously hardcoded to 5000). ## Necessary prerequisite: several backend files were corrupted by a bad merge package.json, jest.config.js, tsconfig.json, config/index.ts, api/app.ts, api/routes/stream.ts, api/routes/agents.ts, and api/routes/stats.ts each contained two full, conflicting versions of their own content concatenated together — duplicate imports/declarations, or (for the *.ts route files) an entire stale stub implementation glued in front of the real one. This blocked `npm install`/`npm test` entirely. Same root cause and fix pattern already documented in Epta-Node#443 (Obiajulu-gif's Epta-Node#359 PR, a different fork of this repo hitting the identical corruption in package.json/jest.config.js/tsconfig.json/api/app.ts): in each file, kept the newer half whose imports/exports/fields actually match what the rest of the codebase references (e.g. agents.ts's real createAgentsRouter() uses the DB-backed AgentDb, not the old in-memory stub; stats.ts's real createStatsRouter() uses the DB-backed StatsCache), discarded the stale duplicate, and added two things that were missing outright: stream.ts's activeStreamServers Set + getStreamConnectionCount() export (referenced by api/app.ts but never defined), and agents.ts's RegisterAgentSchema (referenced by the register route, mirroring the RegisterAgentRequest schema already documented in api/docs.ts). This PR's app.ts fix is the minimal corruption fix only — it does not include the close()/job-worker-drain changes from the related Epta-Node#349 PR, to keep this diff scoped to health checks. Full backend test suite: 46/51 suites passing after these fixes (up from 5 suites failing to even compile before them). The remaining 5 failing suites (tests/tasks.test.ts, api/routes/agents.test.ts, registry/sync.test.ts, api/middleware/versioning.test.ts, cache/cache.test.ts) fail for reasons unrelated to health checks — error-response-shape mismatches, a `@stellar/stellar-sdk/rpc` module resolution issue, and fake-timer flakiness — pre-existing and out of scope here. ## Acceptance Criteria - [x] Readiness fails when DB or provider is unavailable - [x] Payload lists each dependency with status ## Test plan npx jest src/api/routes/health.test.ts — 30/30 passing, including 6 new /health/ready tests (all six dependency keys present, Venice/Horizon failure fails readiness, websocket "unknown" doesn't fail readiness on its own, websocket "unreachable" does) and 1 new /health/live test. Closes Epta-Node#353
|
@prissca 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! 🚀 |
|
@Obiajulu-gif is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
Open
2 tasks
2 tasks
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.
Summary
GET /health/live: alias forGET /health's process-only liveness check (same handler, matches the issue's requested route name).GET /health/ready: extended from checking only the tasks/payments DBs to also check the job queue DB, the Venice AI and Stellar Horizon providers, and (if attached) the WebSocket stream server —{tasks, payments, queue, venice, horizon, websocket}. Fails (500) when any dependency is down. The one exception: a WebSocket probe that was never registered reports"unknown"(a valid configuration — the stream layer may simply not be attached, per the existing convention inservices/metrics.ts) and does not by itself fail readiness; a probe that is attached and reports not-listening does fail it, same as every other dependency.MetricsService.getWebSocketStatus(): a small new public method exposing the existing (private)checkWebSocket()probe, so/health/readycan read live WebSocket status without a full dashboard collection.HEALTH_PROBE_TIMEOUT_MSconfig field (default 5000ms) — the configurable threshold the issue asks for, used by both/health/deep's and/health/ready's provider timeouts (previously hardcoded to 5000).Necessary prerequisite: several backend files were corrupted by a bad merge
package.json,jest.config.js,tsconfig.json,config/index.ts,api/app.ts,api/routes/stream.ts,api/routes/agents.ts, andapi/routes/stats.tseach contained two full, conflicting versions of their own content concatenated together — duplicate imports/declarations, or (for the route files) an entire stale stub implementation glued in front of the real one. This blockednpm install/npm testentirely.Same root cause and fix pattern already documented in Epta-Node/ai-net#443 (a different fork of this repo hitting the identical corruption in
package.json/jest.config.js/tsconfig.json/api/app.tsfor issue #359): in each file, kept the newer half whose imports/exports/fields actually match what the rest of the codebase references (e.g.agents.ts's realcreateAgentsRouter()uses the DB-backedAgentDb, not the old in-memory stub;stats.ts's realcreateStatsRouter()uses the DB-backedStatsCache), discarded the stale duplicate, and restored two things that were missing outright:stream.ts'sactiveStreamServersSet +getStreamConnectionCount()export (referenced byapi/app.tsbut never defined), andagents.ts'sRegisterAgentSchema(referenced by the register route, mirroring theRegisterAgentRequestschema already documented inapi/docs.ts).This PR's
app.tsfix is the minimal corruption fix only — it does not include theclose()/job-worker-drain changes from the related #349 work, to keep this diff scoped to health checks.Full backend test suite: 46/51 suites passing after these fixes (up from 5 suites failing to even compile before them). The remaining 5 failing suites (
tests/tasks.test.ts,api/routes/agents.test.ts,registry/sync.test.ts,api/middleware/versioning.test.ts,cache/cache.test.ts) fail for reasons unrelated to health checks — error-response-shape mismatches, a@stellar/stellar-sdk/rpcmodule resolution issue, and fake-timer flakiness — pre-existing and out of scope here.Acceptance Criteria
Test plan
npx jest src/api/routes/health.test.ts— 30/30 passing, including 6 new/health/readytests (all six dependency keys present, Venice/Horizon failure fails readiness, websocket "unknown" doesn't fail readiness on its own, websocket "unreachable" does) and 1 new/health/livetest.Closes #353