From a5e26cc72178ad109417f268e468ca06fe28f959 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Wed, 3 Apr 2019 16:05:56 +0200 Subject: [PATCH] *: log at debug level when context is canceled Signed-off-by: Simon Pasquier --- dispatch/dispatch.go | 9 ++++++++- notify/notify.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dispatch/dispatch.go b/dispatch/dispatch.go index b19b98d6..445f0917 100644 --- a/dispatch/dispatch.go +++ b/dispatch/dispatch.go @@ -174,7 +174,14 @@ func (d *Dispatcher) processAlert(alert *types.Alert, route *Route) { go ag.run(func(ctx context.Context, alerts ...*types.Alert) bool { _, _, err := d.stage.Exec(ctx, d.logger, alerts...) if err != nil { - level.Error(d.logger).Log("msg", "Notify for alerts failed", "num_alerts", len(alerts), "err", err) + lvl := level.Error(d.logger) + if ctx.Err() == context.Canceled { + // It is expected for the context to be canceled on + // configuration reload or shutdown. In this case, the + // message should only be logged at the debug level. + lvl = level.Debug(d.logger) + } + lvl.Log("msg", "Notify for alerts failed", "num_alerts", len(alerts), "err", err) } return err == nil }) diff --git a/notify/notify.go b/notify/notify.go index cfd81469..864eda6d 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -329,7 +329,14 @@ func (fs FanoutStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.A go func(s Stage) { if _, _, err := s.Exec(ctx, l, alerts...); err != nil { me.Add(err) - level.Error(l).Log("msg", "Error on notify", "err", err) + lvl := level.Error(l) + if ctx.Err() == context.Canceled { + // It is expected for the context to be canceled on + // configuration reload or shutdown. In this case, the + // message should only be logged at the debug level. + lvl = level.Debug(l) + } + lvl.Log("msg", "Error on notify", "err", err) } wg.Done() }(s)