feat: per-unit-descriptor-response-headers - #1257
Conversation
Signed-off-by: Selu <joseluisjimenezquereda@gmail.com> Co-authored-by: Samay Varshney <samay.varshney@arcana.io>
|
Can you review this one @psbrar99 ? Thanks ! |
nacx
left a comment
There was a problem hiding this comment.
Thanks you! I left come comments.
| continue | ||
| } | ||
|
|
||
| unitSuffix := strings.ToLower(status.CurrentLimit.Unit.String()) + "s" |
There was a problem hiding this comment.
Keying the header purely by time unit (ratelimit-limit-seconds, ratelimit-remaining-seconds) breaks down when a request matches two or more descriptors that share the same unit (for example, a per-IP "10/sec" rule and a per-API-key "5/sec" rule on the same request).
You'd emit two ratelimit-limit-seconds / ratelimit-remaining-seconds entries with different values and no way for the client to tell which is which. The test here (and the original #1190 example) only exercises one SECOND + one MINUTE descriptor, so this case isn't covered. Given the feature's whole point is "show me every descriptor's limits," could we disambiguate (like including the descriptor key or an index in the header name) or at least document this as a known limitation and add a test for the collision case?
There was a problem hiding this comment.
I agree.. what do you think if we still follow the same approach, and when we enable this new flag it returns the closer limits per unit? so we can replace LIMIT_ALL_DESCRIPTORS_HEADERS_ENABLED -> LIMIT_PER_UNIT_HEADERS_ENABLED ?
So avoid duplication. Working on it
There was a problem hiding this comment.
The chosen approach LGTM. After a second thought, returning descriptor names, etc., could not be desirable in all cases, as it could leak some internal structure/info that is not desired.
Signed-off-by: Selu <joseluisjimenezquereda@gmail.com>
|
Thanks for the approval @psbrar99 ! ❤️ is there any specific time or schedule to get this merge? |
Summary
Supersedes #1190, which introduced optional response headers for every configured rate-limit descriptor.
This change:
LIMIT_PER_UNIT_HEADERS_ENABLEDRatelimit-Limit-<unit>andRatelimit-Remaining-<unit>for each limited descriptorREADME.mdLIMIT_RESPONSE_HEADERS_ENABLEDis also enabledmainCredit
This work is based on the original implementation by @samay-arcana in #1190. Thank you for the initial feature and test coverage.
Testing