Rename ParamFlowRule.blockGrade to grade

This commit is contained in:
Carpenter Lee 2018-10-16 20:34:40 +08:00
parent b85d8ef1db
commit aaf88b8a0a
7 changed files with 14 additions and 14 deletions

View File

@ -56,7 +56,7 @@ public class ParamFlowRuleEntity extends AbstractRuleEntity<ParamFlowRule> {
@JsonIgnore
public int getBlockGrade() {
return rule.getBlockGrade();
return rule.getGrade();
}
@JsonIgnore

View File

@ -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.paramIdx}}</td>
<td>
{{ruleEntity.rule.blockGrade == 1 ? 'QPS' : '未知'}}
{{ruleEntity.rule.grade == 1 ? 'QPS' : '未知'}}
</td>
<td style="word-wrap:break-word;word-break:break-all;">
{{ruleEntity.rule.count}}

View File

@ -55,7 +55,7 @@ public class ParamFlowQpsDemo {
// QPS mode, threshold is 5 for every frequent "hot spot" parameter in index 0 (the first arg).
ParamFlowRule rule = new ParamFlowRule(RESOURCE_KEY)
.setParamIdx(0)
.setBlockGrade(RuleConstant.FLOW_GRADE_QPS)
.setGrade(RuleConstant.FLOW_GRADE_QPS)
.setCount(5);
// 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)

View File

@ -52,7 +52,7 @@ The description for fields of `ParamFlowRule`:
| :----: | :----| :----|
| resource| resource name (**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**) ||
| paramFlowItemList | the exception items of parameter; you can set threshold to a specific parameter value ||

View File

@ -78,7 +78,7 @@ final class ParamFlowChecker {
static boolean passSingleValueCheck(ResourceWrapper resourceWrapper, ParamFlowRule rule, int count, Object value) {
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);
if (exclusionItems.contains(value)) {

View File

@ -43,7 +43,7 @@ public class ParamFlowRule extends AbstractRule {
/**
* The threshold type of flow control (1: QPS).
*/
private int blockGrade = RuleConstant.FLOW_GRADE_QPS;
private int grade = RuleConstant.FLOW_GRADE_QPS;
/**
* Parameter index.
@ -65,12 +65,12 @@ public class ParamFlowRule extends AbstractRule {
*/
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;
}
@ -124,7 +124,7 @@ public class ParamFlowRule extends AbstractRule {
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 (paramIdx != null ? !paramIdx.equals(rule.paramIdx) : rule.paramIdx != null) { return false; }
return paramFlowItemList != null ? paramFlowItemList.equals(rule.paramFlowItemList) : rule.paramFlowItemList == null;
@ -134,7 +134,7 @@ public class ParamFlowRule extends AbstractRule {
public int hashCode() {
int result = super.hashCode();
long temp;
result = 31 * result + blockGrade;
result = 31 * result + grade;
result = 31 * result + (paramIdx != null ? paramIdx.hashCode() : 0);
temp = Double.doubleToLongBits(count);
result = 31 * result + (int)(temp ^ (temp >>> 32));
@ -147,7 +147,7 @@ public class ParamFlowRule extends AbstractRule {
return "ParamFlowRule{" +
"resource=" + getResource() +
", limitApp=" + getLimitApp() +
", blockGrade=" + blockGrade +
", grade=" + grade +
", paramIdx=" + paramIdx +
", count=" + count +
", paramFlowItemList=" + paramFlowItemList +

View File

@ -81,7 +81,7 @@ public class ParamFlowRuleManagerTest {
ParamFlowRule ruleC = new ParamFlowRule(resA)
.setCount(8)
.setParamIdx(1)
.setBlockGrade(RuleConstant.FLOW_GRADE_QPS);
.setGrade(RuleConstant.FLOW_GRADE_QPS);
// Rule D is for resource B.
ParamFlowRule ruleD = new ParamFlowRule(resB)
.setCount(9)