xiaotan opened a new issue, #4069:
URL: https://github.com/apache/hertzbeat/issues/4069
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
hertzbeat\hertzbeat-alerter\src\main\java\org\apache\hertzbeat\alert\reduce\AlarmSilenceReduce.java中的checkAndSave时间判断方法,判断的是完整日期时间
/**
* Check if alert time is within silence period and update silence rule
counter
* @param now Current time
* @param alertSilence Silence rule to check
* @return true if alert should not be silenced, false if alert should
be silenced
*/
private boolean checkAndSave(LocalDateTime now, AlertSilence
alertSilence) {
boolean startMatch = alertSilence.getPeriodStart() == null
||
now.isAfter(alertSilence.getPeriodStart().toLocalDateTime());
boolean endMatch = alertSilence.getPeriodEnd() == null
||
now.isBefore(alertSilence.getPeriodEnd().toLocalDateTime());
if (startMatch && endMatch) {
int time =
Optional.ofNullable(alertSilence.getTimes()).orElse(0);
alertSilence.setTimes(time + 1);
alertSilenceDao.save(alertSilence);
return false;
}
return true;
}
周期性静默应该只判断时分格式的时间
/**
* Check if alert time is within silence period and update silence rule
counter
* @param now Current time
* @param alertSilence Silence rule to check
* @return true if alert should not be silenced, false if alert should
be silenced
*/
private boolean checkAndSave(LocalDateTime now, AlertSilence
alertSilence) {
boolean startMatch, endMatch;
if (alertSilence.getType() == 1) {
// 周期性静默 - 只比较时间部分
LocalTime nowTime = now.toLocalTime();
startMatch = alertSilence.getPeriodStart() == null
||
!nowTime.isBefore(alertSilence.getPeriodStart().toLocalTime());
endMatch = alertSilence.getPeriodEnd() == null
||
!nowTime.isAfter(alertSilence.getPeriodEnd().toLocalTime());
} else {
// 一次性静默 - 比较完整日期时间(保持原逻辑)
startMatch = alertSilence.getPeriodStart() == null
||
now.isAfter(alertSilence.getPeriodStart().toLocalDateTime());
endMatch = alertSilence.getPeriodEnd() == null
||
now.isBefore(alertSilence.getPeriodEnd().toLocalDateTime());
}
if (startMatch && endMatch) {
int time =
Optional.ofNullable(alertSilence.getTimes()).orElse(0);
alertSilence.setTimes(time + 1);
alertSilenceDao.save(alertSilence);
return false;
}
return true;
}
### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Environment
```markdown
HertzBeat version(s):
```
### Debug logs
_No response_
### Anything else?
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
notifications-unsubscr...@hertzbeat.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@hertzbeat.apache.org
For additional commands, e-mail: notifications-h...@hertzbeat.apache.org