Support limit origin for cluster flow rules | 集群限流规则执行时未区分来源应用
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
配置N条资源名相同的集群模式限流规则,无论来源应用命中规则,所有规则都会调用一次TokenServer
目前的实现版本是否有什么特殊原因?
### Describe what happened (or what feature you want)
```java
public class FlowRuleChecker {
public void checkFlow(Function> ruleProvider, ResourceWrapper resource,
Context context, DefaultNode node, int count, boolean prioritized) throws BlockException {
if (ruleProvider == null || resource == null) {
return;
}
Collection rules = ruleProvider.apply(resource.getName());
if (rules != null) {
for (FlowRule rule : rules) {
if (!canPassCheck(rule, context, node, count, prioritized)) {
throw new FlowException(rule.getLimitApp(), rule);
}
}
}
}
......
public boolean canPassCheck(/*@NonNull*/ FlowRule rule, Context context, DefaultNode node, int acquireCount,
boolean prioritized) {
String limitApp = rule.getLimitApp();
if (limitApp == null) {
return true;
}
if (rule.isClusterMode()) {
return passClusterCheck(rule, context, node, acquireCount, prioritized);
}
return passLocalCheck(rule, context, node, acquireCount, prioritized);
}
......
```
### Describe what you expected to happen
```java
public class FlowRuleChecker {
public void checkFlow(Function> ruleProvider, ResourceWrapper resource,
Context context, DefaultNode node, int count, boolean prioritized) throws BlockException {
if (ruleProvider == null || resource == null) {
return;
}
Collection rules = ruleProvider.apply(resource.getName());
if (rules != null) {
for (FlowRule rule : rules) {
if (!canPassCheck(rule, context, node, count, prioritized)) {
throw new FlowException(rule.getLimitApp(), rule);
}
}
}
}
......
public boolean canPassCheck(/*@NonNull*/ FlowRule rule, Context context, DefaultNode node, int acquireCount,
boolean prioritized) {
String limitApp = rule.getLimitApp();
if (limitApp == null) {
return true;
}
if (rule.isClusterMode()) {
// todo 集群模式也判断按照来源应用判断下应执行的规则
// cluster mod should also check limitapp of rule with origin
String origin = context.getOrigin();
boolean needCheck = false;
if (limitApp.equals(origin) && filterOrigin(origin)) {
needCheck = true;
} else if (RuleConstant.LIMIT_APP_DEFAULT.equals(limitApp)) {
needCheck = true;
} else if (RuleConstant.LIMIT_APP_OTHER.equals(limitApp)
&& FlowRuleManager.isOtherOrigin(origin, rule.getResource())) {
needCheck = true;
}
return needCheck ? passClusterCheck(rule, context, node, acquireCount, prioritized) : true;
}
return passLocalCheck(rule, context, node, acquireCount, prioritized);
}
......
```
### How to reproduce it (as minimally and precisely as possible)
无
### Tell us your environment
无
### Anything else we need to know?
无
Contributor guide
Research direction
Start at FlowRuleChecker.checkFlow and canPassCheck, then trace passClusterCheck and the existing origin helpers in FlowRuleManager. Compare the current cluster-rule path with the expected origin matching shown in the issue. Done means only the applicable cluster rule invokes TokenServer, while unrelated rules are skipped; no test or reproduction is provided in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100