alibaba / alibaba/Sentinel

after gateway flow rule reload ,result of statistics is incorrect

Open
#873 9 comments 0 reactions 0 assignees View on GitHub
area/flow-control area/integrations good first issue kind/bug
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue description

sentinel-gateway-adapter , configed the FlowRules' resource with routeId.
then i added two or more rules in a same routeId,
these time window were setIntervalSec(60).setCount(2) ,
setIntervalSec(3600).setCount(5) and so on

The first two times, the demo executed successfully and the third time threw the blockException,

then i GatewayRuleManager.loadRules(...), //per 30s scheduled

at the time I request the demo and suppose throw exception too, but it executed successfully again.

I repeated the action several times, got the number of setIntervalSec(3600).setCount(5),
contineu repeat the operation above , even thougt i request the demo more than 5 times per hour, it didn't throw exception sometimes after loadRules(...);

```java
//@Scheduled(fixedDelay = 30*1000)
Set gatewayFlowRules = new HashSet();
gatewayFlowRules.add(new GatewayFlowRule(config.getRouteId())
.setCount(1)
.setIntervalSec(1)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_HEADER)
.setFieldName(fopFluidControlPo.getFluidId()+"-SEC") )
);
gatewayFlowRules.add(new GatewayFlowRule(config.getRouteId())
.setCount(2)
.setIntervalSec(60)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_HEADER)
.setFieldName(fopFluidControlPo.getFluidId()+"-MIN") )
);
gatewayFlowRules.add(new GatewayFlowRule(config.getRouteId())
.setCount(3)
.setIntervalSec(3600)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_HEADER)
.setFieldName(fopFluidControlPo.getFluidId()+"-HOUR") )
);
gatewayFlowRules.add(new GatewayFlowRule(config.getRouteId())
.setCount(4)
.setIntervalSec(43200)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_HEADER)
.setFieldName(fopFluidControlPo.getFluidId()+"-DAY") )
);
DegradeRuleManager.loadRules(gatewayFlowRules);
```

## Environment

SpringCloudGateway Greenwich.SR1
SpringBoot 2.1.3.RELEASE
sentinel-spring-cloud-gateway-adapter 1.6.2

## Chinese description:

英文不好,所以觉得还是用中文再说一下,就是如上所述根据不同的时间窗口,配置了不同的流控次数,但是测试的时候,如果不重新加载规则,基本上一切正常(除了超过流控次数时抛出的Exception经常比较混乱,比如同时超过了每分钟和小时的次数,抛出异常所带的rule是随机的,不重要),但是如果在不断请求的过程中,重新加载规则,那个按分钟流控的就会在规则加载完成之后失效,即请求后重新加载规则,此时距离上次请求未到1分钟,依然可以通过流控;更重要的是,如此多试几次之后,已经到达了每小时的流控次数,但是只要重新加载规则,竟然经常还可以继续请求未抛出异常(有时也会抛错),然后每次加载都是上述情况,只要设置定时加载规则,每次加载完后请求,结果都是不一定的。OVER

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the described behavior with the Sentinel gateway adapter versions and the multi-window GatewayFlowRule example. Trace GatewayRuleManager.loadRules(...) during repeated requests and compare statistics before and after reload. Done means reloading rules does not incorrectly reset or bypass active minute- and hour-window limits, with regression coverage for the reported sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.