Skip to content

Commit

Permalink
bugfix some alarm message can not be triggered normally (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Jul 4, 2023
1 parent e6764e6 commit dfd80ed
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void calculate(CollectRep.MetricsData metricsData) {
int defineTimes = define.getTimes() == null ? 1 : define.getTimes();
if (times >= defineTimes) {
triggeredAlertMap.remove(monitorAlertKey);
alarmCommonReduce.reduceAndSendAlarm(triggeredAlert);
alarmCommonReduce.reduceAndSendAlarm(triggeredAlert.clone());
}
} else {
fieldValueMap.put("app", app);
Expand Down Expand Up @@ -311,7 +311,7 @@ private void handlerMonitorAvailableAlert(long monitorId, String app, CollectRep
int defineTimes = avaAlertDefine.getTimes() == null ? 1 : avaAlertDefine.getTimes();
if (times >= defineTimes) {
preAlert.setStatus(CommonConstants.ALERT_STATUS_CODE_PENDING);
alarmCommonReduce.reduceAndSendAlarm(preAlert);
alarmCommonReduce.reduceAndSendAlarm(preAlert.clone());
unAvailableMonitors.add(monitorId);
} else {
preAlert.setStatus(CommonConstants.ALERT_STATUS_CODE_NOT_REACH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.dromara.hertzbeat.common.entity.manager.TagItem;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -90,24 +91,32 @@ public boolean filterConverge(Alert currentAlert) {
if (evalInterval <= 0) {
return true;
}
int alertHash = Objects.hash(currentAlert.getPriority(), currentAlert.getTags());
int alertHash = Objects.hash(currentAlert.getPriority())
+ Arrays.hashCode(currentAlert.getTags().keySet().toArray(new String[0]))
+ Arrays.hashCode(currentAlert.getTags().values().toArray(new String[0]));
Alert preAlert = converageAlertMap.get(alertHash);
if (preAlert == null) {
currentAlert.setTimes(1);
currentAlert.setFirstAlarmTime(now);
currentAlert.setLastAlarmTime(now);
converageAlertMap.put(alertHash, currentAlert);
converageAlertMap.put(alertHash, currentAlert.clone());
return true;
} else {
if (now - preAlert.getFirstAlarmTime() < evalInterval) {
preAlert.setTimes(preAlert.getTimes() + 1);
preAlert.setLastAlarmTime(now);
return false;
} else {
currentAlert.setTimes(preAlert.getTimes() + 1);
currentAlert.setFirstAlarmTime(preAlert.getFirstAlarmTime());
currentAlert.setTimes(preAlert.getTimes());
if (preAlert.getTimes() == 1) {
currentAlert.setFirstAlarmTime(now);
} else {
currentAlert.setFirstAlarmTime(preAlert.getFirstAlarmTime());
}
currentAlert.setLastAlarmTime(now);
converageAlertMap.remove(alertHash);
preAlert.setFirstAlarmTime(now);
preAlert.setLastAlarmTime(now);
preAlert.setTimes(1);
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"alert.center.status": "Status",
"alert.center.time": "Alert Time",
"alert.center.time.tip": "Alerts were triggered {{times}} times during this alert period",
"alert.center.first-time": "First Time",
"alert.center.first-time": "Start Time",
"alert.center.last-time": "Latest Time",
"alert.center.notify.no-delete": "No items selected for deletion!",
"alert.center.confirm.delete": "Please confirm whether to delete!",
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"alert.center.status": "状态",
"alert.center.time": "告警时间",
"alert.center.time.tip": "此告警期间统计触发 {{times}} 次告警",
"alert.center.first-time": "首次",
"alert.center.first-time": "开始",
"alert.center.last-time": "最新",
"alert.center.notify.no-delete": "未选中任何待删除项!",
"alert.center.confirm.delete": "请确认是否删除!",
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/assets/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"alert.center.status": "狀態",
"alert.center.time": "告警時間",
"alert.center.time.tip": "此告警期間統計觸發 {{times}} 次告警",
"alert.center.first-time": "首次",
"alert.center.first-time": "開始",
"alert.center.last-time": "最新",
"alert.center.notify.no-delete": "未選中任何待刪除項!",
"alert.center.confirm.delete": "請確認是否刪除!",
Expand Down

0 comments on commit dfd80ed

Please sign in to comment.