-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dashboard: fix the problem that dashboard could not correctly display…
… the SystemRule in CPU usage strategy (#927)
- Loading branch information
1 parent
d19df2a
commit 5e85965
Showing
7 changed files
with
158 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,10 +88,33 @@ private int countNotNullAndNotNegative(Number... values) { | |
return notNullCount; | ||
} | ||
|
||
/** | ||
* @modify | ||
* 目前代码里做了如下几点修改: | ||
* 1】修改属性名称avgLoad 修改为highestSystemLoad | ||
* 2】修改属性名称avgCpu 修改为highestCpuUsage | ||
* 3】调用countNotNullAndNotNegative非空校验方法里增加参数highestCpuUsage, | ||
* 4】修改notNullCount部分判断错误提示语,因为目前countNotNullAndNotNegative里针对=0的情况也做了限制 | ||
* 5】对于highestSystemLoad、highestCpuUsage增加>1 的这个判断 | ||
* @author [email protected] | ||
* @time 2019年7月17日 18:30:32 | ||
* @modify | ||
* | ||
* @param request | ||
* @param app | ||
* @param ip | ||
* @param port | ||
* @param highestSystemLoad | ||
* @param highestCpuUsage | ||
* @param avgRt | ||
* @param maxThread | ||
* @param qps | ||
* @return | ||
*/ | ||
@ResponseBody | ||
@RequestMapping("/new.json") | ||
Result<?> add(HttpServletRequest request, | ||
String app, String ip, Integer port, Double avgLoad, Long avgRt, Long maxThread, Double qps) { | ||
String app, String ip, Integer port, Double highestSystemLoad,Double highestCpuUsage, Long avgRt, Long maxThread, Double qps) { | ||
AuthUser authUser = authService.getAuthUser(request); | ||
authUser.authTarget(app, PrivilegeType.WRITE_RULE); | ||
if (StringUtil.isBlank(app)) { | ||
|
@@ -103,21 +126,32 @@ Result<?> add(HttpServletRequest request, | |
if (port == null) { | ||
return Result.ofFail(-1, "port can't be null"); | ||
} | ||
int notNullCount = countNotNullAndNotNegative(avgLoad, avgRt, maxThread, qps); | ||
|
||
int notNullCount = countNotNullAndNotNegative(highestSystemLoad, avgRt, maxThread, qps,highestCpuUsage); | ||
if (notNullCount != 1) { | ||
return Result.ofFail(-1, "only one of [avgLoad, avgRt, maxThread, qps] " | ||
+ "value must be set >= 0, but " + notNullCount + " values get"); | ||
return Result.ofFail(-1, "only one of [highestSystemLoad, avgRt, maxThread, qps,highestCpuUsage] " | ||
+ "value must be set > 0, but " + notNullCount + " values get"); | ||
} | ||
if ( null!=highestCpuUsage && 1 < highestCpuUsage ) { | ||
return Result.ofFail(-1, "highestCpuUsage must <= 1"); | ||
} | ||
SystemRuleEntity entity = new SystemRuleEntity(); | ||
entity.setApp(app.trim()); | ||
entity.setIp(ip.trim()); | ||
entity.setPort(port); | ||
// -1 is a fake value | ||
if (avgLoad != null) { | ||
entity.setAvgLoad(avgLoad); | ||
if ( null != highestSystemLoad ) { | ||
entity.setHighestSystemLoad(highestSystemLoad); | ||
} else { | ||
entity.setHighestSystemLoad(-1D); | ||
} | ||
|
||
if ( null != highestCpuUsage ) { | ||
entity.setHighestCpuUsage(highestCpuUsage); | ||
} else { | ||
entity.setAvgLoad(-1D); | ||
entity.setHighestCpuUsage(-1D); | ||
} | ||
|
||
if (avgRt != null) { | ||
entity.setAvgRt(avgRt); | ||
} else { | ||
|
@@ -148,10 +182,30 @@ Result<?> add(HttpServletRequest request, | |
return Result.ofSuccess(entity); | ||
} | ||
|
||
/** | ||
* @modify | ||
* 目前代码里做了如下几点修改: | ||
* 1】修改属性名称avgLoad 修改为highestSystemLoad | ||
* 2】修改属性名称avgCpu 修改为highestCpuUsage | ||
* 1】对于highestSystemLoad、highestCpuUsage增加>1 的这个判断,调整原先<0的判断,调整为<=0 等于0的这种规则设置了也没有意义 | ||
* @author [email protected] | ||
* @time 2019年7月17日 18:30:32 | ||
* @modify | ||
* | ||
* @param request | ||
* @param id | ||
* @param app | ||
* @param highestSystemLoad | ||
* @param highestCpuUsage | ||
* @param avgRt | ||
* @param maxThread | ||
* @param qps | ||
* @return | ||
*/ | ||
@ResponseBody | ||
@RequestMapping("/save.json") | ||
Result<?> updateIfNotNull(HttpServletRequest request, | ||
Long id, String app, Double avgLoad, Long avgRt, Long maxThread, Double qps) { | ||
Long id, String app, Double highestSystemLoad,Double highestCpuUsage, Long avgRt, Long maxThread, Double qps) { | ||
AuthUser authUser = authService.getAuthUser(request); | ||
if (id == null) { | ||
return Result.ofFail(-1, "id can't be null"); | ||
|
@@ -164,11 +218,20 @@ Result<?> updateIfNotNull(HttpServletRequest request, | |
if (StringUtil.isNotBlank(app)) { | ||
entity.setApp(app.trim()); | ||
} | ||
if (avgLoad != null) { | ||
if (avgLoad < 0) { | ||
return Result.ofFail(-1, "avgLoad must >= 0"); | ||
if (highestSystemLoad != null) { | ||
if (highestSystemLoad <= 0) { | ||
return Result.ofFail(-1, "highestSystemLoad must >= 0"); | ||
} | ||
entity.setHighestSystemLoad(highestSystemLoad); | ||
} | ||
if (highestCpuUsage != null) { | ||
if (highestCpuUsage < 0) { | ||
return Result.ofFail(-1, "highestCpuUsage must >= 0"); | ||
} | ||
if (highestCpuUsage > 1) { | ||
return Result.ofFail(-1, "highestCpuUsage must <= 1"); | ||
} | ||
entity.setAvgLoad(avgLoad); | ||
entity.setHighestCpuUsage(highestCpuUsage); | ||
} | ||
if (avgRt != null) { | ||
if (avgRt < 0) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,10 @@ | |
*/ | ||
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; | ||
|
||
import java.util.Date; | ||
|
||
import com.alibaba.csp.sentinel.slots.system.SystemRule; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* @author leyou | ||
*/ | ||
|
@@ -29,10 +29,21 @@ public class SystemRuleEntity implements RuleEntity { | |
private String app; | ||
private String ip; | ||
private Integer port; | ||
private Double avgLoad; | ||
/** | ||
* 对应SystemRule 里的属性highestSystemLoad,这里做下调整 | ||
* @author [email protected] | ||
* @time 2019年7月17日 18:30:32 | ||
*/ | ||
private Double highestSystemLoad; | ||
private Long avgRt; | ||
private Long maxThread; | ||
private Double qps; | ||
/** | ||
* 对应SystemRule 里的属性highestCpuUsage | ||
* @author [email protected] | ||
* @time 2019年7月17日 18:30:32 | ||
*/ | ||
private Double highestCpuUsage; | ||
|
||
private Date gmtCreate; | ||
private Date gmtModified; | ||
|
@@ -42,7 +53,8 @@ public static SystemRuleEntity fromSystemRule(String app, String ip, Integer por | |
entity.setApp(app); | ||
entity.setIp(ip); | ||
entity.setPort(port); | ||
entity.setAvgLoad(rule.getHighestSystemLoad()); | ||
entity.setHighestSystemLoad(rule.getHighestSystemLoad()); | ||
entity.setHighestCpuUsage(rule.getHighestCpuUsage()); | ||
entity.setAvgRt(rule.getAvgRt()); | ||
entity.setMaxThread(rule.getMaxThread()); | ||
entity.setQps(rule.getQps()); | ||
|
@@ -86,12 +98,12 @@ public void setApp(String app) { | |
this.app = app; | ||
} | ||
|
||
public Double getAvgLoad() { | ||
return avgLoad; | ||
public Double getHighestSystemLoad() { | ||
return highestSystemLoad; | ||
} | ||
|
||
public void setAvgLoad(Double avgLoad) { | ||
this.avgLoad = avgLoad; | ||
public void setHighestSystemLoad(Double highestSystemLoad) { | ||
this.highestSystemLoad = highestSystemLoad; | ||
} | ||
|
||
public Long getAvgRt() { | ||
|
@@ -118,6 +130,14 @@ public void setQps(Double qps) { | |
this.qps = qps; | ||
} | ||
|
||
public Double getHighestCpuUsage() { | ||
return highestCpuUsage; | ||
} | ||
|
||
public void setHighestCpuUsage(Double highestCpuUsage) { | ||
this.highestCpuUsage = highestCpuUsage; | ||
} | ||
|
||
@Override | ||
public Date getGmtCreate() { | ||
return gmtCreate; | ||
|
@@ -138,10 +158,11 @@ public void setGmtModified(Date gmtModified) { | |
@Override | ||
public SystemRule toRule() { | ||
SystemRule rule = new SystemRule(); | ||
rule.setHighestSystemLoad(avgLoad); | ||
rule.setHighestSystemLoad(highestSystemLoad); | ||
rule.setAvgRt(avgRt); | ||
rule.setMaxThread(maxThread); | ||
rule.setQps(qps); | ||
rule.setHighestCpuUsage(highestCpuUsage); | ||
return rule; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.