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
Prev Previous commit
Next Next commit
client/network/service: Rename is_primary to is_first
  • Loading branch information
mxinden committed Jun 23, 2020
commit 2ca29a8b23d81dd6ecce7b2cb0b8d74d1b2e97ee
27 changes: 13 additions & 14 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,16 +889,16 @@ 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 primary or not"
"Total number of connections closed, by direction, reason and by being the first or not"
),
&["direction", "reason", "was_primary"]
&["direction", "reason", "was_first"]
Copy link
Contributor

@tomaka tomaka Jun 23, 2020

Choose a reason for hiding this comment

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

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

Connections can close in a different order as they were opened.
What we report is whether the connection that has closed was the last one still open, not whether it is the one that was opened the first.

)?, registry)?,
connections_opened_total: register(CounterVec::new(
Opts::new(
"sub_libp2p_connections_opened_total",
"Total number of connections opened by direction and by being primary or not"
"Total number of connections opened by direction and by being the first or not"
),
&["direction", "is_primary"]
&["direction", "is_first"]
)?, registry)?,
import_queue_blocks_submitted: register(Counter::new(
"import_queue_blocks_submitted",
Expand Down Expand Up @@ -1217,15 +1217,14 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
Poll::Ready(SwarmEvent::ConnectionEstablished { peer_id, endpoint, num_established }) => {
trace!(target: "sub-libp2p", "Libp2p => Connected({:?})", peer_id);

let is_primary = if num_established.get() == 1 { "true" } else { "false" };

if let Some(metrics) = this.metrics.as_ref() {
match endpoint {
ConnectedPoint::Dialer { .. } =>
metrics.connections_opened_total.with_label_values(&["out", is_primary]).inc(),
ConnectedPoint::Listener { .. } =>
metrics.connections_opened_total.with_label_values(&["in", is_primary]).inc(),
}
let direction = match endpoint {
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();
}
},
Poll::Ready(SwarmEvent::ConnectionClosed { peer_id, cause, endpoint, num_established }) => {
Expand All @@ -1249,9 +1248,9 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
};

// `num_established` represents the number of *remaining* connections.
let was_primary = if num_established == 0 { "true" } else { "false" };
let was_first = if num_established == 0 { "true" } else { "false" };

metrics.connections_closed_total.with_label_values(&[direction, reason, was_primary]).inc();
metrics.connections_closed_total.with_label_values(&[direction, reason, was_first]).inc();
}
},
Poll::Ready(SwarmEvent::NewListenAddr(addr)) => {
Expand Down