mirror of
https://github.com/didi/KnowStreaming.git
synced 2025-12-24 03:42:07 +08:00
[Optimize]优化健康巡检相关指标的计算(#726)
1、增加缓存,减少健康状态指标计算时的IO; 2、健康巡检调整为按照资源维度并发处理; 3、明确HealthCheckResultService和HealthStateService的功能边界;
This commit is contained in:
@@ -14,16 +14,16 @@ import java.util.stream.Collectors;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class HealthCheckAggResult {
|
||||
private HealthCheckNameEnum checkNameEnum;
|
||||
protected HealthCheckNameEnum checkNameEnum;
|
||||
|
||||
private List<HealthCheckResultPO> poList;
|
||||
protected List<HealthCheckResultPO> poList;
|
||||
|
||||
private Boolean passed;
|
||||
protected Boolean passed;
|
||||
|
||||
public HealthCheckAggResult(HealthCheckNameEnum checkNameEnum, List<HealthCheckResultPO> poList) {
|
||||
this.checkNameEnum = checkNameEnum;
|
||||
this.poList = poList;
|
||||
if (!ValidateUtils.isEmptyList(poList) && poList.stream().filter(elem -> elem.getPassed() <= 0).count() <= 0) {
|
||||
if (ValidateUtils.isEmptyList(poList) || poList.stream().filter(elem -> elem.getPassed() <= 0).count() <= 0) {
|
||||
passed = true;
|
||||
} else {
|
||||
passed = false;
|
||||
@@ -45,24 +45,12 @@ public class HealthCheckAggResult {
|
||||
return (int) (poList.stream().filter(elem -> elem.getPassed() > 0).count());
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算当前检查的健康分
|
||||
* 比如:计算集群Broker健康检查中的某一项的健康分
|
||||
*/
|
||||
public Integer calRawHealthScore() {
|
||||
if (poList == null || poList.isEmpty()) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
return 100 * this.getPassedCount() / this.getTotalCount();
|
||||
}
|
||||
|
||||
public List<String> getNotPassedResNameList() {
|
||||
if (poList == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return poList.stream().filter(elem -> elem.getPassed() <= 0).map(elem -> elem.getResName()).collect(Collectors.toList());
|
||||
return poList.stream().filter(elem -> elem.getPassed() <= 0 && !ValidateUtils.isBlank(elem.getResName())).map(elem -> elem.getResName()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
|
||||
@@ -3,87 +3,20 @@ package com.xiaojukeji.know.streaming.km.common.bean.entity.health;
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.entity.config.healthcheck.BaseClusterHealthConfig;
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.po.health.HealthCheckResultPO;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.health.HealthCheckNameEnum;
|
||||
import com.xiaojukeji.know.streaming.km.common.utils.ValidateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class HealthScoreResult {
|
||||
private HealthCheckNameEnum checkNameEnum;
|
||||
|
||||
public class HealthScoreResult extends HealthCheckAggResult {
|
||||
private BaseClusterHealthConfig baseConfig;
|
||||
|
||||
private List<HealthCheckResultPO> poList;
|
||||
|
||||
private Boolean passed;
|
||||
|
||||
public HealthScoreResult(HealthCheckNameEnum checkNameEnum,
|
||||
BaseClusterHealthConfig baseConfig,
|
||||
List<HealthCheckResultPO> poList) {
|
||||
this.checkNameEnum = checkNameEnum;
|
||||
super(checkNameEnum, poList);
|
||||
this.baseConfig = baseConfig;
|
||||
this.poList = poList;
|
||||
if (!ValidateUtils.isEmptyList(poList) && poList.stream().filter(elem -> elem.getPassed() <= 0).count() <= 0) {
|
||||
passed = true;
|
||||
} else {
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getTotalCount() {
|
||||
if (poList == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return poList.size();
|
||||
}
|
||||
|
||||
public Integer getPassedCount() {
|
||||
if (poList == null) {
|
||||
return 0;
|
||||
}
|
||||
return (int) (poList.stream().filter(elem -> elem.getPassed() > 0).count());
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算当前检查的健康分
|
||||
* 比如:计算集群Broker健康检查中的某一项的健康分
|
||||
*/
|
||||
public Integer calRawHealthScore() {
|
||||
if (poList == null || poList.isEmpty()) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
return 100 * this.getPassedCount() / this.getTotalCount();
|
||||
}
|
||||
|
||||
public List<String> getNotPassedResNameList() {
|
||||
if (poList == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return poList.stream().filter(elem -> elem.getPassed() <= 0 && !ValidateUtils.isBlank(elem.getResName())).map(elem -> elem.getResName()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
if (ValidateUtils.isEmptyList(poList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return poList.get(0).getCreateTime();
|
||||
}
|
||||
|
||||
public Date getUpdateTime() {
|
||||
if (ValidateUtils.isEmptyList(poList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return poList.get(0).getUpdateTime();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@ public class HealthScoreBaseResultVO extends BaseTimeVO {
|
||||
@ApiModelProperty(value="检查说明", example = "Group延迟")
|
||||
private String configDesc;
|
||||
|
||||
@Deprecated
|
||||
@ApiModelProperty(value="得分", example = "100")
|
||||
private Integer score;
|
||||
private Integer score = 100;
|
||||
|
||||
@ApiModelProperty(value="结果", example = "true")
|
||||
private Boolean passed;
|
||||
|
||||
@@ -24,15 +24,7 @@ public class HealthScoreVOConverter {
|
||||
vo.setConfigName(healthScoreResult.getCheckNameEnum().getConfigName());
|
||||
vo.setConfigItem(healthScoreResult.getCheckNameEnum().getConfigItem());
|
||||
vo.setConfigDesc(healthScoreResult.getCheckNameEnum().getConfigDesc());
|
||||
|
||||
vo.setScore(healthScoreResult.calRawHealthScore());
|
||||
if (healthScoreResult.getTotalCount() <= 0) {
|
||||
// 未知
|
||||
vo.setPassed(null);
|
||||
} else {
|
||||
vo.setPassed(healthScoreResult.getPassedCount().equals(healthScoreResult.getTotalCount()));
|
||||
}
|
||||
|
||||
vo.setPassed(healthScoreResult.getPassed());
|
||||
vo.setCheckConfig(convert2HealthCheckConfigVO(ConfigGroupEnum.HEALTH.name(), healthScoreResult.getBaseConfig()));
|
||||
|
||||
vo.setNotPassedResNameList(healthScoreResult.getNotPassedResNameList());
|
||||
@@ -51,8 +43,7 @@ public class HealthScoreVOConverter {
|
||||
vo.setDimensionName(healthScoreResult.getCheckNameEnum().getDimensionEnum().getMessage());
|
||||
vo.setConfigName(healthScoreResult.getCheckNameEnum().getConfigName());
|
||||
vo.setConfigDesc(healthScoreResult.getCheckNameEnum().getConfigDesc());
|
||||
vo.setScore(healthScoreResult.calRawHealthScore());
|
||||
vo.setPassed(healthScoreResult.getPassedCount().equals(healthScoreResult.getTotalCount()));
|
||||
vo.setPassed(healthScoreResult.getPassed());
|
||||
vo.setCheckConfig(convert2HealthCheckConfigVO(ConfigGroupEnum.HEALTH.name(), healthScoreResult.getBaseConfig()));
|
||||
vo.setCreateTime(healthScoreResult.getCreateTime());
|
||||
vo.setUpdateTime(healthScoreResult.getUpdateTime());
|
||||
|
||||
@@ -20,6 +20,8 @@ public enum HealthCheckDimensionEnum {
|
||||
|
||||
ZOOKEEPER(4, "Zookeeper"),
|
||||
|
||||
MAX_VAL(100, "所有的dimension的值需要小于MAX_VAL")
|
||||
|
||||
;
|
||||
|
||||
private final int dimension;
|
||||
|
||||
Reference in New Issue
Block a user