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:codis-proxy bigKey/Request fuse protection #2646

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

XiaoLiang2333
Copy link
Contributor

@XiaoLiang2333 XiaoLiang2333 changed the title codis-proxy bigKey/Request fuse protection feat:codis-proxy bigKey/Request fuse protection May 10, 2024
@AlexStocks AlexStocks requested a review from chejinge May 10, 2024 12:24
# quick command list
quick_cmd_list = "get,set"
# slow command list
slow_cmd_list = "mget, mset"
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里还是还原回去吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

monitor_log_max_len = 10000
# set the limitation of result set for xmonitor log
monitor_result_set_size = 20
# switch for xmonitor,0 is disabled, 1 is enabled
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里是把监控也做了吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的,除了一些特定的命令外,每一次请求/响应若被判定为bigRequest/Key、HighRisk则会存入日志,以便于使用命令"XMonitor"查看

@AlexStocks
Copy link
Collaborator

关闭一个 Proxy 然后重启,其大 key 信息不存在,但 Pika 大 key 信息还存在,造成 Proxy 与 Pika 大 key 信息不一致。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


When a Proxy is closed and then restarted, its big key information does not exist, but the Pika big key information still exists, causing the Proxy and Pika big key information to be inconsistent.

@AlexStocks AlexStocks requested a review from luky116 May 31, 2024 12:50
)

const (
BUCKET_FILL_INTERVAL int64 = 10 // 令牌桶填充间隔,以一秒为单位进行划分,比如值为10,qps为10000,意味着间隔为1s/10 = 100ms,桶容量为10000/10 = 1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

所有的中文注释,改为英文的


// 令牌桶操作
func isAllowed() bool {
if limiterState.Int64() == SWITCH_CLOSED { // 限流器关闭状态,直接返回true,允许请求通过
Copy link
Collaborator

Choose a reason for hiding this comment

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

return limiterState.Int64() == SWITCH_CLOSED || limiter.Allow()

@luky116
Copy link
Collaborator

luky116 commented Jun 1, 2024

本 PR 的功能是做大 key 分析吗?还有必要做 熔断 逻辑吗?可以把你的思路和步骤详细的写一下

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Is the function of this PR to do big key analysis? Is it still necessary to do circuit breaker logic? You can write down your ideas and steps in detail.

@AlexStocks
Copy link
Collaborator

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Review 🔍

⏱️ Estimated effort to review [1-5]

4, because the PR introduces a significant amount of new code (482 lines in a single file) which implements complex logic for monitoring and logging based on various conditions. The complexity of the logic, combined with the use of concurrency and atomic operations, requires careful review to ensure correctness, thread safety, and performance.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: The CheckResponseByArrayReturned function may return false negatives in scenarios where the array length is not an even number but should still be considered for monitoring based on content size or other criteria. This is due to the condition that immediately returns false if the array length is not an even number.

Performance Concern: The extensive use of atomic operations and potential frequent locking in a high-throughput environment (like a proxy server handling many requests) could lead to performance bottlenecks. Review and possibly benchmark sections where atomic variables are heavily used to ensure that performance is not adversely affected.

🔒 Security concerns

No

Code feedback:
relevant filecodis/pkg/proxy/monitorBkv.go
suggestion      

Consider adding a default case in switch statements where flags are checked (e.g., in CheckBatchsizeOfRequest). This would handle unexpected flags values gracefully, potentially logging a warning or error. This is important to ensure that all possible paths are accounted for, enhancing the robustness of the code. [important]

relevant lineswitch flag & (FlagReqKeys | FlagReqKeyFields) {

relevant filecodis/pkg/proxy/monitorBkv.go
suggestion      

Implement a mechanism to limit the frequency of logging to avoid potential I/O bottlenecks when many records are generated in a short period. This could be achieved by introducing a rate limiter or a buffer that periodically flushes records to the log. [important]

relevant linecollectRecord(record)

relevant filecodis/pkg/proxy/monitorBkv.go
suggestion      

Refactor the repeated pattern of checking conditions and setting values in functions like XMonitorSetMaxLengthOfValue into a helper function to reduce code duplication. This will make the code cleaner and easier to maintain. [medium]

relevant lineif maxLength < 0 {

relevant filecodis/pkg/proxy/monitorBkv.go
suggestion      

For better maintainability, consider separating the large monitorBkv.go file into smaller files, each focusing on a specific aspect of functionality (e.g., request monitoring, response monitoring, utility functions). This modular approach can make the codebase easier to navigate and maintain. [medium]

relevant linepackage proxy

@AlexStocks
Copy link
Collaborator

@CodiumAI-Agent /improve

@CodiumAI-Agent
Copy link

Failed to generate code suggestions for PR

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.

None yet

6 participants