Skip to content

Commit

Permalink
And logging peer reports
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-ssvlabs committed Dec 2, 2024
1 parent 73b6b24 commit 9624542
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
1 change: 0 additions & 1 deletion cli/operator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ var StartNodeCmd = &cobra.Command{
}
}

cfg.P2pNetworkConfig.Metrics = metricsReporter
cfg.P2pNetworkConfig.MessageValidator = messageValidator
cfg.SSVOptions.ValidatorOptions.MessageValidator = messageValidator

Expand Down
3 changes: 0 additions & 3 deletions network/p2p/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"go.uber.org/zap"

"github.com/ssvlabs/ssv/message/validation"
"github.com/ssvlabs/ssv/monitoring/metricsreporter"
"github.com/ssvlabs/ssv/network"
"github.com/ssvlabs/ssv/network/commons"
"github.com/ssvlabs/ssv/networkconfig"
Expand Down Expand Up @@ -75,8 +74,6 @@ type Config struct {
Network networkconfig.NetworkConfig
// MessageValidator validates incoming messages.
MessageValidator validation.MessageValidator
// Metrics report metrics.
Metrics metricsreporter.MetricsReporter

PubsubMsgCacheTTL time.Duration `yaml:"PubsubMsgCacheTTL" env:"PUBSUB_MSG_CACHE_TTL" env-description:"How long a message ID will be remembered as seen"`
PubsubOutQueueSize int `yaml:"PubsubOutQueueSize" env:"PUBSUB_OUT_Q_SIZE" env-description:"The size that we assign to the outbound pubsub message queue"`
Expand Down
7 changes: 5 additions & 2 deletions network/p2p/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.uber.org/zap"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/ssvlabs/ssv/network/peers"
Expand Down Expand Up @@ -45,8 +46,9 @@ func metricName(name string) string {
return fmt.Sprintf("%s.%s", observabilityNamespace, name)
}

func recordPeerCount(ctx context.Context, peers []peer.ID) func() {
func recordPeerCount(ctx context.Context, logger *zap.Logger, peers []peer.ID) func() {
return func() {
logger.Info("reporting total number of peers", zap.Int("peer_count", len(peers)))
peersConnectedGauge.Record(ctx, int64(len(peers)))
}
}
Expand All @@ -63,9 +65,10 @@ func recordPeerCountPerTopic(ctx context.Context, ctrl topics.Controller) func()
}
}

func recordPeerIdentities(ctx context.Context, peers []peer.ID, index peers.Index) func() {
func recordPeerIdentities(ctx context.Context, logger *zap.Logger, peers []peer.ID, index peers.Index) func() {
return func() {
peersByVersion := make(map[string]int64)
logger.Info("reporting peer identities", zap.Int("peer_count", len(peers)))
for _, pid := range peers {
nodeVersion := "unknown"
ni := index.NodeInfo(pid)
Expand Down
11 changes: 4 additions & 7 deletions network/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (
connManagerBalancingInterval = 3 * time.Minute
connManagerBalancingTimeout = time.Minute
peersReportingInterval = 60 * time.Second
peerIdentitiesReportingInterval = 5 * time.Minute
peerIdentitiesReportingInterval = time.Minute
topicsReportingInterval = 180 * time.Second
maximumIrrelevantPeersToDisconnect = 3
)
Expand Down Expand Up @@ -258,14 +258,11 @@ func (n *p2pNetwork) Start(logger *zap.Logger) error {

async.Interval(n.ctx, connManagerBalancingInterval, n.peersBalancing(logger))

// don't report metrics in tests
if n.cfg.Metrics != nil {
async.Interval(n.ctx, peersReportingInterval, recordPeerCount(n.ctx, n.host.Network().Peers()))
async.Interval(n.ctx, peersReportingInterval, recordPeerCount(n.ctx, logger, n.host.Network().Peers()))

async.Interval(n.ctx, peerIdentitiesReportingInterval, recordPeerIdentities(n.ctx, n.host.Network().Peers(), n.idx))
async.Interval(n.ctx, peerIdentitiesReportingInterval, recordPeerIdentities(n.ctx, logger, n.host.Network().Peers(), n.idx))

async.Interval(n.ctx, topicsReportingInterval, recordPeerCountPerTopic(n.ctx, n.topicsCtrl))
}
async.Interval(n.ctx, topicsReportingInterval, recordPeerCountPerTopic(n.ctx, n.topicsCtrl))

if err := n.subscribeToSubnets(logger); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion network/p2p/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ func (ln *LocalNet) NewTestP2pNetwork(ctx context.Context, nodeIndex uint64, key
cfg.Ctx = ctx
cfg.Subnets = "00000000000000000100000400000400" // calculated for topics 64, 90, 114; PAY ATTENTION for future test scenarios which use more than one eth-validator we need to make this field dynamically changing
cfg.NodeStorage = nodeStorage
cfg.Metrics = nil
cfg.MessageValidator = validation.New(
networkconfig.TestNetwork,
nodeStorage.ValidatorStore(),
Expand Down

0 comments on commit 9624542

Please sign in to comment.