From 0140ac354b0440a8f2cea4dd13ef29e7568f144f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 7 Sep 2022 10:25:03 +0300 Subject: [PATCH] [#1759] services/tree: Make logs more descriptive Signed-off-by: Evgenii Stratonikov --- pkg/services/tree/cache.go | 7 +++++-- pkg/services/tree/replicator.go | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/services/tree/cache.go b/pkg/services/tree/cache.go index e5d940ae..266a7b26 100644 --- a/pkg/services/tree/cache.go +++ b/pkg/services/tree/cache.go @@ -2,6 +2,7 @@ package tree import ( "context" + "errors" "fmt" "strings" "sync" @@ -30,6 +31,8 @@ const ( defaultReconnectInterval = time.Second * 15 ) +var errRecentlyFailed = errors.New("client has recently failed") + func (c *clientCache) init() { l, _ := simplelru.NewLRU(defaultClientCacheSize, func(key, value interface{}) { _ = value.(*grpc.ClientConn).Close() @@ -46,8 +49,8 @@ func (c *clientCache) get(ctx context.Context, netmapAddr string) (TreeServiceCl item := ccInt.(cacheItem) if item.cc == nil { if d := time.Since(item.lastTry); d < defaultReconnectInterval { - return nil, fmt.Errorf("skip connecting to %s (time since last error %s)", - netmapAddr, d) + return nil, fmt.Errorf("%w: %s till the next reconnection to %s", + errRecentlyFailed, d, netmapAddr) } } else { if s := item.cc.GetState(); s == connectivity.Idle || s == connectivity.Ready { diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index 0fc0271b..e841c3ba 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -4,6 +4,7 @@ import ( "context" "crypto/sha256" "encoding/hex" + "errors" "fmt" "time" @@ -56,10 +57,15 @@ func (s *Service) replicationWorker() { }) if lastErr != nil { - s.log.Warn("failed to sent update to the node", - zap.String("last_error", lastErr.Error()), - zap.String("address", lastAddr), - zap.String("key", hex.EncodeToString(task.n.PublicKey()))) + if errors.Is(lastErr, errRecentlyFailed) { + s.log.Debug("do not send update to the node", + zap.String("last_error", lastErr.Error())) + } else { + s.log.Warn("failed to sent update to the node", + zap.String("last_error", lastErr.Error()), + zap.String("address", lastAddr), + zap.String("key", hex.EncodeToString(task.n.PublicKey()))) + } } } }