提交 3470b1d5 authored 作者: Edwin's avatar Edwin

feat: enhance alarm message filtering by normalizing endpoint paths and…

feat: enhance alarm message filtering by normalizing endpoint paths and improving service name resolution
上级 a42acfa4
...@@ -133,17 +133,21 @@ public class AlarmServiceImpl implements AlarmService { ...@@ -133,17 +133,21 @@ public class AlarmServiceImpl implements AlarmService {
} }
private boolean shouldSkip(AlarmMessage alarmMessage) { private boolean shouldSkip(AlarmMessage alarmMessage) {
String scope = alarmMessage.getScope(); String rawMessage = alarmMessage.getAlarmMessage();
String name = alarmMessage.getName(); if (rawMessage == null) {
if (StringUtil.isBlank(name)) { rawMessage = "";
return false;
} }
if (SERVICE.equals(scope)) { String serviceName = resolveServiceName(alarmMessage, rawMessage);
return splitToSet(projProperties.getNotNotifyService()).contains(name); if (!StringUtil.isBlank(serviceName)
&& splitToSet(projProperties.getNotNotifyService()).contains(serviceName)) {
log.info("Skip alarm for blocked service: {}", serviceName);
return true;
} }
if (ENDPOINT_RELATION.equalsIgnoreCase(scope)) { String endpointPath = normalizeEndpointPath(resolveEndpointPath(alarmMessage, rawMessage));
String pathUrl = extractPathUrl(name); if (!StringUtil.isBlank(endpointPath)
return !StringUtil.isBlank(pathUrl) && splitToSet(projProperties.getNotNotifyUrl()).contains(pathUrl); && splitToSet(projProperties.getNotNotifyUrl()).contains(endpointPath)) {
log.info("Skip alarm for blocked endpoint: {}", endpointPath);
return true;
} }
return false; return false;
} }
...@@ -533,6 +537,18 @@ public class AlarmServiceImpl implements AlarmService { ...@@ -533,6 +537,18 @@ public class AlarmServiceImpl implements AlarmService {
return name.substring(slashIndex, blankIndex); return name.substring(slashIndex, blankIndex);
} }
private String normalizeEndpointPath(String endpointPath) {
if (StringUtil.isBlank(endpointPath)) {
return "";
}
String trimmed = endpointPath.trim();
int colonIndex = trimmed.indexOf(':');
if (colonIndex > 0 && colonIndex < trimmed.length() - 1 && trimmed.charAt(colonIndex + 1) == '/') {
return trimmed.substring(colonIndex + 1);
}
return trimmed;
}
private Set<String> splitToSet(String value) { private Set<String> splitToSet(String value) {
if (StringUtil.isBlank(value)) { if (StringUtil.isBlank(value)) {
return Collections.emptySet(); return Collections.emptySet();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论