Skip to content

Add emulator handler for RateLimitByKey#221

Open
Mielek wants to merge 2 commits into
Azure:mainfrom
Mielek:emulator/rate-limit-by-key
Open

Add emulator handler for RateLimitByKey#221
Mielek wants to merge 2 commits into
Azure:mainfrom
Mielek:emulator/rate-limit-by-key

Conversation

@Mielek
Copy link
Copy Markdown
Contributor

@Mielek Mielek commented Feb 26, 2026

Summary

Implement RateLimitByKeyHandler with counter-based emulation using CounterKey.

Changes

  • Modified: src/Testing/Emulator/Policies/RateLimitByKeyHandler.cs - counter-based implementation
  • New: test/Test.Testing/Emulator/Policies/RateLimitByKeyTests.cs - 11 test cases
  • Dependency: Includes RateLimitStore infrastructure (shared with RateLimit PR)

Features

  • Counter keyed by config.CounterKey (user-defined expression)
  • IncrementCount support (custom increment, default 1)
  • IncrementCondition support (skip increment when false)
  • Check-then-increment matching gateway behavior
  • 429 with Retry-After on exceeded
  • Headers/variables on success path only

174 tests pass, 0 regressions.

- Implement RateLimitByKeyHandler with counter-based emulation using CounterKey
- Supports IncrementCount (custom increment) and IncrementCondition (skip increment)
- Check-then-increment pattern matching gateway behavior
- Returns 429 when counter at/over limit, with Retry-After headers
- Reuses RateLimitStore infrastructure from RateLimit handler
- Add RateLimitByKeyTests with 11 test cases
- Sections: Inbound

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

2 participants