@@ -56,7 +56,7 @@ public class ParamFlowRuleEntity extends AbstractRuleEntity<ParamFlowRule> { | |||||
@JsonIgnore | @JsonIgnore | ||||
public int getBlockGrade() { | public int getBlockGrade() { | ||||
return rule.getBlockGrade(); | |||||
return rule.getGrade(); | |||||
} | } | ||||
@JsonIgnore | @JsonIgnore | ||||
@@ -69,7 +69,7 @@ | |||||
<td style="word-wrap:break-word;word-break:break-all;">{{ruleEntity.rule.resource}}</td> | <td style="word-wrap:break-word;word-break:break-all;">{{ruleEntity.rule.resource}}</td> | ||||
<td style="word-wrap:break-word;word-break:break-all;">{{ruleEntity.rule.paramIdx}}</td> | <td style="word-wrap:break-word;word-break:break-all;">{{ruleEntity.rule.paramIdx}}</td> | ||||
<td> | <td> | ||||
{{ruleEntity.rule.blockGrade == 1 ? 'QPS' : '未知'}} | |||||
{{ruleEntity.rule.grade == 1 ? 'QPS' : '未知'}} | |||||
</td> | </td> | ||||
<td style="word-wrap:break-word;word-break:break-all;"> | <td style="word-wrap:break-word;word-break:break-all;"> | ||||
{{ruleEntity.rule.count}} | {{ruleEntity.rule.count}} | ||||
@@ -55,7 +55,7 @@ public class ParamFlowQpsDemo { | |||||
// QPS mode, threshold is 5 for every frequent "hot spot" parameter in index 0 (the first arg). | // QPS mode, threshold is 5 for every frequent "hot spot" parameter in index 0 (the first arg). | ||||
ParamFlowRule rule = new ParamFlowRule(RESOURCE_KEY) | ParamFlowRule rule = new ParamFlowRule(RESOURCE_KEY) | ||||
.setParamIdx(0) | .setParamIdx(0) | ||||
.setBlockGrade(RuleConstant.FLOW_GRADE_QPS) | |||||
.setGrade(RuleConstant.FLOW_GRADE_QPS) | |||||
.setCount(5); | .setCount(5); | ||||
// We can set threshold count for specific parameter value individually. | // We can set threshold count for specific parameter value individually. | ||||
// Here we add an exception item. That means: QPS threshold of entries with parameter `PARAM_B` (type: int) | // Here we add an exception item. That means: QPS threshold of entries with parameter `PARAM_B` (type: int) | ||||
@@ -52,7 +52,7 @@ The description for fields of `ParamFlowRule`: | |||||
| :----: | :----| :----| | | :----: | :----| :----| | ||||
| resource| resource name (**required**) || | | resource| resource name (**required**) || | ||||
| count | flow control threshold (**required**) || | | count | flow control threshold (**required**) || | ||||
| blockGrade | flow control mode (only QPS mode is supported) | QPS mode | | |||||
| grade | flow control mode (only QPS mode is supported) | QPS mode | | |||||
| paramIdx | the index of provided parameter in `SphU.entry(xxx, args)` (**required**) || | | paramIdx | the index of provided parameter in `SphU.entry(xxx, args)` (**required**) || | ||||
| paramFlowItemList | the exception items of parameter; you can set threshold to a specific parameter value || | | paramFlowItemList | the exception items of parameter; you can set threshold to a specific parameter value || | ||||
@@ -78,7 +78,7 @@ final class ParamFlowChecker { | |||||
static boolean passSingleValueCheck(ResourceWrapper resourceWrapper, ParamFlowRule rule, int count, Object value) { | static boolean passSingleValueCheck(ResourceWrapper resourceWrapper, ParamFlowRule rule, int count, Object value) { | ||||
Set<Object> exclusionItems = rule.getParsedHotItems().keySet(); | Set<Object> exclusionItems = rule.getParsedHotItems().keySet(); | ||||
if (rule.getBlockGrade() == RuleConstant.FLOW_GRADE_QPS) { | |||||
if (rule.getGrade() == RuleConstant.FLOW_GRADE_QPS) { | |||||
double curCount = getHotParameters(resourceWrapper).getPassParamQps(rule.getParamIdx(), value); | double curCount = getHotParameters(resourceWrapper).getPassParamQps(rule.getParamIdx(), value); | ||||
if (exclusionItems.contains(value)) { | if (exclusionItems.contains(value)) { | ||||
@@ -43,7 +43,7 @@ public class ParamFlowRule extends AbstractRule { | |||||
/** | /** | ||||
* The threshold type of flow control (1: QPS). | * The threshold type of flow control (1: QPS). | ||||
*/ | */ | ||||
private int blockGrade = RuleConstant.FLOW_GRADE_QPS; | |||||
private int grade = RuleConstant.FLOW_GRADE_QPS; | |||||
/** | /** | ||||
* Parameter index. | * Parameter index. | ||||
@@ -65,12 +65,12 @@ public class ParamFlowRule extends AbstractRule { | |||||
*/ | */ | ||||
private Map<Object, Integer> hotItems = new HashMap<Object, Integer>(); | private Map<Object, Integer> hotItems = new HashMap<Object, Integer>(); | ||||
public int getBlockGrade() { | |||||
return blockGrade; | |||||
public int getGrade() { | |||||
return grade; | |||||
} | } | ||||
public ParamFlowRule setBlockGrade(int blockGrade) { | |||||
this.blockGrade = blockGrade; | |||||
public ParamFlowRule setGrade(int grade) { | |||||
this.grade = grade; | |||||
return this; | return this; | ||||
} | } | ||||
@@ -124,7 +124,7 @@ public class ParamFlowRule extends AbstractRule { | |||||
ParamFlowRule rule = (ParamFlowRule)o; | ParamFlowRule rule = (ParamFlowRule)o; | ||||
if (blockGrade != rule.blockGrade) { return false; } | |||||
if (grade != rule.grade) { return false; } | |||||
if (Double.compare(rule.count, count) != 0) { return false; } | if (Double.compare(rule.count, count) != 0) { return false; } | ||||
if (paramIdx != null ? !paramIdx.equals(rule.paramIdx) : rule.paramIdx != null) { return false; } | if (paramIdx != null ? !paramIdx.equals(rule.paramIdx) : rule.paramIdx != null) { return false; } | ||||
return paramFlowItemList != null ? paramFlowItemList.equals(rule.paramFlowItemList) : rule.paramFlowItemList == null; | return paramFlowItemList != null ? paramFlowItemList.equals(rule.paramFlowItemList) : rule.paramFlowItemList == null; | ||||
@@ -134,7 +134,7 @@ public class ParamFlowRule extends AbstractRule { | |||||
public int hashCode() { | public int hashCode() { | ||||
int result = super.hashCode(); | int result = super.hashCode(); | ||||
long temp; | long temp; | ||||
result = 31 * result + blockGrade; | |||||
result = 31 * result + grade; | |||||
result = 31 * result + (paramIdx != null ? paramIdx.hashCode() : 0); | result = 31 * result + (paramIdx != null ? paramIdx.hashCode() : 0); | ||||
temp = Double.doubleToLongBits(count); | temp = Double.doubleToLongBits(count); | ||||
result = 31 * result + (int)(temp ^ (temp >>> 32)); | result = 31 * result + (int)(temp ^ (temp >>> 32)); | ||||
@@ -147,7 +147,7 @@ public class ParamFlowRule extends AbstractRule { | |||||
return "ParamFlowRule{" + | return "ParamFlowRule{" + | ||||
"resource=" + getResource() + | "resource=" + getResource() + | ||||
", limitApp=" + getLimitApp() + | ", limitApp=" + getLimitApp() + | ||||
", blockGrade=" + blockGrade + | |||||
", grade=" + grade + | |||||
", paramIdx=" + paramIdx + | ", paramIdx=" + paramIdx + | ||||
", count=" + count + | ", count=" + count + | ||||
", paramFlowItemList=" + paramFlowItemList + | ", paramFlowItemList=" + paramFlowItemList + | ||||
@@ -81,7 +81,7 @@ public class ParamFlowRuleManagerTest { | |||||
ParamFlowRule ruleC = new ParamFlowRule(resA) | ParamFlowRule ruleC = new ParamFlowRule(resA) | ||||
.setCount(8) | .setCount(8) | ||||
.setParamIdx(1) | .setParamIdx(1) | ||||
.setBlockGrade(RuleConstant.FLOW_GRADE_QPS); | |||||
.setGrade(RuleConstant.FLOW_GRADE_QPS); | |||||
// Rule D is for resource B. | // Rule D is for resource B. | ||||
ParamFlowRule ruleD = new ParamFlowRule(resB) | ParamFlowRule ruleD = new ParamFlowRule(resB) | ||||
.setCount(9) | .setCount(9) | ||||