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.md covering:
    • Configuration via Labkit::RateLimit.configure (Redis pool + logger)
    • Constructing a Limiter and the check / peek API
    • Identifier and the characteristic / match model (incl. eq / re matchers)
    • Rule semantics: limit, period, action (:block / :log / :allow), match, characteristics
    • First-match-wins evaluation order and the special non-terminating behavior of :log rules
    • Result API and to_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
  • Adds a Labkit::RateLimit entry to the Functionality list in the root README.md, with a link to the module README, matching the pattern used for Labkit::Metrics, Labkit::UserExperienceSli, and Labkit::RSpec.
  • Corrects an inaccurate inline comment in lib/labkit/rate_limit/rule.rb that described :allow as a "bypass: short-circuit evaluation with no Redis writes". The evaluator always increments the counter when a rule matches; :allow only changes the reported Result#action when the limit is exceeded.

Closes #68 (closed)

Parent epic: gitlab-com/gl-infra&2021

Edited by Max Woolf

Merge request reports

Loading
Loading