mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-13 17:43:26 +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 close(ag.done)
|
||||||
defer ag.next.Stop()
|
defer ag.next.Stop()
|
||||||
|
|
||||||
|
timeout := ag.opts.GroupInterval
|
||||||
|
|
||||||
|
if timeout < notify.MinTimeout {
|
||||||
|
timeout = notify.MinTimeout
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case now := <-ag.next.C:
|
case now := <-ag.next.C:
|
||||||
// Give the notifcations time until the next flush to
|
// Give the notifcations time until the next flush to
|
||||||
// finish before terminating them.
|
// 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
|
// The now time we retrieve from the ticker is the only reliable
|
||||||
// point of time reference for the subsequent notification pipeline.
|
// 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.
|
// which usually only becomes apparent in tests.
|
||||||
ctx = notify.WithNow(ctx, now)
|
ctx = notify.WithNow(ctx, now)
|
||||||
|
|
||||||
@ -223,6 +229,8 @@ func (ag *aggrGroup) run(nf notifyFunc) {
|
|||||||
return nf(ctx, alerts...)
|
return nf(ctx, alerts...)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
|
||||||
case <-ag.ctx.Done():
|
case <-ag.ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ import (
|
|||||||
"github.com/prometheus/alertmanager/types"
|
"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
|
type notifyKey int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user