alibaba/Sentinel

after gateway flow rule reload ,result of statistics is incorrect

Open

#873 opened on Jun 27, 2019

View on GitHub
 (9 comments) (0 reactions) (0 assignees)Java (23,109 stars) (8,150 forks)batch import
area/flow-controlarea/integrationsgood first issuekind/bug

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(...);

//@Scheduled(fixedDelay = 30*1000)
Set<GatewayFlowRule> gatewayFlowRules = new HashSet<GatewayFlowRule>();
		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

after gateway flow rule reload ,result of statistics is incorrect · alibaba/Sentinel#873 | Good First Issue