discovery: fix more error logs on context cancelation (#6133)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2019-10-18 11:48:51 +02:00 committed by GitHub
parent 96273cc292
commit 19ce6b7f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -357,6 +357,13 @@ func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup.
elapsed := time.Since(t0) elapsed := time.Since(t0)
rpcDuration.WithLabelValues("catalog", "services").Observe(elapsed.Seconds()) rpcDuration.WithLabelValues("catalog", "services").Observe(elapsed.Seconds())
// Check the context before in order to exit early.
select {
case <-ctx.Done():
return
default:
}
if err != nil { if err != nil {
level.Error(d.logger).Log("msg", "Error refreshing service list", "err", err) level.Error(d.logger).Log("msg", "Error refreshing service list", "err", err)
rpcFailuresCount.Inc() rpcFailuresCount.Inc()

View File

@ -151,7 +151,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
wg.Add(len(d.names)) wg.Add(len(d.names))
for _, name := range d.names { for _, name := range d.names {
go func(n string) { go func(n string) {
if err := d.refreshOne(ctx, n, ch); err != nil { if err := d.refreshOne(ctx, n, ch); err != nil && err != context.Canceled {
level.Error(d.logger).Log("msg", "Error refreshing DNS targets", "err", err) level.Error(d.logger).Log("msg", "Error refreshing DNS targets", "err", err)
} }
wg.Done() wg.Done()