Module: Wurk::Health
- Defined in:
- lib/wurk/health.rb
Overview
Thin HTTP listener for k8s liveness/readiness probes. Optional, off by
default — opt in with config.health_check(port: 7433) or
WURK_HEALTH_PORT=7433, then scrape GET /metrics on that port.
Mounting Wurk::Engine does not expose Prometheus metrics: this deliberate
separation keeps internal metrics off the host application's HTTP surface
so access can be restricted independently on the dedicated listener port.
Endpoints:
* GET /live → 200 until the Launcher is shutting down; quiet stays 200.
* GET /ready → 200 only when Redis is reachable AND the heartbeat has
fired within `ready_window` seconds AND, inside a swarm
child, enough of the swarm's children have (see
Health::Fleet). 503 otherwise.
* GET /metrics → Prometheus text exposition (Wurk::Metrics::Prometheus).
On whenever the listener is; `metrics: false` in
`:health_check_options` turns it into a 404.
Anything else returns 404 JSON.
The server uses a raw TCPServer, one accept thread and a short-lived thread per connection (bounded, deadline-capped). No Rack, no dependencies — it lives inside every worker process where Rails may or may not exist (standalone CLI, Embedded, swarm child). Bound to a dedicated port so it does not collide with the host application's HTTP.
Spec: docs/target/sidekiq-ent.md §7.1.2 (config.health_check).
Defined Under Namespace
Constant Summary collapse
- DEFAULT_PORT =
7433- DEFAULT_BIND =
'0.0.0.0'- DEFAULT_READY_WINDOW =
30- JSON_TYPE =
'application/json'
Class Attribute Summary collapse
-
.fleet_size ⇒ Object
Children the swarm was configured with, set by Swarm::ChildBoot inside each child (inherited from nowhere: the parent never runs a listener).
-
.swarm_counters ⇒ Object
The swarm parent's Swarm::RestartCounters, likewise set by ChildBoot; nil outside a swarm child.
Class Method Summary collapse
- .json(status, **extra) ⇒ Object
-
.options_from_env(env = ENV) ⇒ Object
WURK_HEALTH_PORT turns the listener on from the environment, so whoever owns the deployment manifest can add a probe without an application change.
Class Attribute Details
.fleet_size ⇒ Object
Children the swarm was configured with, set by Swarm::ChildBoot inside each child (inherited from nowhere: the parent never runs a listener). nil outside a swarm child — standalone and embedded processes are a fleet of one and /ready judges them on their own heartbeat alone.
43 44 45 |
# File 'lib/wurk/health.rb', line 43 def fleet_size @fleet_size end |
.swarm_counters ⇒ Object
The swarm parent's Swarm::RestartCounters, likewise set by ChildBoot; nil outside a swarm child.
47 48 49 |
# File 'lib/wurk/health.rb', line 47 def swarm_counters @swarm_counters end |
Class Method Details
.json(status, **extra) ⇒ Object
65 66 67 |
# File 'lib/wurk/health.rb', line 65 def json(status, **extra) ::JSON.generate({ status: status }.merge(extra)) end |
.options_from_env(env = ENV) ⇒ Object
WURK_HEALTH_PORT turns the listener on from the environment, so whoever
owns the deployment manifest can add a probe without an application
change. config.health_check wins when both are set. A bad value raises:
a probe silently not listening would restart the pod forever instead.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wurk/health.rb', line 53 def (env = ENV) raw = env['WURK_HEALTH_PORT'].to_s.strip return nil if raw.empty? port = Integer(raw, 10) raise ArgumentError unless port.between?(0, 65_535) { port: port } rescue ArgumentError raise ArgumentError, "WURK_HEALTH_PORT must be a port number (got #{raw.inspect})" end |