One minute exception number degradation policy failed
Issue Description
provider:
@Override
public User testDegrCount(Long userId) throws InterruptedException {
Thread.sleep(500);
if (userId % 10 == 0) {
throw new RpcException("每500毫秒一个请求,一分钟可以处理120个请求,阈值设置为5,每10个请求抛出一个异常,50个请求之后异常数达到阈值,一分钟之内的请求将被降级");
}
return new User(100L, "三爷");
}
consumer:
public void testDegrCount() {
for (int i = 1; i <= 300; i++) {
try {
log.info("{} : {} ", i, userService.testDegrCount(Long.valueOf(i)).getUserName());
} catch (Exception e) {
e.printStackTrace();
log.error("第 {} 个限流失败", i);
}
}
}
降级规则如下,这里的资源名称我做了特殊处理
[{"app":"titans-provider3","count":5.0,"cut":false,"grade":2,"key":"1548378133752","limitApp":"titans-consumer","passCount":0,"resource":"@[email protected]","timeWindow":10}]
Describe what happened (or what feature you want)
调用服务的时候,没有按照预期进行降级。服务一直都可以调用成功,SentinelDubboProviderFilter 中的 Tracer.trace(result.getException()) 每10个请求会被执行一次
Describe what you expected to happen
预期 50个请求之后异常数达到阈值,一分钟之内的请求将被降级
How to reproduce it (as minimally and precisely as possible)
在我本地,按照这种方式调用,一直都可以重现
Tell us your environment
- Windows 10
- JDK 1.8
Anything else we need to know?
Hi @spilledyear, we detect non-English characters in the issue. This comment is an auto translation from @sentinel-bot to help other users to understand this issue. We encourage you to describe your issue in English which is more friendly to other users.
One minute exception number degradation policy failed
Issue Description
provider
@Override
public User testDegrCount(Long userId) throws InterruptedException {
Thread.sleep(500);
if (userId % 10 == 0) {
Throw new RpcException("A request per 500 milliseconds, 120 requests can be processed in one minute, the threshold is set to 5, an exception is thrown every 10 requests, the number of exceptions reaches the threshold after 50 requests, and requests within one minute will be Downgrade"); }
Return new User(100L, "三爷"); }
consumer
public void testDegrCount() {
for (int i = 1; i <= 300; i++) {
try {
log.info("{} : {} ", i, userService.testDegrCount(Long.valueOf(i)).getUserName());
} catch (Exception e) {
e.printStackTrace();
Log.error("{}th limit flow failure", i); }
}
}
The downgrade rules are as follows, I have made special treatment for the resource names here.
[{"app":"titans-provider3","count":5.0,"cut":false,"grade":2,"key":"1548378133752","limitApp":"titans-consumer","passCount":0,"resource":"@[email protected]","timeWindow":10}]
Describe what happened (or what feature you want)
When the service was called, it was not downgraded as expected. The service can always be called successfully, in SentinelDubboProviderFilter Tracer.trace(result.getException()); Every 10 requests will be executed once
Describe what you expected to happen
It is expected that the number of exceptions will reach the threshold after 50 requests, and the request within one minute will be downgraded.
How to reproduce it (as minimally and precisely as possible)
In my local, calling in this way, can always be reproduced
Tell us your environment
win10 jdk 1.8
Anything else we need to know?
你的provider中testDegrCount方法抛出异常是业务逻辑本身抛出的,是不会统计到sentinel内部exception number的,如果需要将这种异常统计到sentinel内部exception number中,可使用Tracer.trace(Throwable e)来做,也就是在你代码consumer中testDegrCount方法捕获异常后,使用Tracer.trace(Throwable e)就行了。可以参考sentinel demo中的ExceptionCountDegradeDemo.
你的provider中testDegrCount方法抛出异常是业务逻辑本身抛出的,是不会统计到sentinel内部exception number的,如果需要将这种异常统计到sentinel内部exception number中,可使用
Tracer.trace(Throwable e)来做,也就是在你代码consumer中testDegrCount方法捕获异常后,使用Tracer.trace(Throwable e)就行了。可以参考sentinel demo中的ExceptionCountDegradeDemo.
我有在ProviderFilter中 trace 这个异常的,昨天问了群里得大佬,异常比例和一分钟异常数 只能对具体的方法生效,而我的规则是加在接口上的,所以没有生效,目前这个问题已经解决了