Karta.Kantoor.KeptStorage (Karta v1.0.0)

The storage held by messages Kantoor asked Karta to keep (Karta.Kantoor.Retention), and the optional per-server hard cap on it.

A message is kept while it is an outgoing message with retention_keep, or an incoming one with a live (not deleted) delivery with retention_keep. Kept messages never expire and are exempt from the server's size cap, so without a ceiling keep would make Karta an unbounded mail store.

  • Metrics, exposed when the Kantoor flag is on (Karta.PromEx.KeptStorage), per server: karta_kantoor_kept_storage_bytes, karta_kantoor_kept_storage_messages, and, where a cap is set, karta_kantoor_kept_storage_cap_bytes; and karta_kantoor_keep_refused_total, the policies refused because of the cap. Operators alert from these; Karta has no alerting of its own. An example: karta_kantoor_kept_storage_bytes / karta_kantoor_kept_storage_cap_bytes > 0.8.
  • The cap is servers.kept_storage_cap_mb, NULL (no cap, the default) unless an operator sets it with set_cap/2. When it is set, a keep that would take the server's kept bytes past it is refused: a send with retention: "keep" fails with kept_storage_full, and a keep answered by an endpoint is not applied (the delivery keeps the route's or the server's policy and says so in its details). Nothing already kept is ever deleted because of the cap. The check is made when the policy is set, without a lock, so concurrent requests can overshoot it by what they hold.

Summary

Functions

May size more bytes be kept for the server? Always when it has no cap, and for a message that is kept already (message_id). Counts a refusal when it says no.

The query of the server's kept messages (accepted, see the module doc).

Emits the kept-storage telemetry events of every server with kept messages or a cap (the polling of Karta.PromEx.KeptStorage).

Sets (megabytes) or clears (nil) the server's cap on kept storage.

How many bytes the server's kept messages take.

Functions

admit?(server_id, size, message_id \\ nil)

@spec admit?(Ecto.UUID.t(), non_neg_integer(), Ecto.UUID.t() | nil) :: boolean()

May size more bytes be kept for the server? Always when it has no cap, and for a message that is kept already (message_id). Counts a refusal when it says no.

kept(server_id)

@spec kept(Ecto.UUID.t()) :: Ecto.Query.t()

The query of the server's kept messages (accepted, see the module doc).

report(opts \\ [])

@spec report(keyword()) :: :ok

Emits the kept-storage telemetry events of every server with kept messages or a cap (the polling of Karta.PromEx.KeptStorage).

It never raises: the poller drops a measurement for good once it raises, and it first runs before the repository has started (and the database may be away for a moment). Such a round is logged and skipped. measure (an option for tests) replaces the measuring.

set_cap(server, megabytes)

@spec set_cap(Karta.Servers.Server.t(), pos_integer() | nil) ::
  {:ok, Karta.Servers.Server.t()} | {:error, Ecto.Changeset.t()}

Sets (megabytes) or clears (nil) the server's cap on kept storage.

used_bytes(server_id)

@spec used_bytes(Ecto.UUID.t()) :: non_neg_integer()

How many bytes the server's kept messages take.