Skip to content

limits: add peek and proportional_rate methods to Rate - #954

Open
Aditya-9-6 wants to merge 1 commit into
cloudflare:mainfrom
Aditya-9-6:feat/rate-peek-and-proportional
Open

limits: add peek and proportional_rate methods to Rate#954
Aditya-9-6 wants to merge 1 commit into
cloudflare:mainfrom
Aditya-9-6:feat/rate-peek-and-proportional

Conversation

@Aditya-9-6

Copy link
Copy Markdown

Summary

Adds non-mutating rate inspection methods (peek and proportional_rate) to pingora_limits::rate::Rate.

Motivation & Problem

When building WAF proxies, traffic inspectors, and multi-stage rate-limiting middleware using pingora-limits, callers frequently need to inspect / dry-run current event counts or sliding window rates for IP reputation scoring and logging without incrementing the rate counter via observe().

Previously, callers had no way to non-destructively peek into the current interval event count, and using PROPORTIONAL_RATE_ESTIMATE_CALC_FN required manually passing the closure to rate_with(...) on every call.

Key Changes

  • Rate::peek: Non-mutating method returning estimated number of events observed in the current interval.
  • Rate::proportional_rate: Ergonomic helper method returning real-time per-second rate estimation calculated over the sliding interval via PROPORTIONAL_RATE_ESTIMATE_CALC_FN.
  • Unit Tests: Added test_peek_and_proportional_rate in pingora-limits/src/rate.rs.

Verification

  • cargo test -p pingora-limits: Passed 9/9 unit tests cleanly.
  • Signed-off-by: Yes.

Signed-off-by: Aditya Dahale <adityadahale96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant