Karta. IPPools. Monitor
(Karta v1.0.0)
Follows which IP pool addresses this node holds, and runs each pool's delivery queue only while it holds one of the pool's addresses.
Every :interval milliseconds (default 5,000) it reads the addresses of
the node's network interfaces that are up (:inet.getifaddrs/0) and the
pools (Karta.IPPools.list_pools/0). A pool is held when the bind
address of one of its addresses (Karta.IPPools.IPAddress.bind_address/1)
is among them. An address that moves between nodes (a keepalived
virtual address, a cloud's floating address) is followed so, without
any election between the nodes:
- a pool this node starts to hold gets its queue
(
Karta.IPPools.queue/1) started here,Oban.start_queue/2withlocal_only: trueand the pool'sconcurrencyjobs at a time (:limitwhen the pool has none), or resumed; - a pool it no longer holds has its queue paused here: running jobs finish (a connection from an address that has gone fails and the recipient is retried later, from the new holder), no new job starts;
- the queue of a pool that was deleted is stopped here;
- the queue of a pool whose
concurrencychanged is scaled here (Oban.scale_queue/2).
With no node holding a pool's address, its mail waits in the queue and is delivered once a node holds it again; the retry period of each recipient keeps running. Two nodes holding the same address for a moment both deliver; each job still runs once.
The interface addresses it last read are what the delivery jobs of this
Oban instance bind to (local_addresses/1). When reading them or the
pools fails, the previous state is kept and a warning logged.
Each change is logged (IP pool bulk: this node now holds 192.0.2.25,
... no longer holds ...), and each check emits, per pool address, the
telemetry event [:karta, :ip_pool, :address] with the measurement
held (1 or 0) and the metadata pool and address (text), for the
metric karta_ip_pool_address_held.
Options: :oban (the Oban instance, default Oban), :interval (nil:
only check/1), :limit (jobs at a time of a pool without its own
concurrency; default 10), :getifaddrs (a function of no
arguments, or {module, function, args}; default :inet.getifaddrs/0),
:list_pools (a function of no arguments; default
Karta.IPPools.list_pools/0), :name.
Summary
Functions
Checks now, and returns what this node holds: %{pool name => [address text]}.
Returns a specification to start this module under a supervisor.
The interface addresses the monitor of the Oban instance oban last
read, or :error when no monitor runs for it.
Starts the monitor; see the module doc for the options.
Functions
@spec check(GenServer.server()) :: %{required(String.t()) => [String.t()]}
Checks now, and returns what this node holds: %{pool name => [address text]}.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec local_addresses(atom()) :: {:ok, MapSet.t(:inet.ip_address())} | :error
The interface addresses the monitor of the Oban instance oban last
read, or :error when no monitor runs for it.
Starts the monitor; see the module doc for the options.