Skip to content

Commit

Permalink
feat(gossipsub): allow whitelisting topics for metrics
Browse files Browse the repository at this point in the history
Some topic subscription metrics were are not registered due to the max topics registered metrics config option.

This PR allows whitelisting topics we want store metrics for.
This is is helpful in the Ethereum network to make sure we cover all the attestation subnets

Pull-Request: #5895.
  • Loading branch information
jxs authored Feb 27, 2025
1 parent d41d6df commit b29c2f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 0.48.1
- Allow whitelisting topics for metrics to ensure metrics are recorded correctly for these topics.
See [PR 5895](https://github.com/libp2p/rust-libp2p/pull/5895)

- Improve `max_messages_per_rpc` consistency by ensuring RPC control messages also adhere to the existing limits.
See [PR 5826](https://github.com/libp2p/rust-libp2p/pull/5826)

Expand Down
7 changes: 7 additions & 0 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,13 @@ where
}
}
}

/// Register topics to ensure metrics are recorded correctly for these topics.
pub fn register_topics_for_metrics(&mut self, topics: Vec<TopicHash>) {
if let Some(metrics) = &mut self.metrics {
metrics.register_allowed_topics(topics);
}
}
}

fn get_ip_addr(addr: &Multiaddr) -> Option<IpAddr> {
Expand Down
7 changes: 7 additions & 0 deletions protocols/gossipsub/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,13 @@ impl Metrics {
metric.set(metric.get() - 1);
}
}

/// Registers a set of topics that we want to store calculate metrics for.
pub(crate) fn register_allowed_topics(&mut self, topics: Vec<TopicHash>) {
for topic_hash in topics {
self.topic_info.insert(topic_hash, true);
}
}
}

/// Reasons why a peer was included in the mesh.
Expand Down

0 comments on commit b29c2f6

Please sign in to comment.