Skip to content

Commit

Permalink
feat(metrics)!: expose identify metrics for connected peers only
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mxinden authored May 15, 2023
1 parent 1742bff commit 2d83725
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 145 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ hyper = { version = "0.14", features = ["server", "tcp", "http1"] }
libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] }
log = "0.4.0"
tokio = { version = "1", features = ["rt-multi-thread"] }
prometheus-client = "0.20.0"
prometheus-client = "0.21.0"
2 changes: 1 addition & 1 deletion examples/metrics/src/http_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;v

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

// Use the tokio runtime to run the hyper server.
let rt = tokio::runtime::Runtime::new()?;
Expand Down
20 changes: 20 additions & 0 deletions misc/metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
## 0.13.0 - unreleased

- Previously `libp2p-metrics::identify` would increase a counter / gauge / histogram on each
received identify information. These metrics are misleading, as e.g. they depend on the identify
interval and don't represent the set of currently connected peers. With this change, 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).

Metrics removed:
- `libp2p_identify_protocols`
- `libp2p_identify_received_info_listen_addrs`
- `libp2p_identify_received_info_protocols`
- `libp2p_identify_listen_addresses`

Metrics added:
- `libp2p_identify_remote_protocols`
- `libp2p_identify_remote_listen_addresses`
- `libp2p_identify_local_observed_addresses`

See [PR 3325].

- Raise MSRV to 1.65.
See [PR 3715].

[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3325]: https://github.com/libp2p/rust-libp2p/pull/3325

## 0.12.0

Expand Down
3 changes: 2 additions & 1 deletion misc/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ libp2p-ping = { workspace = true, optional = true }
libp2p-relay = { workspace = true, optional = true }
libp2p-swarm = { workspace = true }
libp2p-identity = { workspace = true }
prometheus-client = "0.20.0"
prometheus-client = { version = "0.21.0" }
once_cell = "1.16.0"

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

0 comments on commit 2d83725

Please sign in to comment.