Skip to content

feat(limit-count): add constant key type#5984

Merged
spacewander merged 5 commits into
apache:masterfrom
spacewander:lccc
Jan 5, 2022
Merged

feat(limit-count): add constant key type#5984
spacewander merged 5 commits into
apache:masterfrom
spacewander:lccc

Conversation

@spacewander

Copy link
Copy Markdown
Member

See #5881 (comment)

Signed-off-by: spacewander [email protected]

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

@spacewander
spacewander marked this pull request as ready for review December 31, 2021 10:25
@juzhiyuan

Copy link
Copy Markdown
Member

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

Comment thread docs/zh/latest/plugins/limit-count.md Outdated

@bisakhmondal bisakhmondal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment thread docs/en/latest/plugins/limit-count.md Outdated
| 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
Copy Markdown
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
Copy Markdown
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

Comment thread docs/en/latest/plugins/limit-count.md Outdated
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
Copy Markdown
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
Copy Markdown
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?

@leslie-tsang leslie-tsang Jan 3, 2022

Copy link
Copy Markdown
Member

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

@spacewander spacewander Jan 4, 2022

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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.

Comment thread docs/zh/latest/plugins/limit-count.md Outdated
Signed-off-by: spacewander <[email protected]>
@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
@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