Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added p2p debugger setter #5587

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/seednode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/multiversx/mx-chain-go/cmd/seednode/api"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
p2pDebug "github.com/multiversx/mx-chain-go/debug/p2p"
"github.com/multiversx/mx-chain-go/epochStart/bootstrap/disabled"
"github.com/multiversx/mx-chain-go/facade"
cryptoFactory "github.com/multiversx/mx-chain-go/factory/crypto"
Expand Down Expand Up @@ -271,7 +272,17 @@ func createNode(
Logger: logger.GetOrCreate("seed/p2p"),
}

return p2pFactory.NewNetworkMessenger(arg)
netMessenger, err := p2pFactory.NewNetworkMessenger(arg)
if err != nil {
return nil, err
}

err = netMessenger.SetDebugger(p2pDebug.NewP2PDebugger(netMessenger.ID()))
if err != nil {
return nil, err
}

return netMessenger, err
}

func displayMessengerInfo(messenger p2p.Messenger) {
Expand Down
3 changes: 3 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,6 @@ const MetricTrieSyncNumReceivedBytes = "erd_trie_sync_num_bytes_received"

// MetricTrieSyncNumProcessedNodes is the metric that outputs the number of trie nodes processed for accounts during trie sync
const MetricTrieSyncNumProcessedNodes = "erd_trie_sync_num_nodes_processed"

// FullArchiveMetricSuffix is the suffix added to metrics specific for full archive network
const FullArchiveMetricSuffix = "_full_archive"
5 changes: 5 additions & 0 deletions common/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ func AssignShardForPubKeyWhenNotSpecified(pubKey []byte, numShards uint32) uint3

return randomShardID
}

// SuffixedMetric appends the suffix to the provided metric and returns it
func SuffixedMetric(metric string, suffix string) string {
return fmt.Sprintf("%s%s", metric, suffix)
}
13 changes: 13 additions & 0 deletions common/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,16 @@ func testProcessDestinationShardAsObserver(providedShard string, expectedShard u
require.Equal(t, expectedShard, shard)
}
}

func TestSuffixedMetric(t *testing.T) {
t.Parallel()

providedMetric := common.MetricP2PPeerInfo
providedSuffix := ""
expectedMetric := providedMetric
require.Equal(t, expectedMetric, common.SuffixedMetric(providedMetric, providedSuffix))

providedSuffix = common.FullArchiveMetricSuffix
expectedMetric = providedMetric + providedSuffix
require.Equal(t, expectedMetric, common.SuffixedMetric(providedMetric, providedSuffix))
}
6 changes: 6 additions & 0 deletions factory/network/networkComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/consensus"
p2pDebug "github.com/multiversx/mx-chain-go/debug/p2p"
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/factory/disabled"
Expand Down Expand Up @@ -261,6 +262,11 @@ func (ncf *networkComponentsFactory) createNetworkHolder(
return networkComponentsHolder{}, err
}

err = networkMessenger.SetDebugger(p2pDebug.NewP2PDebugger(networkMessenger.ID()))
if err != nil {
return networkComponentsHolder{}, err
}

return networkComponentsHolder{
netMessenger: networkMessenger,
preferredPeersHolder: peersHolder,
Expand Down
6 changes: 4 additions & 2 deletions factory/status/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ func (pc *statusComponents) EpochStartEventHandler() epochStart.ActionHandler {
func ComputeNumConnectedPeers(
appStatusHandler core.AppStatusHandler,
netMessenger p2p.Messenger,
suffix string,
) {
computeNumConnectedPeers(appStatusHandler, netMessenger)
computeNumConnectedPeers(appStatusHandler, netMessenger, suffix)
}

// ComputeConnectedPeers -
func ComputeConnectedPeers(
appStatusHandler core.AppStatusHandler,
netMessenger p2p.Messenger,
suffix string,
) {
computeConnectedPeers(appStatusHandler, netMessenger)
computeConnectedPeers(appStatusHandler, netMessenger, suffix)
}

// MakeHostDriversArgs -
Expand Down
48 changes: 32 additions & 16 deletions factory/status/statusComponentsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,17 @@ func registerPollConnectedPeers(
if check.IfNil(networkComponents) {
return
}
netMessenger := networkComponents.NetworkMessenger()
if check.IfNil(netMessenger) {
mainNetMessenger := networkComponents.NetworkMessenger()
if check.IfNil(mainNetMessenger) {
return
}
computeMetricsForMessenger(appStatusHandler, mainNetMessenger, "")

computeNumConnectedPeers(appStatusHandler, netMessenger)
computeConnectedPeers(appStatusHandler, netMessenger)
fullArchiveNetMessenger := networkComponents.FullArchiveNetworkMessenger()
if check.IfNil(fullArchiveNetMessenger) {
return
}
computeMetricsForMessenger(appStatusHandler, fullArchiveNetMessenger, common.FullArchiveMetricSuffix)
}

err := appStatusPollingHandler.RegisterPollingFunc(p2pMetricsHandlerFunc)
Expand Down Expand Up @@ -263,17 +267,28 @@ func registerShardsInformation(
return nil
}

func computeMetricsForMessenger(
appStatusHandler core.AppStatusHandler,
netMessenger p2p.Messenger,
suffix string,
) {
computeNumConnectedPeers(appStatusHandler, netMessenger, suffix)
computeConnectedPeers(appStatusHandler, netMessenger, suffix)
}

func computeNumConnectedPeers(
appStatusHandler core.AppStatusHandler,
netMessenger p2p.Messenger,
suffix string,
) {
numOfConnectedPeers := uint64(len(netMessenger.ConnectedAddresses()))
appStatusHandler.SetUInt64Value(common.MetricNumConnectedPeers, numOfConnectedPeers)
appStatusHandler.SetUInt64Value(common.SuffixedMetric(common.MetricNumConnectedPeers, suffix), numOfConnectedPeers)
}

func computeConnectedPeers(
appStatusHandler core.AppStatusHandler,
netMessenger p2p.Messenger,
suffix string,
) {
peersInfo := netMessenger.GetConnectedPeersInfo()

Expand All @@ -284,19 +299,19 @@ func computeConnectedPeers(
len(peersInfo.CrossShardObservers),
len(peersInfo.UnknownPeers),
)
appStatusHandler.SetStringValue(common.MetricNumConnectedPeersClassification, peerClassification)
appStatusHandler.SetStringValue(common.MetricP2PNumConnectedPeersClassification, peerClassification)
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricNumConnectedPeersClassification, suffix), peerClassification)
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricP2PNumConnectedPeersClassification, suffix), peerClassification)

setP2pConnectedPeersMetrics(appStatusHandler, peersInfo)
setCurrentP2pNodeAddresses(appStatusHandler, netMessenger)
setP2pConnectedPeersMetrics(appStatusHandler, peersInfo, suffix)
setCurrentP2pNodeAddresses(appStatusHandler, netMessenger, suffix)
}

func setP2pConnectedPeersMetrics(appStatusHandler core.AppStatusHandler, info *p2p.ConnectedPeersInfo) {
appStatusHandler.SetStringValue(common.MetricP2PUnknownPeers, sliceToString(info.UnknownPeers))
appStatusHandler.SetStringValue(common.MetricP2PIntraShardValidators, mapToString(info.IntraShardValidators))
appStatusHandler.SetStringValue(common.MetricP2PIntraShardObservers, mapToString(info.IntraShardObservers))
appStatusHandler.SetStringValue(common.MetricP2PCrossShardValidators, mapToString(info.CrossShardValidators))
appStatusHandler.SetStringValue(common.MetricP2PCrossShardObservers, mapToString(info.CrossShardObservers))
func setP2pConnectedPeersMetrics(appStatusHandler core.AppStatusHandler, info *p2p.ConnectedPeersInfo, suffix string) {
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricP2PUnknownPeers, suffix), sliceToString(info.UnknownPeers))
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricP2PIntraShardValidators, suffix), mapToString(info.IntraShardValidators))
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricP2PIntraShardObservers, suffix), mapToString(info.IntraShardObservers))
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricP2PCrossShardValidators, suffix), mapToString(info.CrossShardValidators))
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricP2PCrossShardObservers, suffix), mapToString(info.CrossShardObservers))
}

func sliceToString(input []string) string {
Expand Down Expand Up @@ -324,8 +339,9 @@ func mapToString(input map[uint32][]string) string {
func setCurrentP2pNodeAddresses(
appStatusHandler core.AppStatusHandler,
netMessenger p2p.Messenger,
suffix string,
) {
appStatusHandler.SetStringValue(common.MetricP2PPeerInfo, sliceToString(netMessenger.Addresses()))
appStatusHandler.SetStringValue(common.SuffixedMetric(common.MetricP2PPeerInfo, suffix), sliceToString(netMessenger.Addresses()))
}

func registerPollProbableHighestNonce(
Expand Down