Skip to content
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

Merged
merged 5 commits into from
Jan 5, 2022
Merged

Conversation

spacewander
Copy link
Member

See #5881 (comment)

Signed-off-by: spacewander spacewanderlzx@gmail.com

What this PR does / why we need it:

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

See apache#5881 (comment)

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
@spacewander spacewander marked this pull request as ready for review December 31, 2021 10:25
@juzhiyuan
Copy link
Member

cc @zaunist @leslie-tsang @guoqqqi to have a check 😄

Co-authored-by: Yu.Bozhong <y.bz@foxmail.com>
Copy link
Member

@bisakhmondal bisakhmondal left a 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.|
Copy link
Member

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?

Copy link
Member Author

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>
Comment on lines +253 to +257
-- 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
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

@leslie-tsang leslie-tsang Jan 3, 2022

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

Copy link
Member Author

@spacewander spacewander Jan 4, 2022

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.

Copy link
Member

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.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
@spacewander spacewander merged commit c6f1a83 into apache:master Jan 5, 2022
@spacewander spacewander deleted the lccc branch January 5, 2022 01:05
kyroslin pushed a commit to kyroslin/apisix that referenced this pull request Jan 5, 2022
Co-authored-by: Yu.Bozhong <y.bz@foxmail.com>
Co-authored-by: Bisakh <bisakhmondal00@gmail.com>
@spacewander spacewander mentioned this pull request Feb 18, 2022
4 tasks
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.

6 participants