Sentinel Support for appending a single rule in the rule manager

nlejzf6q  于 2022-10-19  发布在  其他
关注(0)|答案(3)|浏览(163)

Issue Description

Type: feature request

Describe what happened (or what feature you want)

FlowRuleManager & DegradeRuleManager provide configUpdate() method to update Rules by implements PropertyListener. But, configUpdate() like configLoad() , both of them clear() ConcurrentHashMap first, then putAll() Rules. Why dont provide a method to support add a new Rule into Map? This is necessary in the scenario where rule need to be added dynamically.

Describe what you expected to happen

provide a method like: (eg. in DegradeRuleManager)

public static boolean addRule(DegradeRule rule) {
        if  (null ==rule ) {
            return false;
        }
        return degradeRules.put(rule.getResource(), rule);
    }

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

Tell us your environment

Anything else we need to know?

xpcnnkqh

xpcnnkqh1#

Because the rules are full updated actually.
When add,update or delete a flow rule from dashboard, it push all flow rules to application side, and use FlowRuleManager#loadRules and configUpdate to update all flow rules.

If only push a new rule, boolean addRule(FlowRule) is indeed needed. This may be a good suggestion.

qkf9rpyu

qkf9rpyu2#

In my usage scenario, Rules are not controlled and updated by using Sentinel dashboard, I initialize it and update it by code.
So, I have to add a new Rule only like below:

synchronized (SentinelInitializr.class) {
            List<DegradeRule> rules = DegradeRuleManager.getRules();
            rules.add(rule);
            DegradeRuleManager.loadRules(rules);
        }

but It may also cause concurrency problem.

I will push a PR about this.

w6mmgewl

w6mmgewl3#

Is there any progress?

相关问题