-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the problem that dashboard do not correctly show the SystemRule in CPU usage strategy #922
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7718a5d
本次提交是为了解决https://github.com/alibaba/Sentinel/issues/905 上面 dashboard …
d00857d
按照修改意见修复SystemRuleEntity 中 highestCpuUsage(原avgCpu) highestSystemLoad…
bcf8954
修正理解错误,highestSystemLoad 的取值范围是 [0, +∞)
dd1dd15
调整页面显示文字
0ae8ffa
本次提交是为了解决https://github.com/alibaba/Sentinel/issues/905 上面 dashboard …
Crazy10552 44f69d9
Merge remote-tracking branch 'origin/dashboard-issues-905' into dashb…
Crazy10552 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
highestSystemLoad
的取值范围是 [0, +∞),load 没有 < 1 的限制。这个需要保持与之前一致。