소스 검색

Enhance log and null check for rule managers

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 년 전
부모
커밋
d142a07a39
2개의 변경된 파일19개의 추가작업 그리고 9개의 파일을 삭제
  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 파일 보기

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

@Override
@@ -132,16 +133,22 @@ public class DegradeRuleManager {
degradeRules.clear();
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) {
if (list == null) {
return null;
}
Map<String, List<DegradeRule>> newRuleMap = new ConcurrentHashMap<String, List<DegradeRule>>();

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

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())) {
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 파일 보기

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

public class FlowRuleManager {

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) {
Map<String, List<FlowRule>> newRuleMap = new ConcurrentHashMap<String, List<FlowRule>>();

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

for (FlowRule rule : list) {
if (!isValid(rule)) {
if (!isValidRule(rule)) {
RecordLog.warn("[FlowRuleManager] Ignoring invalid flow rule when loading new flow rules: " + rule);
continue;
}
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());
}
}

Loading…
취소
저장