Skip to content

Commit

Permalink
feat: 接口监控支持白名单
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyQing committed May 14, 2024
1 parent 94e5dc8 commit 60b7c2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import lombok.Setter;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
* 接口健康检测配置属性
Expand Down Expand Up @@ -59,6 +61,10 @@ public class HealthProperties {
* 特定接口失败阈值
*/
private Map<String, BigDecimal> failRateThresholds = new LinkedHashMap<>();
/**
* 接口白名单(不监听异常)
*/
private Set<String> apiWhiteList = new HashSet<>();

// -------企业微信通知配置 start
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public class ApiHealthRepository implements InitializingBean, DisposableBean {
*/
public void add(String name, boolean success, Exception exception) {
try {
if (healthProperties.getApiWhiteList().contains(name)) {
return;
}

ApiHealthCacheDTO apiHealthCacheDTO = apiStatusStatistics.computeIfAbsent(name, createApiHealthCacheDtoFunction);
if (success) {
apiHealthCacheDTO.getSuccessCount().increment();
Expand Down Expand Up @@ -116,7 +120,7 @@ public List<UnHealthApiDTO> getUnHealthInfos() {
* @param failRate
* @return
*/
private final boolean isUnHealth(String name, BigDecimal total, BigDecimal failRate) {
private boolean isUnHealth(String name, BigDecimal total, BigDecimal failRate) {
BigDecimal failRateThreshold = healthProperties.getFailRateThresholds().getOrDefault(name, healthProperties.getDefaultFailRateThreshold());
return (total.intValue() >= healthProperties.getUnhealthMatchMinCount()) && (failRate.compareTo(failRateThreshold) >= 0);
}
Expand Down

0 comments on commit 60b7c2a

Please sign in to comment.