Ensure minimum notification context timeout

This commit is contained in:
Fabian Reinartz 2015-10-09 08:58:44 +02:00
parent 0a5a7691fe
commit 42e1963715
2 changed files with 14 additions and 2 deletions

View File

@ -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
}

View File

@ -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 (