Class: KicksLiveness::Configuration

Inherits:
Object
  • Object
show all
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.

See Also:

Constant Summary collapse

DEFAULT_TICK =

Returns default seconds between checks.

Returns:

  • (Integer)

    default seconds between checks

10
DEFAULT_STARTUP_GRACE_TICKS =

Returns unhealthy ticks tolerated at startup before one ERROR.

Returns:

  • (Integer)

    unhealthy ticks tolerated at startup before one ERROR

6

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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)

Parameters:

  • value (Boolean)

    set false to start no monitor thread, e.g. in tests



33
34
35
# File 'lib/kicks_liveness/configuration.rb', line 33

def enabled=(value)
  @enabled = value
end

#loggerLogger?

Returns explicit logger; defaults to Sneakers.logger.

Returns:

  • (Logger, nil)

    explicit logger; defaults to Sneakers.logger



31
32
33
# File 'lib/kicks_liveness/configuration.rb', line 31

def logger
  @logger
end

#startup_grace_ticksInteger

Returns unhealthy ticks tolerated at startup before one ERROR.

Returns:

  • (Integer)

    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

#dirString

Read-only, sourced from the environment so that it matches what the probe sees.

Returns:

  • (String)

    marks directory



81
82
83
# File 'lib/kicks_liveness/configuration.rb', line 81

def dir
  Heartbeat.env_dir
end

#enabled?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/kicks_liveness/configuration.rb', line 43

def enabled?
  @enabled
end

#max_ageInteger

Read-only, sourced from the environment so that it matches what the probe sees.

Returns:

  • (Integer)

    seconds after which a mark is considered stale



88
89
90
# File 'lib/kicks_liveness/configuration.rb', line 88

def max_age
  Heartbeat.env_max_age
end

#resolved_loggerLogger, ...

Resolved lazily: at the time this object is built, Sneakers.logger may not be configured yet.

Returns:

  • (Logger, false, nil)


95
96
97
# File 'lib/kicks_liveness/configuration.rb', line 95

def resolved_logger
  @logger || (defined?(::Sneakers) && ::Sneakers.logger)
end

#tickNumeric

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.

Returns:

  • (Numeric)


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.

Parameters:

  • seconds (Numeric)

Returns:

  • (Numeric)

Raises:

  • (ArgumentError)

    if not a positive number



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