Skip to content

Commit

Permalink
Some improvements on Sentinel Dashboard
Browse files Browse the repository at this point in the history
- Fixes alibaba#231: when resource name is too long in resource page, the name will jump out and cover other layout
- Hide `origin` input view in degrade rule dialog
- Refine style and color of buttons in dialogs
- Add support for exception count in degrade rule
- Other improvements

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
  • Loading branch information
sczyh30 committed Nov 5, 2018
1 parent 59f2c6b commit b540898
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Date;
import java.util.List;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.util.StringUtil;

import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
Expand All @@ -38,15 +39,17 @@
@Controller
@RequestMapping(value = "/degrade", produces = MediaType.APPLICATION_JSON_VALUE)
public class DegradeController {
private static Logger logger = LoggerFactory.getLogger(DegradeController.class);

private final Logger logger = LoggerFactory.getLogger(DegradeController.class);

@Autowired
InMemDegradeRuleStore repository;
private InMemDegradeRuleStore repository;
@Autowired
private SentinelApiClient sentinelApiClient;

@ResponseBody
@RequestMapping("/rules.json")
Result<List<DegradeRuleEntity>> queryMachineRules(String app, String ip, Integer port) {
public Result<List<DegradeRuleEntity>> queryMachineRules(String app, String ip, Integer port) {
if (StringUtil.isEmpty(app)) {
return Result.ofFail(-1, "app can't be null or empty");
}
Expand All @@ -68,7 +71,7 @@ Result<List<DegradeRuleEntity>> queryMachineRules(String app, String ip, Integer

@ResponseBody
@RequestMapping("/new.json")
Result<?> add(String app, String ip, Integer port, String limitApp, String resource,
public Result<DegradeRuleEntity> add(String app, String ip, Integer port, String limitApp, String resource,
Double count, Integer timeWindow, Integer grade) {
if (StringUtil.isBlank(app)) {
return Result.ofFail(-1, "app can't be null or empty");
Expand All @@ -94,8 +97,8 @@ Result<?> add(String app, String ip, Integer port, String limitApp, String resou
if (grade == null) {
return Result.ofFail(-1, "grade can't be null");
}
if (grade != 0 && grade != 1) {
return Result.ofFail(-1, "grade must be 0 or 1, but " + grade + " got");
if (grade < RuleConstant.DEGRADE_GRADE_RT || grade > RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) {
return Result.ofFail(-1, "Invalid grade: " + grade);
}
DegradeRuleEntity entity = new DegradeRuleEntity();
entity.setApp(app.trim());
Expand Down Expand Up @@ -123,14 +126,14 @@ Result<?> add(String app, String ip, Integer port, String limitApp, String resou

@ResponseBody
@RequestMapping("/save.json")
Result<?> updateIfNotNull(Long id, String app, String limitApp, String resource,
public Result<DegradeRuleEntity> updateIfNotNull(Long id, String app, String limitApp, String resource,
Double count, Integer timeWindow, Integer grade) {
if (id == null) {
return Result.ofFail(-1, "id can't be null");
}
if (grade != null) {
if (grade != 0 && grade != 1) {
return Result.ofFail(-1, "grade must be 0 or 1, but " + grade + " got");
if (grade < RuleConstant.DEGRADE_GRADE_RT || grade > RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) {
return Result.ofFail(-1, "Invalid grade: " + grade);
}
}
DegradeRuleEntity entity = repository.findById(id);
Expand Down Expand Up @@ -172,7 +175,7 @@ Result<?> updateIfNotNull(Long id, String app, String limitApp, String resource,

@ResponseBody
@RequestMapping("/delete.json")
Result<?> delete(Long id) {
public Result<Long> delete(Long id) {
if (id == null) {
return Result.ofFail(-1, "id can't be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,34 @@ app.controller('DegradeCtl', ['$scope', '$stateParams', 'DegradeService', 'ngDia
}
};

function parseDegradeMode(grade) {
switch (grade) {
case 0:
return 'RT';
case 1:
return '异常比例';
case 2:
return '异常数';
default:
return '未知';
}
}

var confirmDialog;
$scope.deleteRule = function (rule) {
$scope.currentRule = rule;
$scope.confirmDialog = {
title: '删除降级规则',
type: 'delete_rule',
attentionTitle: '请确认是否删除如下降级规则',
attention: '资源名: ' + rule.resource + ', 降级应用: ' + rule.limitApp
+ ', 阈值类型: ' + (rule.grade == 0 ? 'RT' : '异常比例') + ', 阈值: ' + rule.count,
attention: '资源名: ' + rule.resource +
', 降级模式: ' + parseDegradeMode(rule.grade) + ', 阈值: ' + rule.count,
confirmBtnText: '删除',
};
confirmDialog = ngDialog.open({
template: '/app/views/dialog/confirm-dialog.html',
scope: $scope,
overlay: true

});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var com_github_culmat_jsTreeTable = (function(){
td.prepend($('<span style="padding-left:16px;" /></span>'))
}
td.prepend($('<span style="padding-left:'+(15*parseInt(level-1))+'px;" /></span>'))
td.css('white-space','nowrap')
// td.css('white-space','nowrap')
tr.trExpand = function(changeState){
if(this.trChildren.length < 1) return
if(changeState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ app.service('DegradeService', ['$http', function ($http) {
return false;
}
if (rule.grade === undefined || rule.grade < 0) {
alert('未知的降级类型');
alert('未知的降级策略');
return false;
}
if (rule.count === undefined || rule.count === '' || rule.count < 0) {
Expand Down
Loading

0 comments on commit b540898

Please sign in to comment.