[#1759] services/tree: Make logs more descriptive

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-07 10:25:03 +03:00 committed by LeL
parent 74c861342e
commit 0140ac354b
2 changed files with 15 additions and 6 deletions

View file

@ -2,6 +2,7 @@ package tree
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
"sync" "sync"
@ -30,6 +31,8 @@ const (
defaultReconnectInterval = time.Second * 15 defaultReconnectInterval = time.Second * 15
) )
var errRecentlyFailed = errors.New("client has recently failed")
func (c *clientCache) init() { func (c *clientCache) init() {
l, _ := simplelru.NewLRU(defaultClientCacheSize, func(key, value interface{}) { l, _ := simplelru.NewLRU(defaultClientCacheSize, func(key, value interface{}) {
_ = value.(*grpc.ClientConn).Close() _ = value.(*grpc.ClientConn).Close()
@ -46,8 +49,8 @@ func (c *clientCache) get(ctx context.Context, netmapAddr string) (TreeServiceCl
item := ccInt.(cacheItem) item := ccInt.(cacheItem)
if item.cc == nil { if item.cc == nil {
if d := time.Since(item.lastTry); d < defaultReconnectInterval { if d := time.Since(item.lastTry); d < defaultReconnectInterval {
return nil, fmt.Errorf("skip connecting to %s (time since last error %s)", return nil, fmt.Errorf("%w: %s till the next reconnection to %s",
netmapAddr, d) errRecentlyFailed, d, netmapAddr)
} }
} else { } else {
if s := item.cc.GetState(); s == connectivity.Idle || s == connectivity.Ready { if s := item.cc.GetState(); s == connectivity.Idle || s == connectivity.Ready {

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"time" "time"
@ -56,10 +57,15 @@ func (s *Service) replicationWorker() {
}) })
if lastErr != nil { if lastErr != nil {
s.log.Warn("failed to sent update to the node", if errors.Is(lastErr, errRecentlyFailed) {
zap.String("last_error", lastErr.Error()), s.log.Debug("do not send update to the node",
zap.String("address", lastAddr), zap.String("last_error", lastErr.Error()))
zap.String("key", hex.EncodeToString(task.n.PublicKey()))) } 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())))
}
} }
} }
} }