More gossipsub metrics (#6873)

N/A


  Add metrics that tell us if a duplicate message that we received was from a mesh peer or from a non mesh peer that we requested with iwant message.
This commit is contained in:
Pawan Dhananjay
2025-01-29 11:42:10 -08:00
committed by GitHub
parent 6973184b06
commit e7ea69647a
3 changed files with 63 additions and 0 deletions

View File

@@ -1841,6 +1841,30 @@ where
peer_score.duplicated_message(propagation_source, &msg_id, &message.topic);
}
self.mcache.observe_duplicate(&msg_id, propagation_source);
// track metrics for the source of the duplicates
if let Some(metrics) = self.metrics.as_mut() {
if self
.mesh
.get(&message.topic)
.is_some_and(|peers| peers.contains(propagation_source))
{
// duplicate was received from a mesh peer
metrics.mesh_duplicates(&message.topic);
} else if self
.gossip_promises
.contains_peer(&msg_id, propagation_source)
{
// duplicate was received from an iwant request
metrics.iwant_duplicates(&message.topic);
} else {
tracing::warn!(
messsage=%msg_id,
peer=%propagation_source,
topic=%message.topic,
"Peer should not have sent message"
);
}
}
return;
}

View File

@@ -41,6 +41,13 @@ impl GossipPromises {
self.promises.contains_key(message)
}
/// Returns true if the message id exists in the promises and contains the given peer.
pub(crate) fn contains_peer(&self, message: &MessageId, peer: &PeerId) -> bool {
self.promises
.get(message)
.is_some_and(|peers| peers.contains_key(peer))
}
///Get the peers we sent IWANT the input message id.
pub(crate) fn peers_for_message(&self, message_id: &MessageId) -> Vec<PeerId> {
self.promises

View File

@@ -194,6 +194,12 @@ pub(crate) struct Metrics {
/// Number of full messages we received that we previously sent a IDONTWANT for.
idontwant_messages_ignored_per_topic: Family<TopicHash, Counter>,
/// Count of duplicate messages we have received from mesh peers for a given topic.
mesh_duplicates: Family<TopicHash, Counter>,
/// Count of duplicate messages we have received from by requesting them over iwant for a given topic.
iwant_duplicates: Family<TopicHash, Counter>,
/// The size of the priority queue.
priority_queue_size: Histogram,
/// The size of the non-priority queue.
@@ -359,6 +365,16 @@ impl Metrics {
"IDONTWANT messages that were sent but we received the full message regardless"
);
let mesh_duplicates = register_family!(
"mesh_duplicates_per_topic",
"Count of duplicate messages received from mesh peers per topic"
);
let iwant_duplicates = register_family!(
"iwant_duplicates_per_topic",
"Count of duplicate messages received from non-mesh peers that we sent iwants for"
);
let idontwant_bytes = {
let metric = Counter::default();
registry.register(
@@ -425,6 +441,8 @@ impl Metrics {
idontwant_msgs_ids,
idontwant_messages_sent_per_topic,
idontwant_messages_ignored_per_topic,
mesh_duplicates,
iwant_duplicates,
priority_queue_size,
non_priority_queue_size,
}
@@ -597,6 +615,20 @@ impl Metrics {
}
}
/// Register a duplicate message received from a mesh peer.
pub(crate) fn mesh_duplicates(&mut self, topic: &TopicHash) {
if self.register_topic(topic).is_ok() {
self.mesh_duplicates.get_or_create(topic).inc();
}
}
/// Register a duplicate message received from a non-mesh peer on an iwant request.
pub(crate) fn iwant_duplicates(&mut self, topic: &TopicHash) {
if self.register_topic(topic).is_ok() {
self.iwant_duplicates.get_or_create(topic).inc();
}
}
pub(crate) fn register_msg_validation(
&mut self,
topic: &TopicHash,