Skip to content

Commit

Permalink
feat(metrics): add libp2p bandwidth metrics (#1973)
Browse files Browse the repository at this point in the history
* add tests

* add tests

* review fixes

* review fixes

* feat(metrics): add libp2p bandwidth metrics
  • Loading branch information
gurinderu committed Dec 22, 2023
1 parent 57a3840 commit 090dff3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fluence-keypair = { workspace = true }
avm-server = { workspace = true }
air-interpreter-wasm = { workspace = true }

libp2p = { workspace = true }
libp2p = { workspace = true, features = ["metrics"] }
libp2p-metrics = { workspace = true }
libp2p-swarm = { workspace = true }
libp2p-connection-limits = { workspace = true }
Expand Down
24 changes: 17 additions & 7 deletions nox/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl<RT: AquaRuntime> Node<RT> {
transport,
config.external_addresses(),
health_registry.as_mut(),
metrics_registry.as_mut(),
)?;

let (services_metrics_backend, services_metrics) =
Expand Down Expand Up @@ -354,6 +355,7 @@ impl<RT: AquaRuntime> Node<RT> {
transport: Boxed<(PeerId, StreamMuxerBox)>,
external_addresses: Vec<Multiaddr>,
health_registry: Option<&mut HealthCheckRegistry>,
metrics_registry: Option<&mut Registry>,
) -> eyre::Result<(
Swarm<FluenceNetworkBehaviour>,
Connectivity,
Expand All @@ -364,13 +366,21 @@ impl<RT: AquaRuntime> Node<RT> {
let (behaviour, connectivity, particle_stream) =
FluenceNetworkBehaviour::new(network_config, health_registry);

let mut swarm = SwarmBuilder::with_existing_identity(key_pair)
.with_tokio()
.with_other_transport(|_| transport)?
.with_behaviour(|_| behaviour)?
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(connection_idle_timeout))
.build();

let mut swarm = match metrics_registry {
None => SwarmBuilder::with_existing_identity(key_pair)
.with_tokio()
.with_other_transport(|_| transport)?
.with_behaviour(|_| behaviour)?
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(connection_idle_timeout))
.build(),
Some(registry) => SwarmBuilder::with_existing_identity(key_pair)
.with_tokio()
.with_other_transport(|_| transport)?
.with_bandwidth_metrics(registry)
.with_behaviour(|_| behaviour)?
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(connection_idle_timeout))
.build(),
};
// Add external addresses to Swarm
external_addresses.iter().cloned().for_each(|addr| {
Swarm::add_external_address(&mut swarm, addr);
Expand Down

0 comments on commit 090dff3

Please sign in to comment.