mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-26 08:02:16 +00:00
Ensure minimum notification context timeout
This commit is contained in:
parent
0a5a7691fe
commit
42e1963715
12
dispatch.go
12
dispatch.go
@ -197,16 +197,22 @@ func (ag *aggrGroup) run(nf notifyFunc) {
|
||||
defer close(ag.done)
|
||||
defer ag.next.Stop()
|
||||
|
||||
timeout := ag.opts.GroupInterval
|
||||
|
||||
if timeout < notify.MinTimeout {
|
||||
timeout = notify.MinTimeout
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case now := <-ag.next.C:
|
||||
// Give the notifcations time until the next flush to
|
||||
// finish before terminating them.
|
||||
ctx, _ := context.WithTimeout(ag.ctx, ag.opts.GroupInterval)
|
||||
ctx, cancel := context.WithTimeout(ag.ctx, timeout)
|
||||
|
||||
// The now time we retrieve from the ticker is the only reliable
|
||||
// point of time reference for the subsequent notification pipeline.
|
||||
// Calculating the current time directly is prone to avoid flaky behavior,
|
||||
// Calculating the current time directly is prone to flaky behavior,
|
||||
// which usually only becomes apparent in tests.
|
||||
ctx = notify.WithNow(ctx, now)
|
||||
|
||||
@ -223,6 +229,8 @@ func (ag *aggrGroup) run(nf notifyFunc) {
|
||||
return nf(ctx, alerts...)
|
||||
})
|
||||
|
||||
cancel()
|
||||
|
||||
case <-ag.ctx.Done():
|
||||
return
|
||||
}
|
||||
|
@ -14,6 +14,10 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
)
|
||||
|
||||
// The minimum timeout that is set for the context of a call
|
||||
// to a notification pipeline.
|
||||
const MinTimeout = 10 * time.Second
|
||||
|
||||
type notifyKey int
|
||||
|
||||
const (
|
||||
|
Loading…
Reference in New Issue
Block a user