fix repeat sender
This commit is contained in:
parent
3babc6c50a
commit
23b6cf1a68
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue