Alternera.Plugin.Provisional.Rate (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

Provisional: added for Rate limit, and a change to it needs a changelog line but no new major (docs/USER_PLUGINS_DESIGN.md).

A rate counted per key, through Alternera.Plugin.Host: check/3 counts one request of key against rate and answers :ok, or {:refuse, retry_in_ms} when the key is over it. The proxy counts with the counter its usage plans use (generic cell rate: burst pass at once after a quiet spell, then one every per_seconds / requests), per node.

The counts are the step's own: the host keeps them under the tenant and the step (its pipeline and id, from the context), so two steps never share counts and a usage plan's counts are apart from every step's. A plugin names only the key within them.

Summary

Types

A rate: requests per per_seconds, burst at once.

Functions

Counts one request of key against rate, in the step's own counts.

Types

rate()

@type rate() :: %{
  requests: pos_integer(),
  per_seconds: pos_integer(),
  burst: pos_integer()
}

A rate: requests per per_seconds, burst at once.

Functions

check(context, key, rate)

@spec check(map(), String.t(), rate()) :: :ok | {:refuse, pos_integer()}

Counts one request of key against rate, in the step's own counts.