alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.2k stars 7.97k forks source link

Circuit breaking by parameters #863

Open tonfay opened 5 years ago

tonfay commented 5 years ago

Whether service degradation for automatic discovery parameters can be done

wchswchs commented 5 years ago

Could you provide more details?

sczyh30 commented 5 years ago

Hi, could you please illustrate your requirement?

tonfay commented 5 years ago

感谢alibaba 对sentinel的开源贡献! 正文: 例: A访问B项目,是否对接口的参数=1进行自动熔断,而非整个方法熔断降级 A访问B项目的B1接口,参数=1 业务正常,参数=2 业务异常.如果对B1资源开启自动降级规则,则无论参数为1或2都会被降级. 问: sentinel是否支持只对异常参数的方法进行降级处理呢?

wchswchs commented 5 years ago

I'd like to ask you why not throw custom biz Exception instead of flag to recognize the service status.

wchswchs commented 5 years ago

And could you give the scenario in detail? For example: param is orderStatus, value 1 for success, value 0 for failure.

tonfay commented 5 years ago

@wchswchs 你好 我这边有一个这样的业务,对车机下发指令,车机终端的信号可能并不是很好. 下发指令就会有发生超时的情况,我对下发指令这里做了一个微服务接口供外部使用. 例: 对这个接口开启自动降级策略(异常数>=1则触发,持续时长为1min) 接口参数为deviceNo 当调用接口deviceNo=0001时 ,下发成功. 当调用接口deviceNo=0002 出现超时情况,此时触发接口的降级策略 当调用接口deviceNo=0003,接口已自动降级,则不对车机终端进行指令下发动作.

目标: 当调用接口deviceNo=0003时 ,应在这1min内,只要参数为0003都应触发服务降级策略.而0003以外的参数是不受到影响的.

wchswchs commented 5 years ago

I see, but I don't understand why keep the exception for 1 mins, it shouldn't keep problem for a long time, and Sentinel provide the strategy for auto degrade and recovery, you can refer to https://github.com/alibaba/Sentinel/wiki/%E7%86%94%E6%96%AD%E9%99%8D%E7%BA%A7.

tonfay commented 5 years ago

降级周期只是个时间问题而已,我不关心时间的问题. sentinel 自动降级,是对方法或代码块级别的,我的问题是,是否能对参数进行自动降级策略. 麻烦您请多关注下问题.您也能更准确的帮助我解决问题.感谢!

wchswchs commented 5 years ago

降级周期只是个时间问题而已,我不关心时间的问题. sentinel 自动降级,是对方法或代码块级别的,我的问题是,是否能对参数进行自动降级策略. 麻烦您请多关注下问题.您也能更准确的帮助我解决问题.感谢!

I understand your meaning, you want to return the terminal device status by wrapping a service, I think you can get your service status by calling the metric api for the service. But maybe we haven't the degrade metric to record. Then I think we can add this api to get the service degrade metrics.

wchswchs commented 5 years ago

You can try to refer to this wiki: https://github.com/alibaba/Sentinel/wiki/%E5%AE%9E%E6%97%B6%E7%9B%91%E6%8E%A7, I'm not sure whether it can help you.

tonfay commented 5 years ago

It's not resolved But thank you very much @wchswchs

wchswchs commented 5 years ago

It's not resolved But thank you very much @wchswchs

Ok, Then we can add this api to get the service degrade metrics.

tonfay commented 5 years ago

It's not resolved But thank you very much @wchswchs

Ok, Then we can add this api to get the service degrade metrics.

I know that, but my requirements are parameters in the corresponding API.

wchswchs commented 5 years ago

Maybe I think you can do refer to the logic below:

  1. if deviceNo=0001, return ok by calling your service because the sentinel degrade metrics api return 0001 is ok.
  2. if deviceNo=0002, trigger fallback by calling your service because the sentinel degrade metrics api return 0002 is timeout.
  3. if deviceNo=0003, return null by calling your service because the sentinel degrade metrics api return 0003 has degraded.
linlinisme commented 5 years ago

I don't think it's a good practice to downgrade based on response parameters. The reasons are as follows:

  1. If the response code represents an abnormal condition, you can throw a corresponding exception. With such a simple process, sentinel can be downgraded by exception statistics.
  2. I don't think that sentinel can monitor the response of other services within the service. If it is feasible, it may be quite complicated, at least there will be corresponding loss in performance. It's better to simply wrap an exception.
  3. I think that sentinel can be optimized to do fine management for exceptions. For example, ignore some types of exceptions, because business exceptions are sometimes just unsuccessful on behalf of this request, not a real exception. Now, in addition to downgrading the total anomaly and abnormal rate. It can also be handled for a particular exception, such as some fatal exceptions, which should be downgraded as soon as they occur. Optimization suggestions I will mention an issue to describe specifically.
tonfay commented 5 years ago

@wchswchs 你好 我这边有一个这样的业务,对车机下发指令,车机终端的信号可能并不是很好. 下发指令就会有发生超时的情况,我对下发指令这里做了一个微服务接口供外部使用. 例: 对这个接口开启自动降级策略(异常数>=1则触发,持续时长为1min) 接口参数为deviceNo 当调用接口deviceNo=0001时 ,下发成功. 当调用接口deviceNo=0002 出现超时情况,此时触发接口的降级策略 当调用接口deviceNo=0003,接口已自动降级,则不对车机终端进行指令下发动作.

目标: 当调用接口deviceNo=0003时 ,应在这1min内,只要参数为0003都应触发服务降级策略.而0003以外的参数是不受到影响的.

请各位针对此问题进行讨论.否则我们会很耽误时间来聊其它问题.

cdfive commented 5 years ago

Sentinel支持热点参数限流,参考 https://github.com/alibaba/Sentinel/wiki/热点参数限流#热点参数规则 但模式是QPS模式。

你说这个感觉有点像是参数+异常降级结合的形式。

目标: 当调用接口deviceNo=0003时 ,应在这1min内,只要参数为0003都应触发服务降级策略.而0003以外的参数是不受到影响的.

这里的deviceNo=0003是不是写错了,是0002吧? 因为看你前面的说的,好像是仅对异常的参数,0003是新的参数啊

tonfay commented 5 years ago

Sentinel支持热点参数限流,参考 https://github.com/alibaba/Sentinel/wiki/热点参数限流#热点参数规则 但模式是QPS模式。

你说这个感觉有点像是参数+异常降级结合的形式。

目标: 当调用接口deviceNo=0003时 ,应在这1min内,只要参数为0003都应触发服务降级策略.而0003以外的参数是不受到影响的.

这里的deviceNo=0003是不是写错了,是0002吧? 因为看你前面的说的,好像是仅对异常的参数,0003是新的参数啊

你好,很高兴您的回答, 参数+异常降级结合形式.我看sentinel 当前是只支持参数+流控, 还没有参数+异常降级的策略. 我的了解有错误嘛?

zebperfect commented 3 years ago

I also faced the same problem, Looking forward to progress.