SaltDns.Proxy.Health (Salt v1.0.0)

What "healthy" means for a load-balancer node, and the state machine that decides when its addresses leave the answers. Pure: no database, no clock of its own, no network.

Three signals

A node is healthy when all three hold (signals/3):

  • connected: its Shaker has a connection to Salt right now;
  • status: its last signed status is ok, reports software.running true, and is younger than the group's limit (default 20 minutes);
  • probe: Salt could open a TCP connection to port 443 on each published address of the node and complete a TLS handshake. Addresses of a family Salt's own host cannot reach are left out of this (SaltDns.Proxy.Families): the signal is good when every address that could be checked is ok and at least one could be checked.

The state machine

The stored state of a node is in or out, with a count of consecutive failed checks (fail) and of consecutive good ones (ok). in becomes out after fail_threshold unhealthy checks in a row (default 3); out becomes in after recover_threshold healthy checks in a row (default 6). A check of the other kind resets the opposite count, so one good check in the middle of failures starts the count again: that is the damping that keeps a flapping node from flapping in the answers.

An operator may force a node drained: it is out, and stays out whatever the checks say. The checks go on being recorded, so the evidence is current when the operator returns the node to automatic.

Summary

Functions

The signals as a short text for events and the console: the failing ones, or healthy.

The signals as a map of strings, for storing.

What the answers see of a node: :drained when forced, else its stored state.

True when every signal is :ok.

A node that has never been checked.

Runs a list of check results through step/3; the final state and every transition.

The three signals from what is known about a node.

Applies one check result. Returns the next state and the transition it caused: :out, :in or nil.

Types

settings()

@type settings() :: %{fail_threshold: pos_integer(), recover_threshold: pos_integer()}

signal()

@type signal() :: :ok | {:bad, atom()}

signals()

@type signals() :: %{connected: signal(), status: signal(), probe: signal()}

state()

@type state() :: %{
  state: :in | :out,
  override: nil | :drained,
  fail: non_neg_integer(),
  ok: non_neg_integer()
}

Functions

describe(signals)

@spec describe(signals()) :: String.t()

The signals as a short text for events and the console: the failing ones, or healthy.

dump(signals)

@spec dump(signals()) :: map()

The signals as a map of strings, for storing.

effective(map)

@spec effective(state()) :: :in | :out | :drained

What the answers see of a node: :drained when forced, else its stored state.

healthy?(arg1)

@spec healthy?(signals()) :: boolean()

True when every signal is :ok.

initial()

@spec initial() :: state()

A node that has never been checked.

run(state, results, settings)

@spec run(state(), [boolean()], settings()) :: {state(), [:in | :out]}

Runs a list of check results through step/3; the final state and every transition.

signals(facts, now, max_age)

@spec signals(map(), DateTime.t(), pos_integer()) :: signals()

The three signals from what is known about a node.

facts: connected (boolean), last_status (the stored report or nil), last_status_at (a DateTime or nil) and probe (:ok, {:error, reason}, :no_addresses or :not_checkable). max_age is in seconds.

step(state, bool, settings)

@spec step(state(), boolean(), settings()) :: {state(), nil | :in | :out}

Applies one check result. Returns the next state and the transition it caused: :out, :in or nil.