# `Ankusa.Health.Check`
[🔗](https://github.com/jamescarr/ankusa/blob/ankusa-v0.7.0/packages/ankusa/lib/ankusa/health/check.ex#L1)

One thing `GET /ready` asks about (`Ankusa.Health`).

A check says whether it `applies?/1` to this node's config (a node with no
store has no `store` check, a threshold left `nil` switches its check off),
whether a failure of it makes the node unready (`gates?/1`), and `run/1`s
itself. `all/0` is the registry, in the order the body lists them:

  * `Ankusa.Health.Check.Drain`: the node is being stopped
    (`Ankusa.Health.drain/1`). Only present while it is; reports `draining`. Gates.
  * `Ankusa.Health.Check.Store`: the store takes a synced write. Gates.
  * `Ankusa.Health.Check.Intake`: the `wal: :dual` intake log answers. Gates.
  * `Ankusa.Health.Check.Sinks`: under `wal: :none`, no sink failed its last
    publish within `listener.ready_sink_error_window_ms`. Gates.
  * `Ankusa.Health.Check.Disk`: `listener.ready_min_free_bytes` of `data_dir`'s file
    system are free. Gates.
  * `Ankusa.Health.Check.Backlog`: the oldest due row has waited no longer than
    `queue.max_oldest_due_ms`. A label: never makes the node unready.
  * `Ankusa.Health.Check.Backup`: the last backup is younger than
    `backup.max_age_ms`. Gates only with `backup.require_fresh`.

`run/1` answers `:ok`, `{:failing, reason}` or `{:draining, reason}`, the
`reason` an atom from a fixed set per check (it reaches the `/ready` body, so
it never carries an error term). A check must not hold a request longer than a
readiness probe waits: bound every call it makes.

# `result`

```elixir
@type result() :: :ok | {:failing, atom()} | {:draining, atom()}
```

# `applies?`

```elixir
@callback applies?(Ankusa.Config.t()) :: boolean()
```

Whether this node's config has the check run at all.

# `gates?`

```elixir
@callback gates?(Ankusa.Config.t()) :: boolean()
```

Whether a check that is not `:ok` makes the node unready (`503`).

# `name`

```elixir
@callback name() :: atom()
```

The key the check's state has in the `/ready` body.

# `run`

```elixir
@callback run(Ankusa.Config.t()) :: result()
```

# `all`

```elixir
@spec all() :: [module()]
```

Every check, in body order.

# `run`

```elixir
@spec run(module(), Ankusa.Config.t()) :: result()
```

Run `check`. A check that raises, exits or throws is failing with reason
`:error`: readiness never crashes the probe, and a check that cannot answer
must not read as healthy.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
