Quellcode durchsuchen

Enhance log and null check for rule managers

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao vor 6 Jahren
Ursprung
Commit
d142a07a39
2 geänderte Dateien mit 19 neuen und 9 gelöschten Zeilen
  1. +15
    -5
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java
  2. +4
    -4
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java

+ 15
- 5
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java Datei anzeigen

@@ -56,6 +56,7 @@ public class DegradeRuleManager {
*/ */
public static void register2Property(SentinelProperty<List<DegradeRule>> property) { public static void register2Property(SentinelProperty<List<DegradeRule>> property) {
synchronized (listener) { synchronized (listener) {
RecordLog.info("[DegradeRuleManager] Registering new property to degrade rule manager");
currentProperty.removeListener(listener); currentProperty.removeListener(listener);
property.addListener(listener); property.addListener(listener);
currentProperty = property; currentProperty = property;
@@ -122,7 +123,7 @@ public class DegradeRuleManager {
degradeRules.clear(); degradeRules.clear();
degradeRules.putAll(rules); degradeRules.putAll(rules);
} }
RecordLog.info("receive degrade config: " + degradeRules);
RecordLog.info("[DegradeRuleManager] Degrade rules received: " + degradeRules);
} }


@Override @Override
@@ -132,16 +133,22 @@ public class DegradeRuleManager {
degradeRules.clear(); degradeRules.clear();
degradeRules.putAll(rules); degradeRules.putAll(rules);
} }
RecordLog.info("init degrade config: " + degradeRules);
RecordLog.info("[DegradeRuleManager] Degrade rules loaded: " + degradeRules);
} }


private Map<String, List<DegradeRule>> loadDegradeConf(List<DegradeRule> list) { private Map<String, List<DegradeRule>> loadDegradeConf(List<DegradeRule> list) {
if (list == null) {
return null;
}
Map<String, List<DegradeRule>> newRuleMap = new ConcurrentHashMap<String, List<DegradeRule>>(); Map<String, List<DegradeRule>> newRuleMap = new ConcurrentHashMap<String, List<DegradeRule>>();


if (list == null || list.isEmpty()) {
return newRuleMap;
}

for (DegradeRule rule : list) { for (DegradeRule rule : list) {
if (!isValidRule(rule)) {
RecordLog.warn("[DegradeRuleManager] Ignoring invalid degrade rule when loading new rules: " + rule);
continue;
}

if (StringUtil.isBlank(rule.getLimitApp())) { if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT); rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
} }
@@ -160,4 +167,7 @@ public class DegradeRuleManager {


} }


private static boolean isValidRule(DegradeRule rule) {
return rule != null && !StringUtil.isBlank(rule.getResource()) && rule.getCount() >= 0;
}
} }

+ 4
- 4
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java Datei anzeigen

@@ -51,7 +51,6 @@ import com.alibaba.csp.sentinel.slots.block.flow.controller.WarmUpController;
* *
* @author jialiang.linjl * @author jialiang.linjl
*/ */

public class FlowRuleManager { public class FlowRuleManager {


private static final Map<String, List<FlowRule>> flowRules = new ConcurrentHashMap<String, List<FlowRule>>(); private static final Map<String, List<FlowRule>> flowRules = new ConcurrentHashMap<String, List<FlowRule>>();
@@ -105,12 +104,13 @@ public class FlowRuleManager {
private static Map<String, List<FlowRule>> loadFlowConf(List<FlowRule> list) { private static Map<String, List<FlowRule>> loadFlowConf(List<FlowRule> list) {
Map<String, List<FlowRule>> newRuleMap = new ConcurrentHashMap<String, List<FlowRule>>(); Map<String, List<FlowRule>> newRuleMap = new ConcurrentHashMap<String, List<FlowRule>>();


if (list == null) {
if (list == null || list.isEmpty()) {
return newRuleMap; return newRuleMap;
} }


for (FlowRule rule : list) { for (FlowRule rule : list) {
if (!isValid(rule)) {
if (!isValidRule(rule)) {
RecordLog.warn("[FlowRuleManager] Ignoring invalid flow rule when loading new flow rules: " + rule);
continue; continue;
} }
if (StringUtil.isBlank(rule.getLimitApp())) { if (StringUtil.isBlank(rule.getLimitApp())) {
@@ -202,7 +202,7 @@ public class FlowRuleManager {


} }


private static boolean isValid(FlowRule rule) {
private static boolean isValidRule(FlowRule rule) {
return rule != null && !StringUtil.isBlank(rule.getResource()); return rule != null && !StringUtil.isBlank(rule.getResource());
} }
} }

Laden…
Abbrechen
Speichern