在"慢调用比例"的降级规则配置下,抛出的DegradeException被 限流的方法捕获,而非降级

public class SentinelExceptionHandler { public static Response handleBlock(Map<String, Object> params, BlockException e){ log.error("SentinelExceptionHandler HandleBlock",e); //在不是抛出异常的情况下(rt时间长),导致抛出的DegradeException被 限流的方法捕获 if(e instanceof DegradeException){ return Response.error(ResultCode.FALLBACK_ERROR,ExceptionUtils.getStackTrace(e)); }else{ return Response.error(ResultCode.LIMIT_ERROR,ExceptionUtils.getStackTrace(e)); } }

public static Response handleFallback(Map<String, Object> params,Throwable e){
    log.error("SentinelExceptionHandler handleFallback",e);
    return Response.error(ResultCode.FALLBACK_ERROR, ExceptionUtils.getStackTrace(e));
}

暂时这样解决的,不知道是不是bug,有谁遇到相同的问题吗?

spring-cloud-starter-alibaba-sentinel ,2.2.3-RELEASE sentinel-core, 1.8.0

@SentinelResource(value = "demo-list",blockHandlerClass= SentinelExceptionHandler.class,fallbackClass = SentinelExceptionHandler.class, blockHandler = "handleBlock",fallback = "handleFallback") public Response list(@RequestParam Map<String, Object> params){ log.info("demo/demo/list invoke ------------------------------"); PageResult pageResult = demoService.queryPage(params); return Response.success(pageResult); }

@Slf4j public class SentinelExceptionHandler { public static Response handleBlock(Map<String, Object> params, BlockException e){ log.error("SentinelExceptionHandler HandleBlock",e); //在不是抛出异常的情况下(rt时间长),抛出的DegradeException被 限流的方法捕获 //todo https://github.com/alibaba/Sentinel/issues/1801 if(e instanceof DegradeException){ return Response.error(ResultCode.FALLBACK_ERROR,ExceptionUtils.getStackTrace(e)); }else{ return Response.error(ResultCode.LIMIT_ERROR,ExceptionUtils.getStackTrace(e)); } }

public static Response handleFallback(Map<String, Object> params,Throwable e){
    log.error("SentinelExceptionHandler handleFallback",e);
    return Response.error(ResultCode.FALLBACK_ERROR, ExceptionUtils.getStackTrace(e));
}

}

原提问者GitHub用户zh69183787

展开
收起
学习娃 2023-05-19 15:40:29 77 分享 版权
1 条回答
写回答
取消 提交回答
  • blockHandler 用于专门处理被 Sentinel 流控、熔断的情况,而 fallback 主要针对业务异常。

    原回答者GitHub用户sczyh30

    2023-05-19 20:48:26
    赞同 展开评论
问答分类:
问答地址:

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

还有其他疑问?
咨询AI助理