Skip to content

Commit 2d83725

Browse files
authored
feat(metrics)!: expose identify metrics for connected peers only
Previously we would increase a counter / gauge / histogram on each received identify information. These metrics are missleading, as e.g. they depend on the identify interval and don't represent the set of currently connected peers. With this commit, identify information is tracked for the currently connected peers only. Instead of an increase on each received identify information, metrics represent the status quo (Gauge). Example: ``` \# HELP libp2p_libp2p_identify_remote_protocols Number of connected nodes supporting a specific protocol, with "unrecognized" for each peer supporting one or more unrecognized protocols... \# TYPE libp2p_libp2p_identify_remote_protocols gauge libp2p_libp2p_identify_remote_protocols_total{protocol="/ipfs/id/push/1.0.0"} 1 libp2p_libp2p_identify_remote_protocols_total{protocol="/ipfs/id/1.0.0"} 1 libp2p_libp2p_identify_remote_protocols_total{protocol="/ipfs/ping/1.0.0"} 1 libp2p_libp2p_identify_remote_protocols_total{protocol="unrecognized"} 1 \# HELP libp2p_libp2p_identify_remote_listen_addresses Number of connected nodes advertising a specific listen address... \# TYPE libp2p_libp2p_identify_remote_listen_addresses gauge libp2p_libp2p_identify_remote_listen_addresses_total{listen_address="/ip4/tcp"} 1 libp2p_libp2p_identify_remote_listen_addresses_total{listen_address="/ip4/udp/quic"} 1 \# HELP libp2p_libp2p_identify_local_observed_addresses Number of connected nodes observing the local node at a specific address... \# TYPE libp2p_libp2p_identify_local_observed_addresses gauge libp2p_libp2p_identify_local_observed_addresses_total{observed_address="/ip4/tcp"} 1 ``` Pull-Request: #3325.
1 parent 1742bff commit 2d83725

File tree

7 files changed

+180
-145
lines changed

7 files changed

+180
-145
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/metrics/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ hyper = { version = "0.14", features = ["server", "tcp", "http1"] }
1212
libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] }
1313
log = "0.4.0"
1414
tokio = { version = "1", features = ["rt-multi-thread"] }
15-
prometheus-client = "0.20.0"
15+
prometheus-client = "0.21.0"

examples/metrics/src/http_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;v
3333

3434
pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> {
3535
// Serve on localhost.
36-
let addr = ([127, 0, 0, 1], 0).into();
36+
let addr = ([127, 0, 0, 1], 8080).into();
3737

3838
// Use the tokio runtime to run the hyper server.
3939
let rt = tokio::runtime::Runtime::new()?;

misc/metrics/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
## 0.13.0 - unreleased
22

3+
- Previously `libp2p-metrics::identify` would increase a counter / gauge / histogram on each
4+
received identify information. These metrics are misleading, as e.g. they depend on the identify
5+
interval and don't represent the set of currently connected peers. With this change, identify
6+
information is tracked for the currently connected peers only. Instead of an increase on each
7+
received identify information, metrics represent the status quo (Gauge).
8+
9+
Metrics removed:
10+
- `libp2p_identify_protocols`
11+
- `libp2p_identify_received_info_listen_addrs`
12+
- `libp2p_identify_received_info_protocols`
13+
- `libp2p_identify_listen_addresses`
14+
15+
Metrics added:
16+
- `libp2p_identify_remote_protocols`
17+
- `libp2p_identify_remote_listen_addresses`
18+
- `libp2p_identify_local_observed_addresses`
19+
20+
See [PR 3325].
21+
322
- Raise MSRV to 1.65.
423
See [PR 3715].
524

625
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
26+
[PR 3325]: https://github.com/libp2p/rust-libp2p/pull/3325
727

828
## 0.12.0
929

misc/metrics/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ libp2p-ping = { workspace = true, optional = true }
2727
libp2p-relay = { workspace = true, optional = true }
2828
libp2p-swarm = { workspace = true }
2929
libp2p-identity = { workspace = true }
30-
prometheus-client = "0.20.0"
30+
prometheus-client = { version = "0.21.0" }
31+
once_cell = "1.16.0"
3132

3233
[target.'cfg(not(target_os = "unknown"))'.dependencies]
3334
libp2p-gossipsub = { workspace = true, optional = true }

0 commit comments

Comments
 (0)