From fa6e4a3ca43296801e60aae74621062b2c2be758 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 23 Nov 2020 14:51:02 +0300 Subject: [PATCH] [#195] services/object: Write debug log messages on internal service errors Signed-off-by: Leonard Lyubich --- pkg/services/object/head/distributed.go | 9 +++++---- pkg/services/object/put/distributed.go | 12 ++++++++++-- pkg/services/object/put/streamer.go | 1 + pkg/services/object/range/streamer.go | 8 ++++---- pkg/services/object/rangehash/distributed.go | 7 ++++--- pkg/services/object/search/streamer.go | 2 +- pkg/services/object/util/log.go | 16 ++++++++++++++++ 7 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 pkg/services/object/util/log.go diff --git a/pkg/services/object/head/distributed.go b/pkg/services/object/head/distributed.go index 2356101700..7922490fdc 100644 --- a/pkg/services/object/head/distributed.go +++ b/pkg/services/object/head/distributed.go @@ -6,7 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/nspcc-dev/neofs-node/pkg/services/object/util" + svcutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/pkg/errors" ) @@ -62,7 +62,7 @@ func (h *distributedHeader) prepare(ctx context.Context, prm *Prm) error { if prm.common.LocalOnly() { // use local-only placement builder - builder = util.NewLocalPlacement(builder, h.localAddrSrc) + builder = svcutil.NewLocalPlacement(builder, h.localAddrSrc) } // set placement builder @@ -106,7 +106,7 @@ loop: if network.IsLocalAddress(h.localAddrSrc, addr) { if err := h.localHeader.head(ctx, prm, h.w.write); err != nil { - // TODO: log error + svcutil.LogServiceError(h.log, "HEAD", addr, err) } return @@ -117,7 +117,8 @@ loop: node: addr, }) if err != nil { - // TODO: log error + svcutil.LogServiceError(h.log, "HEAD", addr, err) + return } diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index 1f64035e9e..c53401fe81 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -5,9 +5,11 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" + svcutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" "github.com/nspcc-dev/neofs-node/pkg/util" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/pkg/errors" ) @@ -23,6 +25,8 @@ type distributedTarget struct { nodeTargetInitializer func(*network.Address) transformer.ObjectTarget fmt *object.FormatValidator + + log *logger.Logger } var errIncompletePut = errors.New("incomplete object put") @@ -85,10 +89,14 @@ loop: target := t.nodeTargetInitializer(addr) if err := target.WriteHeader(t.obj); err != nil { - // TODO: log error + svcutil.LogServiceError(t.log, "PUT", addr, + errors.Wrap(err, "could not write header")) + return } else if _, err := target.Close(); err != nil { - // TODO: log error + svcutil.LogServiceError(t.log, "PUT", addr, + errors.Wrap(err, "could not close object stream")) + return } diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index bc87116ba2..7049e0ea62 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -148,6 +148,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget { } }, fmt: p.fmtValidator, + log: p.log, } } diff --git a/pkg/services/object/range/streamer.go b/pkg/services/object/range/streamer.go index ebc714019a..02b202d612 100644 --- a/pkg/services/object/range/streamer.go +++ b/pkg/services/object/range/streamer.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/nspcc-dev/neofs-node/pkg/services/object/util" + svcutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/pkg/errors" ) @@ -28,7 +28,7 @@ type streamer struct { traverser *placement.Traverser - rangeTraverser *util.RangeTraverser + rangeTraverser *svcutil.RangeTraverser ch chan []byte } @@ -106,7 +106,7 @@ func (p *streamer) switchToObject(id *object.ID) error { if p.prm.common.LocalOnly() { // use local-only placement builder - builder = util.NewLocalPlacement(builder, p.localAddrSrc) + builder = svcutil.NewLocalPlacement(builder, p.localAddrSrc) } // set placement builder @@ -194,7 +194,7 @@ loop: ch: p.ch, }) if err != nil { - // TODO: log error + svcutil.LogServiceError(p.log, "RANGE", addr, err) } ln := nextRange.GetLength() diff --git a/pkg/services/object/rangehash/distributed.go b/pkg/services/object/rangehash/distributed.go index da9a45c912..f74eac57c0 100644 --- a/pkg/services/object/rangehash/distributed.go +++ b/pkg/services/object/rangehash/distributed.go @@ -6,7 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/nspcc-dev/neofs-node/pkg/services/object/util" + svcutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/pkg/errors" ) @@ -60,7 +60,7 @@ func (h *distributedHasher) prepare(ctx context.Context, prm *Prm) error { if prm.common.LocalOnly() { // use local-only placement builder - builder = util.NewLocalPlacement(builder, h.localAddrSrc) + builder = svcutil.NewLocalPlacement(builder, h.localAddrSrc) } // set placement builder @@ -119,7 +119,8 @@ loop: } if err := hasher.hashRange(ctx, prm, w.write); err != nil { - // TODO: log error + svcutil.LogServiceError(h.log, "RANGEHASH", addr, err) + return } }); err != nil { diff --git a/pkg/services/object/search/streamer.go b/pkg/services/object/search/streamer.go index 286b5ec6ff..fb3d288e72 100644 --- a/pkg/services/object/search/streamer.go +++ b/pkg/services/object/search/streamer.go @@ -169,7 +169,7 @@ loop: } if err := streamer.stream(p.ctx, p.ch); err != nil { - // TODO: log error + util.LogServiceError(p.log, "SEARCH", addr, err) } }); err != nil { wg.Done() diff --git a/pkg/services/object/util/log.go b/pkg/services/object/util/log.go new file mode 100644 index 0000000000..1ea5bbbc2f --- /dev/null +++ b/pkg/services/object/util/log.go @@ -0,0 +1,16 @@ +package util + +import ( + "github.com/nspcc-dev/neofs-node/pkg/network" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" + "go.uber.org/zap" +) + +// LogServiceError writes debug error message of object service to provided logger. +func LogServiceError(l *logger.Logger, req string, node *network.Address, err error) { + l.Debug("object service error", + zap.Stringer("node", node), + zap.String("request", req), + zap.String("error", err.Error()), + ) +}