forked from TrueCloudLab/frostfs-node
[#1210] reputation: Improve debug logs
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
0adb29c035
commit
13af4e6046
17 changed files with 188 additions and 60 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
|
||||
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
)
|
||||
|
||||
type clientCache interface {
|
||||
|
@ -31,6 +32,7 @@ type remoteTrustProvider struct {
|
|||
deadEndProvider reputationcommon.WriterProvider
|
||||
clientCache clientCache
|
||||
remoteProvider clientKeyRemoteProvider
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
// RemoteProviderPrm groups the required parameters of the remoteTrustProvider's constructor.
|
||||
|
@ -43,6 +45,7 @@ type RemoteProviderPrm struct {
|
|||
DeadEndProvider reputationcommon.WriterProvider
|
||||
ClientCache clientCache
|
||||
WriterProvider clientKeyRemoteProvider
|
||||
Log *logger.Logger
|
||||
}
|
||||
|
||||
func NewRemoteTrustProvider(prm RemoteProviderPrm) reputationrouter.RemoteWriterProvider {
|
||||
|
@ -55,6 +58,8 @@ func NewRemoteTrustProvider(prm RemoteProviderPrm) reputationrouter.RemoteWriter
|
|||
PanicOnPrmValue("ClientCache", prm.ClientCache)
|
||||
case prm.WriterProvider == nil:
|
||||
PanicOnPrmValue("WriterProvider", prm.WriterProvider)
|
||||
case prm.Log == nil:
|
||||
PanicOnPrmValue("Logger", prm.Log)
|
||||
}
|
||||
|
||||
return &remoteTrustProvider{
|
||||
|
@ -62,16 +67,21 @@ func NewRemoteTrustProvider(prm RemoteProviderPrm) reputationrouter.RemoteWriter
|
|||
deadEndProvider: prm.DeadEndProvider,
|
||||
clientCache: prm.ClientCache,
|
||||
remoteProvider: prm.WriterProvider,
|
||||
log: prm.Log,
|
||||
}
|
||||
}
|
||||
|
||||
func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (reputationcommon.WriterProvider, error) {
|
||||
rtp.log.Debug("initializing remote writer provider")
|
||||
|
||||
if srv == nil {
|
||||
rtp.log.Debug("route has reached dead-end provider")
|
||||
return rtp.deadEndProvider, nil
|
||||
}
|
||||
|
||||
if rtp.netmapKeys.IsLocalKey(srv.PublicKey()) {
|
||||
// if local => return no-op writer
|
||||
rtp.log.Debug("initializing no-op writer provider")
|
||||
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package intermediate
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
||||
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||
consumerstorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/consumers"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var ErrIncorrectContextPanicMsg = "could not write intermediate trust: passed context incorrect"
|
||||
|
@ -28,6 +31,13 @@ type ConsumerTrustWriter struct {
|
|||
}
|
||||
|
||||
func (w *ConsumerTrustWriter) Write(t reputation.Trust) error {
|
||||
w.log.Debug("writing received consumer's trusts",
|
||||
zap.Uint64("epoch", w.eiCtx.Epoch()),
|
||||
zap.Uint32("iteration", w.eiCtx.I()),
|
||||
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
|
||||
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
|
||||
)
|
||||
|
||||
trust := eigentrust.IterationTrust{Trust: t}
|
||||
|
||||
trust.SetEpoch(w.eiCtx.Epoch())
|
||||
|
|
|
@ -2,6 +2,7 @@ package intermediate
|
|||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
||||
|
@ -70,6 +71,8 @@ type FinalWriter struct {
|
|||
}
|
||||
|
||||
func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error {
|
||||
fw.l.Debug("start writing global trusts to contract")
|
||||
|
||||
args := repClient.PutPrm{}
|
||||
|
||||
var trustedPublicKey [33]byte
|
||||
|
@ -120,6 +123,7 @@ func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error
|
|||
"sent global trust to contract",
|
||||
zap.Uint64("epoch", t.Epoch()),
|
||||
zap.Float64("value", t.Value().Float64()),
|
||||
zap.String("peer", hex.EncodeToString(t.Peer().Bytes())),
|
||||
)
|
||||
|
||||
return nil
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package intermediate
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// DaughterStorageWriterProvider is implementation of reputation.WriterProvider
|
||||
|
@ -24,6 +27,12 @@ type DaughterTrustWriter struct {
|
|||
}
|
||||
|
||||
func (w *DaughterTrustWriter) Write(t reputation.Trust) error {
|
||||
w.log.Debug("writing received daughter's trusts",
|
||||
zap.Uint64("epoch", w.ctx.Epoch()),
|
||||
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
|
||||
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
|
||||
)
|
||||
|
||||
w.storage.Put(w.ctx.Epoch(), t)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package intermediate
|
|||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
|
||||
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/internal/client"
|
||||
|
@ -9,7 +10,9 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
reputationapi "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// RemoteProviderPrm groups the required parameters of the RemoteProvider's constructor.
|
||||
|
@ -19,6 +22,7 @@ import (
|
|||
// failure (error or panic depending on the implementation).
|
||||
type RemoteProviderPrm struct {
|
||||
Key *ecdsa.PrivateKey
|
||||
Log *logger.Logger
|
||||
}
|
||||
|
||||
// NewRemoteProvider creates a new instance of the RemoteProvider.
|
||||
|
@ -31,28 +35,34 @@ func NewRemoteProvider(prm RemoteProviderPrm) *RemoteProvider {
|
|||
switch {
|
||||
case prm.Key == nil:
|
||||
common.PanicOnPrmValue("NetMapSource", prm.Key)
|
||||
case prm.Log == nil:
|
||||
common.PanicOnPrmValue("Logger", prm.Log)
|
||||
}
|
||||
|
||||
return &RemoteProvider{
|
||||
key: prm.Key,
|
||||
log: prm.Log,
|
||||
}
|
||||
}
|
||||
|
||||
// RemoteProvider is an implementation of the clientKeyRemoteProvider interface.
|
||||
type RemoteProvider struct {
|
||||
key *ecdsa.PrivateKey
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
func (rp RemoteProvider) WithClient(c coreclient.Client) reputationcommon.WriterProvider {
|
||||
return &TrustWriterProvider{
|
||||
client: c,
|
||||
key: rp.key,
|
||||
log: rp.log,
|
||||
}
|
||||
}
|
||||
|
||||
type TrustWriterProvider struct {
|
||||
client coreclient.Client
|
||||
key *ecdsa.PrivateKey
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||
|
@ -66,6 +76,7 @@ func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputa
|
|||
eiCtx: eiContext,
|
||||
client: twp.client,
|
||||
key: twp.key,
|
||||
log: twp.log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -73,10 +84,21 @@ type RemoteTrustWriter struct {
|
|||
eiCtx eigentrustcalc.Context
|
||||
client coreclient.Client
|
||||
key *ecdsa.PrivateKey
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
// Write sends trust value to remote node via ReputationService.AnnounceIntermediateResult RPC.
|
||||
func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
||||
epoch := rtp.eiCtx.Epoch()
|
||||
i := rtp.eiCtx.I()
|
||||
|
||||
rtp.log.Debug("announcing trust",
|
||||
zap.Uint64("epoch", epoch),
|
||||
zap.Uint32("iteration", i),
|
||||
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
|
||||
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
|
||||
)
|
||||
|
||||
apiTrustingPeer := reputationapi.NewPeerID()
|
||||
apiTrustingPeer.SetPublicKey(t.TrustingPeer())
|
||||
|
||||
|
@ -95,8 +117,8 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
|||
|
||||
p.SetContext(rtp.eiCtx)
|
||||
p.SetClient(rtp.client)
|
||||
p.SetEpoch(rtp.eiCtx.Epoch())
|
||||
p.SetIteration(rtp.eiCtx.I())
|
||||
p.SetEpoch(epoch)
|
||||
p.SetIteration(i)
|
||||
p.SetTrust(*apiPeerToPeerTrust)
|
||||
|
||||
_, err := internalclient.AnnounceIntermediate(p)
|
||||
|
|
|
@ -17,34 +17,18 @@ type DaughterTrustIteratorProvider struct {
|
|||
ConsumerStorage *consumerstorage.Storage
|
||||
}
|
||||
|
||||
type ErrNoData struct {
|
||||
hasDaughter bool
|
||||
daughter reputation.PeerID
|
||||
epoch uint64
|
||||
}
|
||||
|
||||
func (e *ErrNoData) Error() string {
|
||||
if e.hasDaughter {
|
||||
return fmt.Sprintf("no data in %d epoch for peer: %s", e.epoch, hex.EncodeToString(e.daughter.Bytes()))
|
||||
}
|
||||
|
||||
return fmt.Sprintf("no daughter data in %d epoch", e.epoch)
|
||||
}
|
||||
|
||||
// InitDaughterIterator returns iterator over received
|
||||
// local trusts for ctx.Epoch() epoch from daughter p.
|
||||
//
|
||||
// Returns ErrNoData if there is no trust data for
|
||||
// specified epoch and daughter's PeerId.
|
||||
func (ip *DaughterTrustIteratorProvider) InitDaughterIterator(ctx eigentrustcalc.Context,
|
||||
p reputation.PeerID) (eigentrustcalc.TrustIterator, error) {
|
||||
daughterIterator, ok := ip.DaughterStorage.DaughterTrusts(ctx.Epoch(), p)
|
||||
epoch := ctx.Epoch()
|
||||
|
||||
daughterIterator, ok := ip.DaughterStorage.DaughterTrusts(epoch, p)
|
||||
if !ok {
|
||||
return nil, &ErrNoData{
|
||||
daughter: p,
|
||||
hasDaughter: true,
|
||||
epoch: ctx.Epoch(),
|
||||
}
|
||||
return nil, fmt.Errorf("no data in %d epoch for daughter: %s",
|
||||
epoch,
|
||||
hex.EncodeToString(p.Bytes()),
|
||||
)
|
||||
}
|
||||
|
||||
return daughterIterator, nil
|
||||
|
@ -53,14 +37,13 @@ func (ip *DaughterTrustIteratorProvider) InitDaughterIterator(ctx eigentrustcalc
|
|||
// InitAllDaughtersIterator returns iterator over all
|
||||
// daughters of the current node(manager) and all local
|
||||
// trusts received from them for ctx.Epoch() epoch.
|
||||
//
|
||||
// Returns ErrNoData if there is no trust data for
|
||||
// specified epoch.
|
||||
func (ip *DaughterTrustIteratorProvider) InitAllDaughtersIterator(
|
||||
ctx eigentrustcalc.Context) (eigentrustcalc.PeerTrustsIterator, error) {
|
||||
iter, ok := ip.DaughterStorage.AllDaughterTrusts(ctx.Epoch())
|
||||
epoch := ctx.Epoch()
|
||||
|
||||
iter, ok := ip.DaughterStorage.AllDaughterTrusts(epoch)
|
||||
if !ok {
|
||||
return nil, &ErrNoData{epoch: ctx.Epoch()}
|
||||
return nil, fmt.Errorf("no data in %d epoch for daughters", epoch)
|
||||
}
|
||||
|
||||
return iter, nil
|
||||
|
@ -69,14 +52,16 @@ func (ip *DaughterTrustIteratorProvider) InitAllDaughtersIterator(
|
|||
// InitConsumersIterator returns iterator over all daughters
|
||||
// of the current node(manager) and all their consumers' local
|
||||
// trusts for ctx.Epoch() epoch and ctx.I() iteration.
|
||||
//
|
||||
// Returns ErrNoData if there is no trust data for
|
||||
// specified epoch and iteration.
|
||||
func (ip *DaughterTrustIteratorProvider) InitConsumersIterator(
|
||||
ctx eigentrustcalc.Context) (eigentrustcalc.PeerTrustsIterator, error) {
|
||||
consumerIterator, ok := ip.ConsumerStorage.Consumers(ctx.Epoch(), ctx.I())
|
||||
epoch, iter := ctx.Epoch(), ctx.I()
|
||||
|
||||
consumerIterator, ok := ip.ConsumerStorage.Consumers(epoch, iter)
|
||||
if !ok {
|
||||
return nil, &ErrNoData{epoch: ctx.Epoch()}
|
||||
return nil, fmt.Errorf("no data for %d iteration in %d epoch for consumers's trusts",
|
||||
iter,
|
||||
epoch,
|
||||
)
|
||||
}
|
||||
|
||||
return consumerIterator, nil
|
||||
|
|
|
@ -8,7 +8,9 @@ import (
|
|||
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
reputationapi "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// RemoteProviderPrm groups the required parameters of the RemoteProvider's constructor.
|
||||
|
@ -18,6 +20,7 @@ import (
|
|||
// failure (error or panic depending on the implementation).
|
||||
type RemoteProviderPrm struct {
|
||||
Key *ecdsa.PrivateKey
|
||||
Log *logger.Logger
|
||||
}
|
||||
|
||||
// NewRemoteProvider creates a new instance of the RemoteProvider.
|
||||
|
@ -30,28 +33,34 @@ func NewRemoteProvider(prm RemoteProviderPrm) *RemoteProvider {
|
|||
switch {
|
||||
case prm.Key == nil:
|
||||
common.PanicOnPrmValue("NetMapSource", prm.Key)
|
||||
case prm.Log == nil:
|
||||
common.PanicOnPrmValue("Logger", prm.Log)
|
||||
}
|
||||
|
||||
return &RemoteProvider{
|
||||
key: prm.Key,
|
||||
log: prm.Log,
|
||||
}
|
||||
}
|
||||
|
||||
// RemoteProvider is an implementation of the clientKeyRemoteProvider interface.
|
||||
type RemoteProvider struct {
|
||||
key *ecdsa.PrivateKey
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
func (rp RemoteProvider) WithClient(c coreclient.Client) reputationcommon.WriterProvider {
|
||||
return &TrustWriterProvider{
|
||||
client: c,
|
||||
key: rp.key,
|
||||
log: rp.log,
|
||||
}
|
||||
}
|
||||
|
||||
type TrustWriterProvider struct {
|
||||
client coreclient.Client
|
||||
key *ecdsa.PrivateKey
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||
|
@ -59,6 +68,7 @@ func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputa
|
|||
ctx: ctx,
|
||||
client: twp.client,
|
||||
key: twp.key,
|
||||
log: twp.log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -66,6 +76,7 @@ type RemoteTrustWriter struct {
|
|||
ctx reputationcommon.Context
|
||||
client coreclient.Client
|
||||
key *ecdsa.PrivateKey
|
||||
log *logger.Logger
|
||||
|
||||
buf []reputationapi.Trust
|
||||
}
|
||||
|
@ -85,11 +96,17 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
|||
}
|
||||
|
||||
func (rtp *RemoteTrustWriter) Close() error {
|
||||
epoch := rtp.ctx.Epoch()
|
||||
|
||||
rtp.log.Debug("announcing trusts",
|
||||
zap.Uint64("epoch", epoch),
|
||||
)
|
||||
|
||||
var prm internalclient.AnnounceLocalPrm
|
||||
|
||||
prm.SetContext(rtp.ctx)
|
||||
prm.SetClient(rtp.client)
|
||||
prm.SetEpoch(rtp.ctx.Epoch())
|
||||
prm.SetEpoch(epoch)
|
||||
prm.SetTrusts(rtp.buf)
|
||||
|
||||
_, err := internalclient.AnnounceLocal(prm)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
||||
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type TrustStorage struct {
|
||||
|
@ -23,7 +24,13 @@ type TrustStorage struct {
|
|||
}
|
||||
|
||||
func (s *TrustStorage) InitIterator(ctx reputationcommon.Context) (trustcontroller.Iterator, error) {
|
||||
epochStorage, err := s.Storage.DataForEpoch(ctx.Epoch())
|
||||
epoch := ctx.Epoch()
|
||||
|
||||
s.Log.Debug("initializing iterator over trusts",
|
||||
zap.Uint64("epoch", epoch),
|
||||
)
|
||||
|
||||
epochStorage, err := s.Storage.DataForEpoch(epoch)
|
||||
if err != nil && !errors.Is(err, truststorage.ErrNoPositiveTrust) {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue