feat: add Prometheus metrics to rate limit evaluator

feat: add Prometheus metrics to rate limit evaluator

Add 4 Prometheus metrics to Labkit::RateLimit::Evaluator to observe rate limiting behavior without additional log volume:

  • gitlab_labkit_rate_limiter_calls_total (counter) — incremented on every successful check. Labels: rate_limiter, rule, action (block/log/allow).
  • gitlab_labkit_rate_limiter_errors_total (counter) — incremented when a check fails (Redis unavailable). Label: rate_limiter.
  • gitlab_labkit_rate_limiter_limit (gauge, multiprocess: :max) — the resolved limit value per rule.
  • gitlab_labkit_rate_limiter_period_seconds (gauge, multiprocess: :max) — the resolved period value per rule.

The Metrics module delegates to Labkit::Metrics::Client without memoization, relying on Registry.safe_register for idempotent get-or-create. This avoids stale references when the Prometheus registry is reset in tests.

Also adds resolved_limit and resolved_period to Result so callers (and metrics) can access the resolved values without re-invoking callables.

gitlab-com/gl-infra/production-engineering#28798 (closed)

Edited by Bob Van Landuyt

Merge request reports

Loading
Loading