fix repeat sender

This commit is contained in:
Ulric Qin 2021-12-15 19:37:55 +08:00
parent 3babc6c50a
commit 23b6cf1a68
2 changed files with 14 additions and 15 deletions

View File

@ -5,14 +5,15 @@ import (
"github.com/didi/nightingale/v5/src/server/memsto"
)
func isMuted(event *models.AlertCurEvent) bool {
// 如果传入了clock这个可选参数就表示使用这个clock表示的时间否则就从event的字段中取TriggerTime
func isMuted(event *models.AlertCurEvent, clock ...int64) bool {
mutes, has := memsto.AlertMuteCache.Gets(event.GroupId)
if !has || len(mutes) == 0 {
return false
}
for i := 0; i < len(mutes); i++ {
if matchMute(event, mutes[i]) {
if matchMute(event, mutes[i], clock...) {
return true
}
}
@ -20,8 +21,13 @@ func isMuted(event *models.AlertCurEvent) bool {
return false
}
func matchMute(event *models.AlertCurEvent, mute *models.AlertMute) bool {
if event.TriggerTime < mute.Btime || event.TriggerTime > mute.Etime {
func matchMute(event *models.AlertCurEvent, mute *models.AlertMute, clock ...int64) bool {
ts := event.TriggerTime
if len(clock) > 0 {
ts = clock[0]
}
if ts < mute.Btime || ts > mute.Etime {
return false
}

View File

@ -49,23 +49,16 @@ func repeat() {
event.DB2Mem()
// 重复通知的告警,应该用新的时间来判断是否生效和是否屏蔽,
// 不能使用TriggerTime因为TriggerTime是触发时的时间
// 先发了告警又做了屏蔽本质是不想发了如果继续用TriggerTime判断
// 就还是会发不符合预期所以这里伪装一下TriggerTime
// 判断完了再卸掉伪装
realTriggerTime := event.TriggerTime
event.TriggerTime = event.NotifyRepeatNext
if isNoneffective(event.TriggerTime, rule) {
// 不能使用TriggerTime因为TriggerTime是触发时的时间是一个比较老的时间
// 先发了告警又做了屏蔽本质是不想发了如果继续用TriggerTime判断就还是会发不符合预期
if isNoneffective(event.NotifyRepeatNext, rule) {
continue
}
if isMuted(event) {
if isMuted(event, event.NotifyRepeatNext) {
continue
}
event.TriggerTime = realTriggerTime
fillUsers(event)
notify(event)