Signed-off-by: Eric Zhao <sczyh16@gmail.com>master
@@ -86,7 +86,7 @@ public class MetricWriter { | |||
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 class MetricWriter { | |||
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 @@ public class MetricWriter { | |||
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 @@ public class MetricWriter { | |||
; | |||
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 { | |||
@@ -50,7 +50,7 @@ public class DynamicSentinelProperty<T> implements SentinelProperty<T> { | |||
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<T> listener : listeners) { | |||
@@ -17,13 +17,23 @@ package com.alibaba.csp.sentinel.slots.block; | |||
/*** | |||
* @author youji.zj | |||
* @author Eric Zhao | |||
*/ | |||
public abstract class AbstractRule implements Rule { | |||
/*** 规则的资源描述 ***/ | |||
/** | |||
* Resource name. | |||
*/ | |||
private String resource; | |||
/*** 被限制的应用,授权时候为逗号分隔的应用集合,限流时为单个应用 ***/ | |||
/** | |||
* <p> | |||
* Application name that will be limited by origin. | |||
* Multiple application name can be separated with comma (','). | |||
* </p> | |||
* <p>The default limitApp is `default`, which means allowing all origin apps.</p> | |||
* <p>For example: limitApp = `appA,appB` will limit requests from appA and appB.</p> | |||
*/ | |||
private String limitApp; | |||
public String getResource() { | |||
@@ -19,7 +19,7 @@ package com.alibaba.csp.sentinel.slots.block; | |||
* @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() {} | |||
} |
@@ -21,11 +21,11 @@ import java.util.Map; | |||
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 @@ public final class AuthorityRuleManager { | |||
} | |||
if (StringUtil.isBlank(rule.getLimitApp())) { | |||
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT); | |||
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT); | |||
} | |||
String identity = rule.getResource(); | |||
@@ -28,7 +28,7 @@ import com.alibaba.csp.sentinel.property.PropertyListener; | |||
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 @@ public class DegradeRuleManager { | |||
} | |||
if (StringUtil.isBlank(rule.getLimitApp())) { | |||
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT); | |||
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT); | |||
} | |||
String identity = rule.getResource(); | |||
@@ -40,12 +40,9 @@ import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot; | |||
*/ | |||
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 @@ public class FlowRule extends AbstractRule { | |||
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 @@ public class FlowRule extends AbstractRule { | |||
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(); | |||
} | |||
@@ -17,6 +17,8 @@ package com.alibaba.csp.sentinel.slots.block.flow; | |||
import java.util.Comparator; | |||
import com.alibaba.csp.sentinel.slots.block.RuleConstant; | |||
public class FlowRuleComparator implements Comparator<FlowRule> { | |||
@Override | |||
@@ -30,9 +32,9 @@ public class FlowRuleComparator implements Comparator<FlowRule> { | |||
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; | |||
@@ -114,7 +114,7 @@ public class FlowRuleManager { | |||
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()); | |||
@@ -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 class SystemRuleManager { | |||
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 class SystemRuleManager { | |||
} | |||
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 class SystemRuleManager { | |||
* @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 class SystemRuleManager { | |||
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 class SystemRuleManager { | |||
public static double getCurrentSystemAvgLoad() { | |||
return statusListener.getSystemAverageLoad(); | |||
} | |||
} |
@@ -57,7 +57,7 @@ public final class AppNameUtil { | |||
static { | |||
resolveAppName(); | |||
RecordLog.info("app name resolved: " + appName); | |||
RecordLog.info("App name resolved: " + appName); | |||
} | |||
public static void resolveAppName() { | |||
@@ -26,7 +26,7 @@ import com.alibaba.csp.sentinel.log.RecordLog; | |||
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 @@ public final class ParamFlowRuleManager { | |||
} | |||
if (StringUtil.isBlank(rule.getLimitApp())) { | |||
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT); | |||
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT); | |||
} | |||
if (rule.getParamFlowItemList() == null) { | |||