Skip to content

feat(limit-count): allow sharing counter#5881

Merged
spacewander merged 4 commits into
apache:masterfrom
spacewander:lig
Dec 24, 2021
Merged

feat(limit-count): allow sharing counter#5881
spacewander merged 4 commits into
apache:masterfrom
spacewander:lig

Conversation

@spacewander

Copy link
Copy Markdown
Member

Signed-off-by: spacewander [email protected]

What this PR does / why we need it:

Fix #5342

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

Comment thread t/plugin/limit-count2.t
--- error_log
[error]
--- response_body
{"error_msg":"failed to check the configuration of plugin limit-count err: group conf mismatched"}

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 can we update the limit-count config?

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.

We need to update the group too. Otherwise, the same group will have two different configuration.

Comment thread docs/zh/latest/plugins/limit-count.md Outdated
Comment thread docs/zh/latest/plugins/limit-count.md Outdated
if not conf.group then
key = key .. ctx.conf_type .. ctx.conf_version
else
key = key .. conf.group

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So traffic will eventually be limited according to the key generated by the combination of key and group.
But key can not be empty (if key is empty, remote_addr will be set as the default key),
so it is never possible to limit the rate only according to the group.

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.

Yes, the previous limit-count is two-dimension:
per-route x per-key

This PR allows to use:
group x per-key

If we want to limit only according to the group, we can use a constant variable, like hostname, so the per-key will be always a single point.

In the next PR, I will introduce a new key type that is equal to a constant variable, so we don't need a special configuration for the key part.

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.

Look like the hostname is not constant if the cluster limit-count is used. Anyway, we can solve it in the next PR.

@spacewander
spacewander merged commit 7a56580 into apache:master Dec 24, 2021
@spacewander
spacewander deleted the lig branch December 24, 2021 07:50
spacewander added a commit to spacewander/incubator-apisix that referenced this pull request Dec 31, 2021
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.

request help: share limit counter between routes

5 participants