Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
39 changes: 30 additions & 9 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,8 @@ struct Metrics {
// This list is ordered alphabetically
connections_closed_total: CounterVec<U64>,
connections_opened_total: CounterVec<U64>,
distinct_peers_connections_closed_total: CounterVec<U64>,
distinct_peers_connections_opened_total: CounterVec<U64>,
import_queue_blocks_submitted: Counter<U64>,
import_queue_finality_proofs_submitted: Counter<U64>,
import_queue_justifications_submitted: Counter<U64>,
Expand Down Expand Up @@ -889,16 +891,30 @@ impl Metrics {
connections_closed_total: register(CounterVec::new(
Opts::new(
"sub_libp2p_connections_closed_total",
"Total number of connections closed, by direction, reason and by being the first or not"
"Total number of connections closed, by direction and reason"
),
&["direction", "reason", "was_first"]
&["direction", "reason"]
)?, registry)?,
connections_opened_total: register(CounterVec::new(
Opts::new(
"sub_libp2p_connections_opened_total",
"Total number of connections opened by direction and by being the first or not"
"Total number of connections opened by direction"
),
&["direction", "is_first"]
&["direction"]
)?, registry)?,
distinct_peers_connections_closed_total: register(CounterVec::new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
distinct_peers_connections_closed_total: register(CounterVec::new(
distinct_peers_connections_closed_total: register(Counter::new(

Opts::new(
"sub_libp2p_distinct_peers_connections_closed_total",
"Total number of connections closed with distinct peers, by direction and reason"
),
&["direction", "reason"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&["direction", "reason"]

I didn't think about it, but I don't think it makes sense to have the direction or reason on these metrics.

It would be misleading to report a single direction while we might have multiple connections with multiple directions.

Similarly, the reason here is the reason for closing the last connection, which to me makes the last connection special while it shouldn't be.
For instance, if a severe protocol error happens on the "main" connection, we immediately close it and also close all the other connections to that same peer afterwards. The reason reported here would be the one of the other connection (if any), which doesn't really make sense.

)?, registry)?,
distinct_peers_connections_opened_total: register(CounterVec::new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea: remove the direction.

Suggested change
distinct_peers_connections_opened_total: register(CounterVec::new(
distinct_peers_connections_opened_total: register(Counter::new(

Opts::new(
"sub_libp2p_distinct_peers_connections_opened_total",
"Total number of connections opened with distinct peers by direction"
),
&["direction"]
)?, registry)?,
import_queue_blocks_submitted: register(Counter::new(
"import_queue_blocks_submitted",
Expand Down Expand Up @@ -1222,9 +1238,12 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
ConnectedPoint::Dialer { .. } => "out",
ConnectedPoint::Listener { .. } => "in",
};
let is_first = if num_established.get() == 1 { "true" } else { "false" };

metrics.connections_opened_total.with_label_values(&[direction, is_first]).inc();
metrics.connections_opened_total.with_label_values(&[direction]).inc();

if num_established.get() == 1 {
metrics.distinct_peers_connections_opened_total.with_label_values(&[direction]).inc();
}
}
},
Poll::Ready(SwarmEvent::ConnectionClosed { peer_id, cause, endpoint, num_established }) => {
Expand All @@ -1247,10 +1266,12 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
ConnectionError::Handler(NodeHandlerWrapperError::KeepAliveTimeout) => "keep-alive-timeout",
};

// `num_established` represents the number of *remaining* connections.
let was_first = if num_established == 0 { "true" } else { "false" };
metrics.connections_closed_total.with_label_values(&[direction, reason]).inc();

metrics.connections_closed_total.with_label_values(&[direction, reason, was_first]).inc();
// `num_established` represents the number of *remaining* connections.
if num_established == 0 {
metrics.distinct_peers_connections_closed_total.with_label_values(&[direction, reason]).inc();
}
}
},
Poll::Ready(SwarmEvent::NewListenAddr(addr)) => {
Expand Down