Sentinel [Feature] Support setting the universal default rule for all resources

qmelpv7a  于 2021-11-29  发布在  Java
关注(0)|答案(19)|浏览(454)

据了解,目前的规则只能针对某个资源进行设置。希望提供支持全局规则设置,或资源名可通配符表达。
应用场景:所有资源默认错误率达到多少自动降级,有特殊需求的资源另外设置。

ogq8wdun

ogq8wdun1#

How about this? Take downgrade as an example, We add default rule when build process chain.

public ProcessorSlotChain build(ResourceWrapper resource) {
        ProcessorSlotChain chain = new DefaultProcessorSlotChain();
        chain.addLast(new NodeSelectorSlot());
        chain.addLast(new ClusterBuilderSlot());
        chain.addLast(new LogSlot());
        chain.addLast(new StatisticSlot());
        chain.addLast(new SystemSlot());
        chain.addLast(new AuthoritySlot());
        chain.addLast(new FlowSlot());
        chain.addLast(new DegradeSlot(resource));

        return chain;
    }
public DegradeSlot(ResourceWrapper resource){
        DegradeRuleManager.setDefaultDegrade(resource.getName());
   }
public static void setDefaultDegrade(String resource) {
        if (degradeRules.get(resource) == null && SentinelConfig.globalRuleOpen()) {
            Set<DegradeRule> newRules = new HashSet<>(1);
            newRules.add(createDefaultRule(resource));
            setRulesForResource(resource, newRules);
        }
    }
xzabzqsa

xzabzqsa2#

上古贴 [捂脸] ,惊喜的发现还没有fixed

lyr7nygr

lyr7nygr6#

yeah,we plan use sentinel to replace hystrix, the default hystrix settings can meet our system requirements,but find sentinel cannot set it

lmvvr0a8

lmvvr0a87#

1,全局规则配置,如果对一个api资源用户自定义配置了规则优先执行这个
目前有个需求是通过gateway做路由,因为业务中需要拼装数据下载文件,使用了r4j实现熔断是针对整个服务的,改用sentinel,但发现规则不是根据api最小资源来执行优先级的,能不能api分组规则定义的是qps是1,具体api定义规则qps是3,不管是定义多少只要定义了最小资源api级别的按它来执行?

wydwbb8l

wydwbb8l8#

结合feign 对下游业务做限流,也很有必有有针对某一个服务的限流

f87krz0w

f87krz0w9#

like hystrix.command.default.*

bvpmtnay

bvpmtnay10#

the PR PR #956 I had closed, And I push a new PR #966

vatpfxk5

vatpfxk511#

很好的建议,对减少用户规则设置的工作量有很大帮助。

我们不支持规则通配符主要有两个考虑:

  • 一个是统计效率,模糊匹配会增加计算量;
  • 一个是规则的明确性,每一条规则的作用范围应该是明确的,避免误杀其他资源。

全局默认降级规则的想法不错,可以再深入讨论一下,比如把全局规则存储在哪里、跟用户的规则是什么关系等等。

cl25kdpy

cl25kdpy12#

Thanks for reminding. Flow Rule's TrafficControllers some are stateless, some not..... What trouble is DegradeRule, it is not totally stateless . Because cut state is global share...... The design is really should be carefully considered..

5hcedyr0

5hcedyr013#

In fact, each rule may have its own additional statistic data (i.e. it's not stateless: for FlowRule it's handled in the inner TrafficController, and for DegradeRule the data is in the rule directly due to legacy design). Thepure rule entitycan be only single in global scope, but its relevant data should be handled separately. This should be carefully considered.

zujrkrfu

zujrkrfu14#

emm.... It does not matter. We can tread it like "global default rule", We can still implement in "global manager". I think all the rules should share same "global rule", it is unnecessary to**a default rule will be created and added for the resource. As soon as there are user-defined rules for this resource, the default rule will be deprecated.**First we can save memory, Second We keep *RuleManager original logic.

xytpbqjk

xytpbqjk15#

@linlinisme The issue title might be confusing... In this thread, we were actually discussing the universal default rule for all resources. That is, when a new resource is created, if there're no rules for this resource, then a default rule will be created and added for the resource. As soon as there are user-defined rules for this resource, the default rule will be deprecated.

The "global rule" (aka. for each type it has the only one and it represents all resources) is also useful in some scenarios. We could discuss with it (and the PR #956) in a new issue :)

相关问题