From 8ec6f028541531755bb53a52bd8ea863a45530dd Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Wed, 9 Oct 2019 11:51:38 +0200 Subject: [PATCH] discovery: don't log errors on context cancelation Signed-off-by: Simon Pasquier --- discovery/kubernetes/endpoints.go | 4 +++- discovery/kubernetes/ingress.go | 4 +++- discovery/kubernetes/node.go | 4 +++- discovery/kubernetes/pod.go | 4 +++- discovery/kubernetes/service.go | 4 +++- discovery/refresh/refresh.go | 8 ++++++-- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index 83e39d973..93acec584 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -128,7 +128,9 @@ func (e *Endpoints) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { defer e.queue.ShutDown() if !cache.WaitForCacheSync(ctx.Done(), e.endpointsInf.HasSynced, e.serviceInf.HasSynced, e.podInf.HasSynced) { - level.Error(e.logger).Log("msg", "endpoints informer unable to sync cache") + if ctx.Err() != context.Canceled { + level.Error(e.logger).Log("msg", "endpoints informer unable to sync cache") + } return } diff --git a/discovery/kubernetes/ingress.go b/discovery/kubernetes/ingress.go index 9ad4677db..1feffa68f 100644 --- a/discovery/kubernetes/ingress.go +++ b/discovery/kubernetes/ingress.go @@ -70,7 +70,9 @@ func (i *Ingress) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { defer i.queue.ShutDown() if !cache.WaitForCacheSync(ctx.Done(), i.informer.HasSynced) { - level.Error(i.logger).Log("msg", "ingress informer unable to sync cache") + if ctx.Err() != context.Canceled { + level.Error(i.logger).Log("msg", "ingress informer unable to sync cache") + } return } diff --git a/discovery/kubernetes/node.go b/discovery/kubernetes/node.go index 973be2809..677cb74b0 100644 --- a/discovery/kubernetes/node.go +++ b/discovery/kubernetes/node.go @@ -79,7 +79,9 @@ func (n *Node) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { defer n.queue.ShutDown() if !cache.WaitForCacheSync(ctx.Done(), n.informer.HasSynced) { - level.Error(n.logger).Log("msg", "node informer unable to sync cache") + if ctx.Err() != context.Canceled { + level.Error(n.logger).Log("msg", "node informer unable to sync cache") + } return } diff --git a/discovery/kubernetes/pod.go b/discovery/kubernetes/pod.go index 4f522e96a..baf58d24b 100644 --- a/discovery/kubernetes/pod.go +++ b/discovery/kubernetes/pod.go @@ -82,7 +82,9 @@ func (p *Pod) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { defer p.queue.ShutDown() if !cache.WaitForCacheSync(ctx.Done(), p.informer.HasSynced) { - level.Error(p.logger).Log("msg", "pod informer unable to sync cache") + if ctx.Err() != context.Canceled { + level.Error(p.logger).Log("msg", "pod informer unable to sync cache") + } return } diff --git a/discovery/kubernetes/service.go b/discovery/kubernetes/service.go index 25471558c..858ef36bd 100644 --- a/discovery/kubernetes/service.go +++ b/discovery/kubernetes/service.go @@ -75,7 +75,9 @@ func (s *Service) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { defer s.queue.ShutDown() if !cache.WaitForCacheSync(ctx.Done(), s.informer.HasSynced) { - level.Error(s.logger).Log("msg", "service informer unable to sync cache") + if ctx.Err() != context.Canceled { + level.Error(s.logger).Log("msg", "service informer unable to sync cache") + } return } diff --git a/discovery/refresh/refresh.go b/discovery/refresh/refresh.go index ebc99e2e0..c48524c50 100644 --- a/discovery/refresh/refresh.go +++ b/discovery/refresh/refresh.go @@ -75,7 +75,9 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Get an initial set right away. tgs, err := d.refresh(ctx) if err != nil { - level.Error(d.logger).Log("msg", "Unable to refresh target groups", "err", err.Error()) + if ctx.Err() != context.Canceled { + level.Error(d.logger).Log("msg", "Unable to refresh target groups", "err", err.Error()) + } } else { select { case ch <- tgs: @@ -92,7 +94,9 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { case <-ticker.C: tgs, err := d.refresh(ctx) if err != nil { - level.Error(d.logger).Log("msg", "Unable to refresh target groups", "err", err.Error()) + if ctx.Err() != context.Canceled { + level.Error(d.logger).Log("msg", "Unable to refresh target groups", "err", err.Error()) + } continue }