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

feat(gossipsub): allow whitelisting topics for metrics #5895

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
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
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
Loading