Skip to content

feat:codis-proxy bigKey/Request fuse protection#2646

Closed
XiaoLiang2333 wants to merge 1 commit into
OpenAtomFoundation:unstablefrom
XiaoLiang2333:develop-
Closed

feat:codis-proxy bigKey/Request fuse protection#2646
XiaoLiang2333 wants to merge 1 commit into
OpenAtomFoundation:unstablefrom
XiaoLiang2333:develop-

Conversation

@XiaoLiang2333

Copy link
Copy Markdown
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
Comment thread codis/config/proxy.toml
# quick command list
quick_cmd_list = "get,set"
# slow command list
slow_cmd_list = "mget, mset"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里还是还原回去吧

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread codis/config/proxy.toml
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里是把监控也做了吗

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@Issues-translate-bot

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

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

luky116 commented Jun 1, 2024

Copy link
Copy Markdown
Collaborator

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

@Issues-translate-bot

Copy link
Copy Markdown

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

@CodiumAI-Agent /review

@QodoAI-Agent

Copy link
Copy Markdown

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

@CodiumAI-Agent /improve

@QodoAI-Agent

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@XiaoLiang2333

Copy link
Copy Markdown
Contributor Author

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

本PR有关<bigKey/Request监测,黑白名单,qps令牌桶限流>以及上述情况的熔断(可设置百分比),思路与步骤稍后我会挂一篇Blog解释

@Issues-translate-bot

Copy link
Copy Markdown

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


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

This PR is about <bigKey/Request monitoring, black and white list, qps token bucket current limit> and the circuit breaker in the above situation (the percentage can be set). I will explain the ideas and steps in a blog later.

@XiaoLiang2333

Copy link
Copy Markdown
Contributor Author

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

目前解决思路是,将MonitorLog信息从内存迁移到磁盘,新proxy实例可以从磁盘文件读取到之前的Log信息,具体实现正在与 @chejinge 导师讨论

@Issues-translate-bot

Copy link
Copy Markdown

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.

The current solution is to migrate MonitorLog information from memory to disk. The new proxy instance can read the previous Log information from the disk file. The specific implementation is being discussed with @chejinge instructor.

@AlexStocks

Copy link
Copy Markdown
Contributor

@XiaoLiang2333 代码中不要出现中文

@Issues-translate-bot

Copy link
Copy Markdown

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


@XiaoLiang2333 Do not allow Chinese characters to appear in the code

@XiaoLiang2333

Copy link
Copy Markdown
Contributor Author

@XiaoLiang2333 代码中不要出现中文

好的

@Issues-translate-bot

Copy link
Copy Markdown

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


@XiaoLiang2333 Do not allow Chinese characters to appear in the code

OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants