소스 검색

Improve the edit dialog for FlowRule and ParamFlowRule in Sentinel dashboard (#845)

* dashboard: update edit dialog for FlowRule and ParamFlowRule
- Add duration configuration support for ParamFlowRule
- Some other enhancements

* Code polish: move implementation of toRule() to AbstractRuleEntity

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao Jason Joo 5 년 전
부모
커밋
eb7508ca80
8개의 변경된 파일73개의 추가작업 그리고 18개의 파일을 삭제
  1. +6
    -0
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java
  2. +6
    -0
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java
  3. +0
    -6
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java
  4. +20
    -6
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java
  5. +9
    -0
      sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/identity.js
  6. +10
    -1
      sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js
  7. +4
    -4
      sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html
  8. +18
    -1
      sentinel-dashboard/src/main/webapp/resources/app/views/dialog/param-flow-rule-dialog.html

+ 6
- 0
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java 파일 보기

@@ -188,6 +188,12 @@ public class ParamFlowRuleController {
if (entity.getParamIdx() == null || entity.getParamIdx() < 0) {
return Result.ofFail(-1, "paramIdx should be valid");
}
if (entity.getDurationInSec() <= 0) {
return Result.ofFail(-1, "durationInSec should be valid");
}
if (entity.getControlBehavior() < 0) {
return Result.ofFail(-1, "controlBehavior should be valid");
}
return null;
}



+ 6
- 0
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java 파일 보기

@@ -18,6 +18,7 @@ package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;
import java.util.Date;

import com.alibaba.csp.sentinel.slots.block.AbstractRule;
import com.alibaba.csp.sentinel.slots.block.Rule;

/**
* @author Eric Zhao
@@ -103,4 +104,9 @@ public abstract class AbstractRuleEntity<T extends AbstractRule> implements Rule
this.gmtModified = gmtModified;
return this;
}

@Override
public T toRule() {
return rule;
}
}

+ 0
- 6
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java 파일 보기

@@ -15,7 +15,6 @@
*/
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;

import com.alibaba.csp.sentinel.slots.block.Rule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.util.AssertUtil;

@@ -56,9 +55,4 @@ public class AuthorityRuleEntity extends AbstractRuleEntity<AuthorityRule> {
public int getStrategy() {
return rule.getStrategy();
}
@Override
public Rule toRule() {
return rule;
}
}

+ 20
- 6
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java 파일 보기

@@ -17,7 +17,6 @@ package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;

import java.util.List;

import com.alibaba.csp.sentinel.slots.block.Rule;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowItem;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
@@ -76,6 +75,26 @@ public class ParamFlowRuleEntity extends AbstractRuleEntity<ParamFlowRule> {
return rule.getParamFlowItemList();
}

@JsonIgnore
public int getControlBehavior() {
return rule.getControlBehavior();
}

@JsonIgnore
public int getMaxQueueingTimeMs() {
return rule.getMaxQueueingTimeMs();
}

@JsonIgnore
public int getBurstCount() {
return rule.getBurstCount();
}

@JsonIgnore
public long getDurationInSec() {
return rule.getDurationInSec();
}

@JsonIgnore
public boolean isClusterMode() {
return rule.isClusterMode();
@@ -85,9 +104,4 @@ public class ParamFlowRuleEntity extends AbstractRuleEntity<ParamFlowRule> {
public ParamFlowClusterConfig getClusterConfig() {
return rule.getClusterConfig();
}
@Override
public Rule toRule() {
return rule;
}
}

+ 9
- 0
sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/identity.js 파일 보기

@@ -322,6 +322,15 @@ app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService',
paramFlowItemList: [],
count: 0,
limitApp: 'default',
controlBehavior: 0,
durationInSec: 1,
burstCount: 0,
maxQueueingTimeMs: 0,
clusterMode: false,
clusterConfig: {
thresholdType: 0,
fallbackToLocalWhenFail: true,
}
}
};



+ 10
- 1
sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js 파일 보기

@@ -130,6 +130,9 @@ angular.module('sentinelDashboardApp').controller('ParamFlowController', ['$scop

$scope.editRule = function (rule) {
$scope.currentRule = angular.copy(rule);
if ($scope.currentRule.rule && $scope.currentRule.rule.durationInSec === undefined) {
$scope.currentRule.rule.durationInSec = 1;
}
$scope.paramFlowRuleDialog = {
title: '编辑热点规则',
type: 'edit',
@@ -157,9 +160,14 @@ angular.module('sentinelDashboardApp').controller('ParamFlowController', ['$scop
paramFlowItemList: [],
count: 0,
limitApp: 'default',
controlBehavior: 0,
durationInSec: 1,
burstCount: 0,
maxQueueingTimeMs: 0,
clusterMode: false,
clusterConfig: {
thresholdType: 0
thresholdType: 0,
fallbackToLocalWhenFail: true,
}
}
};
@@ -167,6 +175,7 @@ angular.module('sentinelDashboardApp').controller('ParamFlowController', ['$scop
title: '新增热点规则',
type: 'add',
confirmBtnText: '新增',
supportAdvanced: true,
showAdvanceButton: true,
};
paramFlowRuleDialog = ngDialog.open({


+ 4
- 4
sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html 파일 보기

@@ -15,9 +15,9 @@
</div>

<div class="form-group">
<label class="col-sm-2 control-label" data-toggle="tooltip" title="流控针对应用,即流量入口的调用来源(origin)">来源应用</label>
<label class="col-sm-2 control-label" data-toggle="tooltip" title="流控针对的来源,即流量入口的调用来源(origin)">针对来源</label>
<div class="col-sm-9">
<input type="text" class="form-control highlight-border" ng-model='currentRule.limitApp' placeholder='指调用方,"default"表示所有应用。'
<input type="text" class="form-control highlight-border" ng-model='currentRule.limitApp' placeholder='调用来源,"default"表示所有应用'
/>
</div>
</div>
@@ -72,9 +72,9 @@
<label class="col-sm-2 control-label">失败退化</label>
<div class="col-sm-8">
<label class="checkbox-inline">
<input type="checkbox" name="clusterMode" ng-model="currentRule.clusterConfig.fallbackToLocalWhenFail">
<input type="checkbox" name="fallbackToLocalWhenFail" ng-model="currentRule.clusterConfig.fallbackToLocalWhenFail">
<i class="glyphicon glyphicon-info-sign"></i>&nbsp;如果 Token Server 不可用是否退化到单机限流
</label>
<i class="glyphicon glyphicon-info-sign"></i>&nbsp;如果 Token Server 不可用是否退化到单机限流
</div>
</div>



+ 18
- 1
sentinel-dashboard/src/main/webapp/resources/app/views/dialog/param-flow-rule-dialog.html 파일 보기

@@ -27,9 +27,16 @@
<div class="form-group">
<div ng-if="!currentRule.rule.clusterMode">
<label class="col-sm-2 control-label">单机阈值</label>
<div class="col-sm-9">
<div class="col-sm-3">
<input type="number" class="form-control highlight-border" ng-model='currentRule.rule.count' placeholder='单机阈值' />
</div>
<label class="col-sm-3 control-label" title="统计窗口时间长度,单位为 s">统计窗口时长</label>
<div class="input-group col-sm-3">
<input type="number" class="form-control highlight-border"
ng-model='currentRule.rule.durationInSec' min="1"
placeholder='请填入统计窗口时长(单位为 秒)' />
<span class="input-group-addon">秒</span>
</div>
</div>
<div ng-if="currentRule.rule.clusterMode && currentRule.rule.clusterConfig.thresholdType == 0">
<label class="col-sm-2 control-label">均摊阈值</label>
@@ -61,6 +68,16 @@
</div>
</div>

<div class="form-group" ng-if="currentRule.rule.clusterMode">
<label class="col-sm-2 control-label">失败退化</label>
<div class="col-sm-8">
<div class="checkbox-inline">
<input type="checkbox" name="fallbackToLocalWhenFail"
ng-model="currentRule.rule.clusterConfig.fallbackToLocalWhenFail">
<i class="glyphicon glyphicon-info-sign"></i>&nbsp;若选择,则 Token Server 不可用时将退化到单机限流
</div>
</div>
</div>

<!-- exclusion item part start -->
<div ng-if="!paramFlowRuleDialog.showAdvanceButton">


Loading…
취소
저장