Loading
docs(rate_limit): add module README and link from root README
Description
Adds documentation for Labkit::RateLimit, which was previously undocumented in the repo despite being in active use and rolling out across GitLab Rails via Gitlab::ApplicationRateLimiter::LabkitAdapter.
Specifically:
- Adds
lib/labkit/rate_limit/README.mdcovering:- Configuration via
Labkit::RateLimit.configure(Redis pool + logger) - Constructing a
Limiterand thecheck/peekAPI Identifierand the characteristic /matchmodel (incl.eq/rematchers)Rulesemantics:limit,period,action(:block/:log/:allow),match,characteristics- First-match-wins evaluation order and the special non-terminating behavior of
:logrules ResultAPI andto_response_headers- Redis key shape, TTL semantics, and 200-byte SHA-256 fallback
- Emitted Prometheus metrics (names, labels, label values)
- Fail-open behavior on Redis error
- Dev/test strict validation vs production sanitisation/warn behavior
- Configuration via
- Adds a
Labkit::RateLimitentry to the Functionality list in the rootREADME.md, with a link to the module README, matching the pattern used forLabkit::Metrics,Labkit::UserExperienceSli, andLabkit::RSpec. - Corrects an inaccurate inline comment in
lib/labkit/rate_limit/rule.rbthat described:allowas a "bypass: short-circuit evaluation with no Redis writes". The evaluator always increments the counter when a rule matches;:allowonly changes the reportedResult#actionwhen the limit is exceeded.
Related Issues
Closes #68 (closed)
Parent epic: gitlab-com/gl-infra&2021
Edited by Max Woolf