refactor fireEvent

This commit is contained in:
Ulric Qin 2021-12-23 22:43:18 +08:00
parent 218140066b
commit 1ea8694769
1 changed files with 18 additions and 17 deletions

View File

@ -288,24 +288,8 @@ func labelMapToArr(m map[string]string) []string {
}
func (r RuleEval) handleNewEvent(event *models.AlertCurEvent) {
if fired, has := r.fires[event.Hash]; has {
if r.rule.NotifyRepeatStep == 0 {
// 说明不想重复通知那就直接返回了nothing to do
return
}
// 之前发送过告警了,这次是否要继续发送,要看是否过了通道静默时间
if event.LastEvalTime > fired.LastEvalTime+int64(r.rule.NotifyRepeatStep)*60 {
r.fires[event.Hash] = event
pushEventToQueue(event)
}
return
}
if event.PromForDuration == 0 {
r.fires[event.Hash] = event
pushEventToQueue(event)
r.fireEvent(event)
return
}
@ -317,6 +301,23 @@ func (r RuleEval) handleNewEvent(event *models.AlertCurEvent) {
}
if r.pendings[event.Hash].LastEvalTime-r.pendings[event.Hash].TriggerTime > int64(event.PromForDuration) {
r.fireEvent(event)
}
}
func (r RuleEval) fireEvent(event *models.AlertCurEvent) {
if fired, has := r.fires[event.Hash]; has {
if r.rule.NotifyRepeatStep == 0 {
// 说明不想重复通知那就直接返回了nothing to do
return
}
// 之前发送过告警了,这次是否要继续发送,要看是否过了通道静默时间
if event.LastEvalTime > fired.LastEvalTime+int64(r.rule.NotifyRepeatStep)*60 {
r.fires[event.Hash] = event
pushEventToQueue(event)
}
} else {
r.fires[event.Hash] = event
pushEventToQueue(event)
}