diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java index 1c8e8d22..c7d56d1c 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java @@ -15,18 +15,19 @@ */ package com.alibaba.csp.sentinel; -import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.node.ClusterNode; import com.alibaba.csp.sentinel.node.DefaultNode; import com.alibaba.csp.sentinel.node.EntranceNode; import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper; -import com.alibaba.csp.sentinel.slots.system.SystemRule; import com.alibaba.csp.sentinel.util.VersionUtil; /** + * Universal constants of Sentinel. + * * @author qinan.qn * @author youji.zj * @author jialiang.linjl + * @author Eric Zhao */ public final class Constants { @@ -60,16 +61,10 @@ public final class Constants { new ClusterNode(ROOT_ID, ResourceTypeConstants.COMMON)); /** - * Global statistic node for inbound traffic. Usually used for {@link SystemRule} checking. + * Global statistic node for inbound traffic. Usually used for {@code SystemRule} checking. */ public final static ClusterNode ENTRY_NODE = new ClusterNode(TOTAL_IN_RESOURCE_NAME, ResourceTypeConstants.COMMON); - /** - * Response time that exceeds TIME_DROP_VALVE will be calculated as TIME_DROP_VALVE. Default value is 4900 ms. - * It can be configured by property file or JVM parameter via {@code -Dcsp.sentinel.statistic.max.rt=xxx}. - */ - public static final int TIME_DROP_VALVE = SentinelConfig.statisticMaxRt(); - /** * The global switch for Sentinel. */ diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/config/SentinelConfig.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/config/SentinelConfig.java index 30d80717..a0d7c226 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/config/SentinelConfig.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/config/SentinelConfig.java @@ -18,6 +18,7 @@ package com.alibaba.csp.sentinel.config; import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.util.AppNameUtil; import com.alibaba.csp.sentinel.util.AssertUtil; +import com.alibaba.csp.sentinel.util.StringUtil; import java.util.Map; import java.util.Properties; @@ -30,7 +31,7 @@ import java.util.concurrent.ConcurrentHashMap; * @author leyou * @author Eric Zhao */ -public class SentinelConfig { +public final class SentinelConfig { /** * The default application type. @@ -54,7 +55,8 @@ public class SentinelConfig { static final long DEFAULT_SINGLE_METRIC_FILE_SIZE = 1024 * 1024 * 50; static final int DEFAULT_TOTAL_METRIC_FILE_COUNT = 6; static final int DEFAULT_COLD_FACTOR = 3; - static final int DEFAULT_STATISTIC_MAX_RT = 4900; + + public static final int DEFAULT_STATISTIC_MAX_RT = 4900; static { try { @@ -186,13 +188,28 @@ public class SentinelConfig { } } + /** + *
Get the max RT value that Sentinel could accept.
+ *Response time that exceeds {@code statisticMaxRt} will be recorded as this value. + * The default value is {@link #DEFAULT_STATISTIC_MAX_RT}.
+ * + * @return the max allowed RT value + * @since 1.4.1 + */ public static int statisticMaxRt() { + String v = props.get(STATISTIC_MAX_RT); try { - return Integer.parseInt(props.get(STATISTIC_MAX_RT)); + if (StringUtil.isEmpty(v)) { + return DEFAULT_STATISTIC_MAX_RT; + } + return Integer.parseInt(v); } catch (Throwable throwable) { - RecordLog.warn("[SentinelConfig] Parse statisticMaxRt fail, use default value: " - + DEFAULT_STATISTIC_MAX_RT, throwable); + RecordLog.warn("[SentinelConfig] Invalid statisticMaxRt value: {0}, using the default value instead: " + + DEFAULT_STATISTIC_MAX_RT, v, throwable); + SentinelConfig.setConfig(STATISTIC_MAX_RT, String.valueOf(DEFAULT_STATISTIC_MAX_RT)); return DEFAULT_STATISTIC_MAX_RT; } } + + private SentinelConfig() {} } 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 95a967a7..6cb09f8e 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 @@ -23,7 +23,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import com.alibaba.csp.sentinel.Constants; +import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.context.Context; import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.node.DefaultNode; @@ -211,7 +211,7 @@ public final class DegradeRuleManager { if (!baseValid) { return false; } - int maxAllowedRt = Constants.TIME_DROP_VALVE; + int maxAllowedRt = SentinelConfig.statisticMaxRt(); if (rule.getGrade() == RuleConstant.DEGRADE_GRADE_RT) { if (rule.getRtSlowRequestAmount() <= 0) { return false; diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/StatisticSlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/StatisticSlot.java index 30b6a6a8..09affecc 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/StatisticSlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/StatisticSlot.java @@ -17,6 +17,7 @@ package com.alibaba.csp.sentinel.slots.statistic; import java.util.Collection; +import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.slotchain.ProcessorSlotEntryCallback; import com.alibaba.csp.sentinel.slotchain.ProcessorSlotExitCallback; import com.alibaba.csp.sentinel.slots.block.flow.PriorityWaitException; @@ -133,10 +134,11 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot