diff --git a/beacon_node/lighthouse_network/src/config.rs b/beacon_node/lighthouse_network/src/config.rs index 4c6524084..e18fd00ae 100644 --- a/beacon_node/lighthouse_network/src/config.rs +++ b/beacon_node/lighthouse_network/src/config.rs @@ -114,6 +114,9 @@ pub struct Config { /// List of extra topics to initially subscribe to as strings. pub topics: Vec, + + /// Whether metrics are enabled. + pub metrics_enabled: bool, } impl Default for Config { @@ -188,6 +191,7 @@ impl Default for Config { import_all_attestations: false, shutdown_after_sync: false, topics: Vec::new(), + metrics_enabled: false, } } } diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index 6eeb17123..ce8aca472 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -137,6 +137,8 @@ pub struct NetworkService { subscribe_all_subnets: bool, /// Shutdown beacon node after sync is complete. shutdown_after_sync: bool, + /// Whether metrics are enabled or not. + metrics_enabled: bool, /// A timer for updating various network metrics. metrics_update: tokio::time::Interval, /// gossipsub_parameter_update timer @@ -263,6 +265,7 @@ impl NetworkService { next_unsubscribe, subscribe_all_subnets: config.subscribe_all_subnets, shutdown_after_sync: config.shutdown_after_sync, + metrics_enabled: config.metrics_enabled, metrics_update, gossipsub_parameter_update, fork_context, @@ -325,7 +328,7 @@ fn spawn_service( loop { // build the futures to check simultaneously tokio::select! { - _ = service.metrics_update.tick() => { + _ = service.metrics_update.tick(), if service.metrics_enabled => { // update various network metrics metric_update_counter +=1; if metric_update_counter % T::EthSpec::default_spec().seconds_per_slot == 0 { diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index c086d71ab..12c7d59b5 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -705,6 +705,10 @@ pub fn set_network_config( config.private = true; } + if cli_args.is_present("metrics") { + config.metrics_enabled = true; + } + Ok(()) } diff --git a/lighthouse/tests/beacon_node.rs b/lighthouse/tests/beacon_node.rs index 2456c8d50..a7ccdbebd 100644 --- a/lighthouse/tests/beacon_node.rs +++ b/lighthouse/tests/beacon_node.rs @@ -619,7 +619,10 @@ fn metrics_flag() { CommandLineTest::new() .flag("metrics", None) .run() - .with_config(|config| assert!(config.http_metrics.enabled)); + .with_config(|config| { + assert!(config.http_metrics.enabled); + assert!(config.network.metrics_enabled); + }); } #[test] fn metrics_address_flag() {