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

[Merged by Bors] - track gossip payload/messages by protocol #3798

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 54 additions & 10 deletions p2p/metrics/gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,39 @@ var (
peersPerProtocol = metrics.NewGauge("peers_per_protocol", subsystem, "Number of peers per protocol", []string{"protocol"})
)

// ProcessedMessagesDuration in nanoseconds to process a message. Labeled by protocol and result.
var ProcessedMessagesDuration = metrics.NewHistogramWithBuckets(
"processed_messages_duration",
subsystem,
"Duration in nanoseconds to process a message",
[]string{"protocol", "result"},
prometheus.ExponentialBuckets(1_000_000, 4, 10),
var (
// ProcessedMessagesDuration in nanoseconds to process a message. Labeled by protocol and result.
ProcessedMessagesDuration = metrics.NewHistogramWithBuckets(
"processed_messages_duration",
subsystem,
"Duration in nanoseconds to process a message",
[]string{"protocol", "result"},
prometheus.ExponentialBuckets(1_000_000, 4, 10),
)
deliveredMessagesBytes = metrics.NewCounter(
"delivered_messages_bytes",
subsystem,
"Total amount of delivered payloads (doesn't count gossipsub metadata)",
[]string{"protocol"},
)
receivedMessagesBytes = metrics.NewCounter(
"received_messages_bytes",
subsystem,
"Total amount of received payloads (doesn't count gossipsub metadata)",
[]string{"protocol"},
)
deliveredMessagesCount = metrics.NewCounter(
"delivered_messages_count",
subsystem,
"Total number of delivered messages",
[]string{"protocol"},
)
receivedMessagesCount = metrics.NewCounter(
"received_messages_count",
subsystem,
"Total amount of received messages",
[]string{"protocol"},
)
)

// GossipCollector pubsub.RawTracer implementation
Expand Down Expand Up @@ -81,17 +107,35 @@ func (g *GossipCollector) Graft(peer.ID, string) {}
func (g *GossipCollector) Prune(peer.ID, string) {}

// ValidateMessage is invoked when a message first enters the validation pipeline.
func (g *GossipCollector) ValidateMessage(*pubsub.Message) {}
func (g *GossipCollector) ValidateMessage(msg *pubsub.Message) {
if msg.Topic == nil {
return
}
receivedMessagesBytes.WithLabelValues(*msg.Topic).Add(float64(len(msg.Data)))
receivedMessagesCount.WithLabelValues(*msg.Topic).Inc()
}

// DeliverMessage is invoked when a message is delivered.
func (g *GossipCollector) DeliverMessage(*pubsub.Message) {}
func (g *GossipCollector) DeliverMessage(msg *pubsub.Message) {
if msg.Topic == nil {
return
}
deliveredMessagesBytes.WithLabelValues(*msg.Topic).Add(float64(len(msg.Data)))
deliveredMessagesCount.WithLabelValues(*msg.Topic).Inc()
}

// RejectMessage is invoked when a message is Rejected or Ignored.
// The reason argument can be one of the named strings Reject*.
func (g *GossipCollector) RejectMessage(*pubsub.Message, string) {}

// DuplicateMessage is invoked when a duplicate message is dropped.
func (g *GossipCollector) DuplicateMessage(*pubsub.Message) {}
func (g *GossipCollector) DuplicateMessage(msg *pubsub.Message) {
if msg.Topic == nil {
return
}
receivedMessagesBytes.WithLabelValues(*msg.Topic).Add(float64(len(msg.Data)))
receivedMessagesCount.WithLabelValues(*msg.Topic).Inc()
}

// ThrottlePeer is invoked when a peer is throttled by the peer gater.
func (g *GossipCollector) ThrottlePeer(peer.ID) {}
Expand Down