Vaultx.Base.RateLimiter (Vaultx v0.7.0)

View Source

Token-bucket rate limiter for Vaultx HTTP requests with optional multi-bucket support.

  • Each bucket has capacity = rate + burst
  • Tokens refill at rate per second
  • consume blocks (sleep) until a token is available

Agent state keeps multiple buckets, keyed by an identifier (e.g., host|namespace). If not started (feature disabled), calls become no-ops.

Summary

Functions

Returns a specification to start this module under a supervisor.

Consume 1 token from the default bucket ("default").

Consume 1 token from a named bucket. Uses default rate/burst configured at start.

Consume 1 token from a named bucket with explicit rate and burst. Useful when per-request opts specify rate/burst.

Types

bucket()

@type bucket() :: %{
  rate: pos_integer(),
  burst: non_neg_integer(),
  capacity: pos_integer(),
  tokens: float(),
  last_refill: integer()
}

state()

@type state() :: %{
  buckets: %{optional(String.t()) => bucket()},
  default_rate: pos_integer(),
  default_burst: non_neg_integer()
}

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

consume()

Consume 1 token from the default bucket ("default").

consume(bucket_key)

Consume 1 token from a named bucket. Uses default rate/burst configured at start.

consume(bucket_key, rate, burst)

Consume 1 token from a named bucket with explicit rate and burst. Useful when per-request opts specify rate/burst.

start_link(opts)