Behaviour for rate limiting implementations.
Sigra supports both IP-based and account-based rate limiting. When
Hammer is available, Sigra.RateLimiters.Hammer provides the
implementation. When Hammer is absent, Sigra.RateLimiters.Noop
is used as a fail-open fallback with a logged warning.
Return Values
Rate limiters return tagged tuples following Hammer's convention:
{:allow, count}-- request allowed,countis the current request count{:deny, retry_after_ms}-- request denied,retry_after_msindicates when to retry
Mox Usage
Mox.defmock(MockRateLimiter, for: Sigra.RateLimiter)
Summary
Callbacks
Checks whether a request identified by key should be allowed.
Callbacks
@callback check_rate( key :: String.t(), limit :: pos_integer(), window_ms :: pos_integer() ) :: {:allow, count :: pos_integer()} | {:deny, retry_after_ms :: pos_integer()}
Checks whether a request identified by key should be allowed.