Class: KicksLiveness::Configuration
- Inherits:
-
Object
- Object
- KicksLiveness::Configuration
- Defined in:
- lib/kicks_liveness/configuration.rb
Overview
What the application may configure, and what comes from the environment only.
dir and max_age are deliberately read-only here: the probe runs as a
separate process launched by the container runtime and cannot read the
application's initializer. Were they settable in both places, a mismatch
between what the worker writes and what the probe expects would pass
unnoticed.
Constant Summary collapse
- DEFAULT_TICK =
Returns default seconds between checks.
10- DEFAULT_STARTUP_GRACE_TICKS =
Returns unhealthy ticks tolerated at startup before one ERROR.
6
Instance Attribute Summary collapse
- #enabled ⇒ Object writeonly
-
#logger ⇒ Logger?
Explicit logger; defaults to
Sneakers.logger. -
#startup_grace_ticks ⇒ Integer
Unhealthy ticks tolerated at startup before one ERROR.
Instance Method Summary collapse
-
#dir ⇒ String
Read-only, sourced from the environment so that it matches what the probe sees.
- #enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#max_age ⇒ Integer
Read-only, sourced from the environment so that it matches what the probe sees.
-
#resolved_logger ⇒ Logger, ...
Resolved lazily: at the time this object is built,
Sneakers.loggermay not be configured yet. -
#tick ⇒ Numeric
Seconds between checks.
-
#tick=(seconds) ⇒ Numeric
A tick is what the monitor thread sleeps on, so a non-positive value is not a setting but a broken monitor.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
35 36 37 38 39 40 |
# File 'lib/kicks_liveness/configuration.rb', line 35 def initialize @startup_grace_ticks = DEFAULT_STARTUP_GRACE_TICKS @enabled = true @logger = nil @tick = environment_tick end |
Instance Attribute Details
#enabled=(value) ⇒ Object (writeonly)
33 34 35 |
# File 'lib/kicks_liveness/configuration.rb', line 33 def enabled=(value) @enabled = value end |
#logger ⇒ Logger?
Returns explicit logger; defaults to Sneakers.logger.
31 32 33 |
# File 'lib/kicks_liveness/configuration.rb', line 31 def logger @logger end |
#startup_grace_ticks ⇒ Integer
Returns unhealthy ticks tolerated at startup before one ERROR.
29 30 31 |
# File 'lib/kicks_liveness/configuration.rb', line 29 def startup_grace_ticks @startup_grace_ticks end |
Instance Method Details
#dir ⇒ String
Read-only, sourced from the environment so that it matches what the probe sees.
81 82 83 |
# File 'lib/kicks_liveness/configuration.rb', line 81 def dir Heartbeat.env_dir end |
#enabled? ⇒ Boolean
43 44 45 |
# File 'lib/kicks_liveness/configuration.rb', line 43 def enabled? @enabled end |
#max_age ⇒ Integer
Read-only, sourced from the environment so that it matches what the probe sees.
88 89 90 |
# File 'lib/kicks_liveness/configuration.rb', line 88 def max_age Heartbeat.env_max_age end |
#resolved_logger ⇒ Logger, ...
Resolved lazily: at the time this object is built, Sneakers.logger may
not be configured yet.
95 96 97 |
# File 'lib/kicks_liveness/configuration.rb', line 95 def resolved_logger @logger || (defined?(::Sneakers) && ::Sneakers.logger) end |
#tick ⇒ Numeric
Seconds between checks. An incompatibility warning for an environment fallback is delayed until this value is actually used, so an initializer can override it or disable the monitor without a misleading warning.
24 25 26 27 |
# File 'lib/kicks_liveness/configuration.rb', line 24 def tick warn_incompatible_environment_tick_once @tick end |
#tick=(seconds) ⇒ Numeric
A tick is what the monitor thread sleeps on, so a non-positive value is not a setting but a broken monitor. An initializer is code, and code should fail loudly at boot, where the developer is looking. Environment input is resolved separately by #environment_tick, with a safe fallback.
55 56 57 58 59 60 61 |
# File 'lib/kicks_liveness/configuration.rb', line 55 def tick=(seconds) raise ArgumentError, "tick must be a positive number, got #{seconds.inspect}" unless positive_number?(seconds) raise ArgumentError, "tick must be less than max_age (#{max_age}s), got #{seconds.inspect}" if seconds >= max_age @incompatible_environment_tick = nil @tick = seconds end |