alibaba / alibaba/Sentinel

sentinel-dubbo-adapter 1.8.2 consumer端 SentinelRpcException 非业务异常也被统计

Open
#2,464 5 comments 0 reactions 0 assignees View on GitHub
area/integrations good first issue
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue Description

Type: *bug report* or *feature request*

### Describe what happened (or what feature you want)
现象:
使用1.8.2版本的sentinel-dubbo-adapter模块,非业务异常(Sentinel因为熔断或者限流的异常)被消费者SentinelDubboConsumerFilter记录成为了一次业务异常,逻辑错误。
原因:
在sentinel-dubbo-adapter模块利用了Dubbo的Filter机制,包裹了一层。先看SentinelDubboProviderFilter的逻辑,我们设想提供者端触发了限流,则会抛出BlockException,但是返回给消费者的异常并不是BlockException,而是包裹成为了SentinelRpcException。
![image](https://user-images.githubusercontent.com/38968098/143555602-3a4ed9a5-5b0a-4c7c-a8c2-5ee1ac8b3ec1.png)
![image](https://user-images.githubusercontent.com/38968098/143555712-ec81cc81-95e7-42d2-83de-c5cc1c8f5cd2.png)

而在SentinelDubboConsumerFilter端,result.hasException() 则会为true,触发Tracer.traceEntry() 逻辑,这里面的shouldTrace()方法只判断了排除BlockException,而SentinelRpcException未被排除,即会被记录为一次业务异常。会造成consumer端熔断判断的失误。
![image](https://user-images.githubusercontent.com/38968098/143556082-23e8601c-1117-4e2b-98f9-40c81edf2409.png)

### Describe what you expected to happen
在Tracer.traceEntry()逻辑中,也要去掉SentinelRpcException,遇到这个异常 则不记录,和BlockException同等对待。
解决方案:
1.可自定义一个init接口,Sentinel启动初始化时调用Tracer.setExceptionsToIgnore() 把SentinelRpcException加进去
2.因为DubboFilter类在dubbo启动refer或者export时会被加载,可在filter的静态块调用Tracer.setExceptionsToIgnore()把SentinelRpcException加进去

### How to reproduce it (as minimally and precisely as possible)

1. 设置2个dubbo服务,A,B。A调用B。
2. 给A设置异常数熔断规则,给B设置限流规则。保证业务无异常。
3. 让B触发限流
4. A会被熔断

### Tell us your environment
Win10 ,Dubbo2.6.5,Sentinel1.8.2,Nacos2.0.3

### Anything else we need to know?

why wrap this exception?
![image](https://user-images.githubusercontent.com/38968098/143794206-ee2cacd2-76b9-4e9b-8be9-afb3b882d06c.png)

Contributor guide

Open the contributing guide

Research direction

Start with sentinel-dubbo-adapter's SentinelDubboConsumerFilter and Tracer.traceEntry()/shouldTrace(), then inspect how SentinelDubboProviderFilter wraps BlockException as SentinelRpcException. Reproduce the two-service Dubbo scenario described in the issue and verify that provider-side rate-limit exceptions are not counted as consumer business exceptions; add regression coverage if the relevant test location is found.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.