Sigra.RateLimiters.Hammer (Sigra v1.20.0)

Copy Markdown View Source

Hammer 7.x rate limiter implementation.

Requires the host app to define a Hammer module with use Hammer, backend: :ets and start it in the supervision tree. Configure the module name via:

config :sigra, hammer_module: MyApp.RateLimit

Hammer 7.x API

Hammer 7.x uses hit(key, scale_ms, limit) -- note that the window (scale) comes before the limit. This wrapper adapts the Sigra.RateLimiter check_rate/3 callback signature (key, limit, window_ms) to the correct Hammer parameter order.

Fail-Open Behavior

If the configured Hammer module is unavailable (e.g., GenServer not started), the wrapper logs a warning and returns {:allow, 0} -- failing open to avoid blocking legitimate requests when rate limiting infrastructure is down.