Add Config struct and NewHandlerWithConfig(logger, cfg, checks...) constructor. Config.CheckTimeout sets the per-request deadline for all health checks; zero value defaults to 5 seconds. NewHandler remains unchanged as a backward-compatible wrapper. API committed as stable.
3.5 KiB
3.5 KiB
Changelog
All notable changes to this module will be documented in this file.
The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.
1.0.0 — 2026-05-12
Added
Configstruct —CheckTimeout time.Duration; zero value defaults to 5 seconds.NewHandlerWithConfig(logger Logger, cfg Config, checks ...Checkable) http.Handler— constructor with explicit configuration.NewHandleris now a backward-compatible wrapper that callsNewHandlerWithConfigwith zeroConfig.
Unchanged
All existing API (Level, LevelCritical, LevelDegraded, Checkable, Logger,
ComponentStatus, Response, NewHandler) is API-compatible with v0.9.0.
0.9.0 - 2026-03-18
Added
Leveltype —intrepresenting component criticality; zero value isLevelCriticalLevelCriticalconstant (value0) — a failing critical component sets overall status toDOWNand returns HTTP 503LevelDegradedconstant (value1) — a failing degraded component sets overall status toDEGRADEDand returns HTTP 200Checkableinterface —HealthCheck(ctx context.Context) error,Name() string,Priority() Level; implemented by infrastructure componentsLoggerinterface — duck-typed minimal logger (Debug,Info,Warn,Error,WithContext) satisfied bylogz.Loggerwithout importing logzComponentStatusstruct — JSON-serialisable per-component result with fieldsstatus string,latency string(omitempty), anderror string(omitempty)Responsestruct — JSON-serialisable overall response with fieldsstatus stringandcomponents map[string]ComponentStatusNewHandler(logger Logger, checks ...Checkable) http.Handler— constructs anhttp.Handlerthat runs all registered checks concurrently, collects results via a buffered channel, and writes a JSONResponse- Parallel check execution: each
Checkable.HealthCheckcall runs in its own goroutine; a buffered channel sized to the check count prevents goroutine leaks - Per-request 5-second deadline derived from
context.WithTimeout(r.Context(), 5*time.Second)and propagated to all check goroutines - Overall status aggregation:
UPif all checks pass;DEGRADED(HTTP 200) if at least one degraded component fails and no critical component fails;DOWN(HTTP 503) if any critical component fails - Check latency measurement: each goroutine records
time.Since(start)and includes it as a string inComponentStatus Content-Type: application/jsonresponse header set on every response
Design Notes
- All checks run in parallel goroutines and report through a buffered channel; the buffer is sized exactly to the number of registered checks at construction time, so the handler is guaranteed to drain all results without blocking even if it returns early.
- The two-level criticality model (
LevelCritical/LevelDegraded) gives orchestrators and load balancers a clean binary HTTP signal (200 vs 503) while still surfacing partial degradation in the JSON body for monitoring systems. - The
LoggerandCheckableinterfaces are defined entirely within this package using duck typing — no micro-lib module is imported, keepinghealtha pure stdlib package (Tier 0/1) that infra packages can satisfy without a circular dependency.