-
Notifications
You must be signed in to change notification settings - Fork 1k
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(swarm): expose duration of a connection #3135
Comments
I've been wondering, would it make more sense to implement a I think that might be easier to integrate compared to hooking into their event loop. |
Good thought @thomaseizinger! I think this would be significantly less intrusive than the current approach. How would one capture events from other Something along the lines of: #[derive(NetworkBehaviour)]
struct MyBehaviour {
floodsub: Floodsub,
mdns: Mdns,
}
let my_behaviour = MyBehaviour::default();
let my_instrumented_behaviour = libp2p_metrics::Behaviour::new(my_behaviour); I would guess that this needs some macro magic. Not to say that it is not worth exploring. |
Either a wrapper as you said or we add metrics to the individual behaviours. |
Something like the following could work: pub struct RecordBehaviour<B, M> {
inner: B,
metrics: M
}
impl<B, M> NetworkBehaviour for RecordBehaviour<B, M> where M: Recorder<B::OutEvent> {
}
impl Deref for RecordBehaviour<B, M> { }
impl DerefMut for RecordBehaviour<B, M> { } Instead of |
@thomaseizinger Could you provide me with a little more detail on how to implement it (the overall roadmap)? If I understand how to do it, I could support this issue :) |
I think the above suggestion of a new abstraction requires some exploratory work, along the lines of "How can we make the integration of the current In regards to the concrete issue, namely to expose the lifetime (duration) of a connection, I would suggest the following:
What do you think @tcoratger? Is this of some help? |
As Max said, I think this still needs some fleshing out. We should likely not block this issue on it but proceed the way Max suggested above. I'll open a separate issue to discuss that. |
Done: #3868 |
Description
Expose the duration a connection was alive.
I would assume the easiest way to expose this is via
SwarmEvent::ConnectionClosed
.rust-libp2p/swarm/src/lib.rs
Lines 195 to 207 in 7803524
Motivation
Needed for monitoring purposes, e.g. to be exposed to Prometheus via libp2p-metrics.
Current Implementation
Are you planning to do it yourself in a pull request?
No
The text was updated successfully, but these errors were encountered: