-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(limit-count): add constant key type #5984
Conversation
See apache#5881 (comment) Signed-off-by: spacewander <spacewanderlzx@gmail.com>
cc @zaunist @leslie-tsang @guoqqqi to have a check 😄 |
Co-authored-by: Yu.Bozhong <y.bz@foxmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@@ -39,7 +39,7 @@ Limit request rate by a fixed number of requests in a given time window. | |||
| ------------------- | ------- | --------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | |||
| count | integer | required | | count > 0 | the specified number of requests threshold. | | |||
| time_window | integer | required | | time_window > 0 | the time window in seconds before the request count is reset. | | |||
| key_type | string | optional | "var" | ["var", "var_combination"] | the type of key. | | |||
| key_type | string | optional | "var" | ["var", "var_combination", "constant"] | the type of key. | | |||
| key | string | optional | "remote_addr" | | the user specified key to limit the rate. If the `key_type` is "var", the key will be treated as a name of variable. If the `key_type` is "var_combination", the key will be a combination of variables. For example, if we use "$remote_addr $consumer_name" as keys, plugin will be restricted by two keys which are "remote_addr" and "consumer_name". If the value of the key is empty, `remote_addr` will be set as the default key.| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, can we add a line here[L43] to document how the key will be interpreted when the key_type
is constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in the new commit
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
Co-authored-by: Bisakh <bisakhmondal00@gmail.com>
-- here we add a separator ':' to mark the boundary of the prefix and the key itself | ||
if not conf.group then | ||
key = key .. ctx.conf_type .. ctx.conf_version | ||
key = ctx.conf_type .. ctx.conf_version .. ':' .. key | ||
else | ||
key = key .. conf.group | ||
key = conf.group .. ':' .. key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should add a note here to alert those who use the key to monitoring or something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you give an example for the note?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
-- key format changed from `key*` to `*:key` for constant key type support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err...
I don't want to comment on all the changes in the code, unless it is something that affects public API. AFAIK, we don't describe the key format in the doc. So I think such change is just implementation details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make Sense, leave the comment here should do the trick as well.
Co-authored-by: Yu.Bozhong <y.bz@foxmail.com> Co-authored-by: Bisakh <bisakhmondal00@gmail.com>
See #5881 (comment)
Signed-off-by: spacewander spacewanderlzx@gmail.com
What this PR does / why we need it:
Pre-submission checklist: