3.6 KiB
3.6 KiB
Proposal — Migrate @suaveplan/health-check to genesis
Why
@suaveplan/health-check is the server-tier orchestrator for /health, /ready, and /live endpoints with dependency checks. The upstream package at /mnt/s/web/suaveplan/packages/server/health-check/ predates the genesis enterprise gates: it uses the upstream EventEmitter shape, calls global Date.now()/setTimeout/fetch/node:net directly, has no error-code registry, no OTel self-telemetry, and no Zod boundary validation. This change re-lands the package at packages/observability/monitor/health-check/ (sibling to logger, audit-logging, opentelemetry) at full feature surface with the genesis contract.
What
Land @suaveplan/health-check@0.1.0 with the following feature modules (one per folder, 5-files-per-feature):
health-checker/—HealthCheckerorchestrator withEventBus<HealthEventMap>and injectableClock/TimersLike/LoggerLikehttp-check/—createHttpCheckfactory with injectablefetchImpl+Clocktcp-check/—createTcpCheckfactory with injectableTcpConnectFn+Clockresponse-builder/—ResponseBuildermappingCheckStatus→ HTTP status codeserror-codes/—HEALTH_CHECK_CODESviadefineCodes+ public-ctorHealthCheckErrortelemetry/— OTel meter (health_check_runs_total,health_check_aggregate_status_total,health_check_duration_ms)types/— sharedCheckResult/CheckFn/DependencyCheckConfig/HealthResponse/ReadinessResponse/LivenessResponse/HttpHealthResponse/HttpCheckConfig/TcpCheckConfig/HealthEvent/HealthEventMap
Source mapping
| Upstream file | Genesis file | Notes |
|---|---|---|
src/checker/health-checker.ts |
src/health-checker/health-checker.ts |
EventEmitter → EventBus<HealthEventMap>; Clock+TimersLike+LoggerLike injected; Zod-validated options; HealthCheckError on every failure |
src/checks/http-check.ts |
src/http-check/http-check.ts |
fetchImpl injection replaces global fetch; Zod options |
src/checks/tcp-check.ts |
src/tcp-check/tcp-check.ts |
TcpConnectFn injection replaces direct node:net.connect; settled-flag guards late events |
src/response/response-builder.ts |
src/response-builder/response-builder.ts |
Same algorithm, renamed file |
src/types/types.ts |
src/types/types.ts |
Adds HealthEventMap, TcpConnectFn/TcpSocketLike, HttpCheckConfig.fetchImpl, TcpCheckConfig.connectImpl |
src/index.ts |
src/index.ts |
Explicit named re-exports only |
| (none) | src/error-codes/error-codes.ts |
New — required by genesis rule |
| (none) | src/telemetry/telemetry.ts |
New — required by genesis rule |
Deviations from upstream
- Upstream uses
@suaveplan/events'EventEmitterwith variadic tuple payloads. Genesis@suaveplan/eventsexposesEventBus<TMap>with single-payloademit(type, payload).STATUS_CHANGEDtherefore emits{ previous, current }object instead of two positional args. Exposed asHealthChecker.events. - Upstream calls
Date.now()andsetTimeoutdirectly. Genesis injectsClock+TimersLikeper the universal-tier contract. - Upstream has no error-code registry. Genesis adds
HEALTH_CHECK_CODES+ public-ctorHealthCheckError. - Upstream HTTP / TCP checks depend on the runtime's global
fetchandnode:net. Genesis injects them so tests never touch real sockets. - Upstream emits no self-telemetry. Genesis adds a
telemetry/module emitting per-check counters + duration histogram + aggregate-status counter. - Boundary validation: every public option object is now Zod-validated; failures throw
HealthCheckError(INVALID_OPTIONS).