diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java index 836d27b8f5..7cd6f735e6 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java @@ -86,7 +86,7 @@ public MetricWriter(long singleFileSize, int totalFileCount) { if (singleFileSize <= 0 || totalFileCount <= 0) { throw new IllegalArgumentException(); } - RecordLog.info("new MetricWriter, singleFileSize=" + singleFileSize + ", totalFileCount=" + totalFileCount); + RecordLog.info("[MetricWriter] Creating new MetricWriter, singleFileSize=" + singleFileSize + ", totalFileCount=" + totalFileCount); this.baseDir = METRIC_BASE_DIR; File dir = new File(baseDir); if (!dir.exists()) { @@ -100,7 +100,7 @@ public MetricWriter(long singleFileSize, int totalFileCount) { try { this.timeSecondBase = df.parse("1970-01-01 00:00:00").getTime() / 1000; } catch (Exception e) { - RecordLog.info("new MetricWriter error: ", e); + RecordLog.warn("[MetricWriter] Create new MetricWriter error", e); } } @@ -286,9 +286,9 @@ private void removeMoreFiles() throws Exception { String fileName = list.get(i); String indexFile = formIndexFileName(fileName); new File(fileName).delete(); - RecordLog.info("remove metric file: " + fileName); + RecordLog.info("[MetricWriter] Removing metric file: " + fileName); new File(indexFile).delete(); - RecordLog.info("remove metric index file: " + indexFile); + RecordLog.info("[MetricWriter] Removing metric index file: " + indexFile); } } @@ -307,8 +307,8 @@ private void closeAndNewFile(String fileName) throws Exception { ; curMetricIndexFile = new File(idxFile); outIndex = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile, append))); - RecordLog.info("create new metric file: " + fileName); - RecordLog.info("create new metric index file: " + idxFile); + RecordLog.info("[MetricWriter] New metric file created: " + fileName); + RecordLog.info("[MetricWriter] New metric index file created: " + idxFile); } private boolean validSize() throws Exception { diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/property/DynamicSentinelProperty.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/property/DynamicSentinelProperty.java index 3b2bc0cdb6..a72c3d0ccf 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/property/DynamicSentinelProperty.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/property/DynamicSentinelProperty.java @@ -50,7 +50,7 @@ public void updateValue(T newValue) { if (isEqual(value, newValue)) { return; } - RecordLog.info("SentinelProperty, config is real updated to: " + newValue); + RecordLog.info("[DynamicSentinelProperty] Config will be updated to: " + newValue); value = newValue; for (PropertyListener listener : listeners) { diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java index ea7e7a3f1c..9e160623f9 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java @@ -17,13 +17,23 @@ /*** * @author youji.zj + * @author Eric Zhao */ public abstract class AbstractRule implements Rule { - /*** 规则的资源描述 ***/ + /** + * Resource name. + */ private String resource; - /*** 被限制的应用,授权时候为逗号分隔的应用集合,限流时为单个应用 ***/ + /** + *

+ * Application name that will be limited by origin. + * Multiple application name can be separated with comma (','). + *

+ *

The default limitApp is `default`, which means allowing all origin apps.

+ *

For example: limitApp = `appA,appB` will limit requests from appA and appB.

+ */ private String limitApp; public String getResource() { diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/RuleConstant.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/RuleConstant.java index a9208177ba..4ff261103c 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/RuleConstant.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/RuleConstant.java @@ -19,7 +19,7 @@ * @author youji.zj * @author jialiang.linjl */ -public class RuleConstant { +public final class RuleConstant { public static final int FLOW_GRADE_THREAD = 0; public static final int FLOW_GRADE_QPS = 1; @@ -38,4 +38,8 @@ public class RuleConstant { public static final int CONTROL_BEHAVIOR_WARM_UP = 1; public static final int CONTROL_BEHAVIOR_RATE_LIMITER = 2; + public static final String LIMIT_APP_DEFAULT = "default"; + public static final String LIMIT_APP_OTHER = "other"; + + private RuleConstant() {} } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java index 50faef4386..613bde57e1 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java @@ -21,11 +21,11 @@ import java.util.concurrent.ConcurrentHashMap; import com.alibaba.csp.sentinel.log.RecordLog; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.property.DynamicSentinelProperty; import com.alibaba.csp.sentinel.property.PropertyListener; import com.alibaba.csp.sentinel.property.SentinelProperty; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; /** * Manager for authority rules. @@ -115,7 +115,7 @@ private Map> loadAuthorityConf(List l } if (StringUtil.isBlank(rule.getLimitApp())) { - rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT); + rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT); } String identity = rule.getResource(); diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java index ec48942c26..7a79f66c90 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java @@ -28,7 +28,7 @@ import com.alibaba.csp.sentinel.property.SentinelProperty; import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; import com.alibaba.csp.sentinel.slots.block.BlockException; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.util.StringUtil; /*** @@ -150,7 +150,7 @@ private Map> loadDegradeConf(List list) { } if (StringUtil.isBlank(rule.getLimitApp())) { - rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT); + rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT); } String identity = rule.getResource(); diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java index e63f459ab5..5ed7cf15ce 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java @@ -40,12 +40,9 @@ */ public class FlowRule extends AbstractRule { - public static final String LIMIT_APP_DEFAULT = "default"; - public static final String LIMIT_APP_OTHER = "other"; - public FlowRule(){ super(); - setLimitApp(LIMIT_APP_DEFAULT); + setLimitApp(RuleConstant.LIMIT_APP_DEFAULT); } /** @@ -196,7 +193,7 @@ private Node selectNodeByRequesterAndStrategy(String origin, Context context, De return node; } - } else if (LIMIT_APP_DEFAULT.equals(limitApp)) { + } else if (RuleConstant.LIMIT_APP_DEFAULT.equals(limitApp)) { if (strategy == RuleConstant.STRATEGY_DIRECT) { return node.getClusterNode(); } @@ -216,7 +213,7 @@ private Node selectNodeByRequesterAndStrategy(String origin, Context context, De return node; } - } else if (LIMIT_APP_OTHER.equals(limitApp) && FlowRuleManager.isOtherOrigin(origin, getResource())) { + } else if (RuleConstant.LIMIT_APP_OTHER.equals(limitApp) && FlowRuleManager.isOtherOrigin(origin, getResource())) { if (strategy == RuleConstant.STRATEGY_DIRECT) { return context.getOriginNode(); } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleComparator.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleComparator.java index b5d091c141..688bed9692 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleComparator.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleComparator.java @@ -17,6 +17,8 @@ import java.util.Comparator; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; + public class FlowRuleComparator implements Comparator { @Override @@ -30,9 +32,9 @@ public int compare(FlowRule o1, FlowRule o2) { return 0; } - if (FlowRule.LIMIT_APP_DEFAULT.equals(o1.getLimitApp())) { + if (RuleConstant.LIMIT_APP_DEFAULT.equals(o1.getLimitApp())) { return 1; - } else if (FlowRule.LIMIT_APP_DEFAULT.equals(o2.getLimitApp())) { + } else if (RuleConstant.LIMIT_APP_DEFAULT.equals(o2.getLimitApp())) { return -1; } else { return 0; diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java index 3f719e6c23..68295fc14f 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java @@ -114,7 +114,7 @@ private static Map> loadFlowConf(List list) { continue; } if (StringUtil.isBlank(rule.getLimitApp())) { - rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT); + rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT); } Controller rater = new DefaultController(rule.getCount(), rule.getGrade()); diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java index d5a8ccc7d9..f25155a100 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java @@ -77,7 +77,7 @@ public class SystemRuleManager { private static volatile boolean maxRtIsSet = false; private static volatile boolean maxThreadIsSet = false; - static AtomicBoolean checkSystemStatus = new AtomicBoolean(false); + private static AtomicBoolean checkSystemStatus = new AtomicBoolean(false); private static SystemStatusListener statusListener = null; private final static SystemPropertyListener listener = new SystemPropertyListener(); @@ -185,11 +185,9 @@ public void configUpdate(List rules) { checkSystemStatus.set(false); } - RecordLog.info("current system system status : " + checkSystemStatus.get()); - RecordLog.info("current highestSystemLoad status : " + highestSystemLoad); - RecordLog.info("current maxRt : " + maxRt); - RecordLog.info("current maxThread : " + maxThread); - RecordLog.info("current qps : " + qps); + + RecordLog.info(String.format("[SystemRuleManager] Current system check status: %s, highestSystemLoad: " + + highestSystemLoad + ", " + "maxRt: %d, maxThread: %d, maxQps: " + qps, checkSystemStatus.get(), maxRt, maxThread)); } protected void restoreSetting() { @@ -222,9 +220,8 @@ public static void setHighestSystemLoad(double highestSystemLoad) { } public static void loadSystemConf(SystemRule rule) { - boolean checkStatus = false; - // 首先判断是否有效 + // Check if it's valid. if (rule.getHighestSystemLoad() >= 0) { highestSystemLoad = Math.min(highestSystemLoad, rule.getHighestSystemLoad()); @@ -260,9 +257,8 @@ public static void loadSystemConf(SystemRule rule) { * @throws BlockException when any system rule's threshold is exceeded. */ public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockException { - - // 确定开关开了 - if (checkSystemStatus.get() == false) { + // Ensure the checking switch is on. + if (!checkSystemStatus.get()) { return; } @@ -288,7 +284,7 @@ public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockExce throw new SystemBlockException(resourceWrapper.getName(), "rt"); } - // 完全按照RT,BBR算法来 + // BBR algorithm. if (highestSystemLoadIsSet && getCurrentSystemAvgLoad() > highestSystemLoad) { if (currentThread > 1 && currentThread > Constants.ENTRY_NODE.maxSuccessQps() * Constants.ENTRY_NODE.minRt() / 1000) { @@ -301,5 +297,4 @@ public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockExce public static double getCurrentSystemAvgLoad() { return statusListener.getSystemAverageLoad(); } - } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/AppNameUtil.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/AppNameUtil.java index 7a182bae5f..0cde3e85d2 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/AppNameUtil.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/AppNameUtil.java @@ -57,7 +57,7 @@ private AppNameUtil() { static { resolveAppName(); - RecordLog.info("app name resolved: " + appName); + RecordLog.info("App name resolved: " + appName); } public static void resolveAppName() { diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java index 4700ddd70f..b10b260a7b 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java @@ -26,7 +26,7 @@ import com.alibaba.csp.sentinel.property.DynamicSentinelProperty; import com.alibaba.csp.sentinel.property.PropertyListener; import com.alibaba.csp.sentinel.property.SentinelProperty; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.util.StringUtil; /** @@ -169,7 +169,7 @@ private Map> aggregateHotParamRules(List