Ankusa.SDK.Admin (ankusa_sdk v0.6.0)

Copy Markdown View Source

The operator listener (admin.port, default 4002): health, Prometheus metrics, the redacted configuration, the dead-letter queue, replay jobs, and the quarantine list.

Responses are node-local by design, so a fleet operator scrapes every node's admin port. The listener performs no authentication of its own — :headers is for whatever a deployer's boundary expects in front of it.

Failures carry retryable: false for a rejection (409 role_not_enabled, another 4xx), true for a 5xx, a redirect, a non-JSON success body, or an unreachable listener.

admin = Ankusa.SDK.Admin.new("http://localhost:4002")
{:ok, %{"status" => "ok"}} = Ankusa.SDK.Admin.health(admin)
{:ok, %{"total" => total}} = Ankusa.SDK.Admin.list_dead_letters(admin, limit: 10)

{:ok, replay} = Ankusa.SDK.Admin.create_replay(admin, %{"kind" => "dlq", "rate" => 500})
{:ok, %{"replays" => replays}} = Ankusa.SDK.Admin.list_replays(admin)
{:ok, replay} = Ankusa.SDK.Admin.update_replay(admin, replay["id"], %{"state" => "paused"})

Summary

Functions

The effective, redacted configuration: GET /v1/config.

Create a replay job: POST /v1/replays with spec as the JSON body.

One replay job by id: GET /v1/replays/:id. A 404 is replay_not_found.

Liveness probe: GET /health → {"status", "instance", "roles"}.

The audit trail, newest first: GET /v1/audit.

A page of dead-lettered hooks, newest first: GET /v1/dlq.

Recent quarantined hooks, newest first: GET /v1/quarantine.

Every replay job, newest first: GET /v1/replays → {"replays", [...]}.

The Prometheus text exposition body: GET /metrics.

Build a client for base_url.

Change a replay job: PATCH /v1/replays/:id.

Types

t()

@type t() :: %Ankusa.SDK.Admin{http: term()}

Functions

config(client)

@spec config(t()) :: {:ok, term()} | {:error, Exception.t()}

The effective, redacted configuration: GET /v1/config.

create_replay(client, spec)

@spec create_replay(t(), term()) :: {:ok, term()} | {:error, Exception.t()}

Create a replay job: POST /v1/replays with spec as the JSON body.

spec is a map (or keyword list) naming the job: %{"kind" => "dlq"}, %{"kind" => "archive"} or %{"kind" => "quarantine"}, plus the kind's filter (source_id/id/since/until for dlq and quarantine, from/to/sinks for archive) and the optional rate and max_lag_ms. The response is the full Replay object; a retry of the same spec answers the existing running/paused job instead of creating a second.

get_replay(client, id)

@spec get_replay(t(), String.t()) :: {:ok, term()} | {:error, Exception.t()}

One replay job by id: GET /v1/replays/:id. A 404 is replay_not_found.

health(client)

@spec health(t()) :: {:ok, term()} | {:error, Exception.t()}

Liveness probe: GET /health → {"status", "instance", "roles"}.

list_audit(client, params \\ [])

@spec list_audit(t(), term()) :: {:ok, term()} | {:error, Exception.t()}

The audit trail, newest first: GET /v1/audit.

params may carry cursor, limit, since, until, actor, action and tenant; nil values are left out of the query string rather than sent as =.

list_dead_letters(client, params \\ [])

@spec list_dead_letters(t(), term()) :: {:ok, term()} | {:error, Exception.t()}

A page of dead-lettered hooks, newest first: GET /v1/dlq.

params may carry source_id, since and limit; nil values are left out of the query string rather than sent as =.

list_quarantined(client, params \\ [])

@spec list_quarantined(t(), term()) :: {:ok, term()} | {:error, Exception.t()}

Recent quarantined hooks, newest first: GET /v1/quarantine.

params may carry limit; nil values are left out of the query string.

list_replays(client)

@spec list_replays(t()) :: {:ok, term()} | {:error, Exception.t()}

Every replay job, newest first: GET /v1/replays → {"replays", [...]}.

metrics(client)

@spec metrics(t()) :: {:ok, binary()} | {:error, Exception.t()}

The Prometheus text exposition body: GET /metrics.

new(base_url, opts \\ [])

@spec new(String.t(), keyword()) :: t()

Build a client for base_url.

Options are :headers (a map or {name, value} list sent on every request), :timeout_ms (default 10_000, applied to connect and receive — to receive only with a :finch pool, which owns its connect options), and :req_options (transport tuning: :finch, :connect_options, :pool_timeout, :plug; :finch and :connect_options are exclusive).

update_replay(client, id, patch)

@spec update_replay(t(), String.t(), term()) ::
  {:ok, term()} | {:error, Exception.t()}

Change a replay job: PATCH /v1/replays/:id.

patch may set state ("running"/"paused"/"cancelled"), rate, and max_lag_ms. A job that already finished (done/cancelled/failed) is a replay_finished rejection.