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:add wasm go key-rate-limit plugin #1751

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kai2321
Copy link
Collaborator

@kai2321 kai2321 commented Feb 12, 2025

Ⅰ. Describe what this PR did

实现wasm-go的本地key-rate-limit插件

Ⅱ. Does this pull request fix one issue?

#596

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.41%. Comparing base (ef31e09) to head (c3c2627).
Report is 309 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1751      +/-   ##
==========================================
+ Coverage   35.91%   43.41%   +7.50%     
==========================================
  Files          69       76       +7     
  Lines       11576    12278     +702     
==========================================
+ Hits         4157     5331    +1174     
+ Misses       7104     6617     -487     
- Partials      315      330      +15     

see 71 files with indirect coverage changes

@kai2321
Copy link
Collaborator Author

kai2321 commented Feb 17, 2025

请求review(如果有时间的话)

var tokenBucketPrefix string = "mse.token_bucket"

// Key-prefix for token bucket last updated time.
var lastRefilledPrefix string = "mse.last_refilled"
Copy link
Collaborator

Choose a reason for hiding this comment

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

这两个是不是用const更好?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

已改

// Key-prefix for token bucket last updated time.
var lastRefilledPrefix string = "mse.last_refilled"

var ruleId int = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个作为 parseConfig 的一个局部变量是不是就够了?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这里我想请教一下parseConfig在处理不同级别的规则,比如domain和ingress的rule是不是会分别调用parseconfig还是一次性调用,如果一次性调用的话ruleId作为parseConfig的局部变量就可以了。

Copy link
Collaborator

Choose a reason for hiding this comment

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

这里我想请教一下parseConfig在处理不同级别的规则,比如domain和ingress的rule是不是会分别调用parseconfig还是一次性调用,如果一次性调用的话ruleId作为parseConfig的局部变量就可以了。

不同粒度的配置是独立的解析的,不需要考虑覆盖。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这里主要是想通过一个全局的ruleId来区分不同粒度下limit_key规则相同的情况,独立接卸的情况下ruleId如果作为parseConfig的一个局部变量是不是没法区分

Copy link
Collaborator

Choose a reason for hiding this comment

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

@johnlanni 看一下这种场景建议如何实现。

var initialValue uint64 = 0
for _, rule := range rules {
lastRefilledKey := strconv.Itoa(rule.ruleId) + lastRefilledPrefix + rule.key
tokenBucketKey := strconv.Itoa(rule.ruleId) + tokenBucketPrefix + rule.key
Copy link
Collaborator

Choose a reason for hiding this comment

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

感觉可以给LimitItem加个函数生成这两个key

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

已加

@kai2321 kai2321 force-pushed the feat-key-rate-limit branch from 43726bd to c3c2627 Compare February 24, 2025 12:33
@kai2321
Copy link
Collaborator Author

kai2321 commented Feb 27, 2025

PTAL @CH3CHO

Copy link
Collaborator

@CH3CHO CH3CHO left a comment

Choose a reason for hiding this comment

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

暂时没有其他问题了

// Key-prefix for token bucket last updated time.
var lastRefilledPrefix string = "mse.last_refilled"

var ruleId int = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

@johnlanni 看一下这种场景建议如何实现。

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.

3 participants