-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Observability - instrument P2P component
- Loading branch information
1 parent
8b1eebe
commit b9c7af3
Showing
6 changed files
with
86 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package p2pv1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/ssvlabs/ssv/network/peers" | ||
"github.com/ssvlabs/ssv/network/topics" | ||
"github.com/ssvlabs/ssv/observability" | ||
) | ||
|
||
const ( | ||
observabilityName = "github.com/ssvlabs/ssv/network/p2p" | ||
observabilityNamespace = "ssv.p2p.peer" | ||
) | ||
|
||
var ( | ||
meter = otel.Meter(observabilityName) | ||
|
||
peersConnectedGauge = observability.NewMetric( | ||
meter.Int64Gauge( | ||
metricName("connected"), | ||
metric.WithUnit("{peer}"), | ||
metric.WithDescription("number of connected peers"))) | ||
|
||
peersByTopicCounter = observability.NewMetric( | ||
meter.Int64Gauge( | ||
metricName("by_topic"), | ||
metric.WithUnit("{peer}"), | ||
metric.WithDescription("number of connected peers per topic"))) | ||
|
||
peerIdentityGauge = observability.NewMetric( | ||
meter.Int64Gauge( | ||
metricName("identity"), | ||
metric.WithUnit("{peer}"), | ||
metric.WithDescription("describes identities of connected peers"))) | ||
) | ||
|
||
func metricName(name string) string { | ||
return fmt.Sprintf("%s.%s", observabilityNamespace, name) | ||
} | ||
|
||
func recordPeerCount(ctx context.Context, peers []peer.ID) func() { | ||
return func() { | ||
peersConnectedGauge.Record(ctx, int64(len(peers))) | ||
} | ||
} | ||
|
||
func recordPeerCountPerTopic(ctx context.Context, ctrl topics.Controller) func() { | ||
return func() { | ||
for _, topicName := range ctrl.Topics() { | ||
peers, err := ctrl.Peers(topicName) | ||
if err != nil { | ||
return | ||
} | ||
peersByTopicCounter.Record(ctx, int64(len(peers)), metric.WithAttributes(attribute.String("ssv.p2p.topic.name", topicName))) | ||
} | ||
} | ||
} | ||
|
||
func recordPeerIdentities(ctx context.Context, peers []peer.ID, index peers.Index) func() { | ||
return func() { | ||
for _, pid := range peers { | ||
nodeVersion := "unknown" | ||
ni := index.NodeInfo(pid) | ||
if ni != nil { | ||
if ni.Metadata != nil { | ||
nodeVersion = ni.Metadata.NodeVersion | ||
} | ||
} | ||
peerIdentityGauge.Record(ctx, 1, metric.WithAttributes(attribute.String("ssv.node.version", nodeVersion))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters