Skip to content

Commit

Permalink
config: use metrics address from config
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed May 31, 2022
1 parent 8659966 commit d604a2f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
4 changes: 1 addition & 3 deletions crates/sui-config/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,11 @@ impl<R: ::rand::RngCore + ::rand::CryptoRng> ConfigBuilder<R> {
narwhal_committee: narwhal_committee.clone(),
};

let metrics_address = utils::new_network_address();

NodeConfig {
key_pair: validator.key_pair,
db_path,
network_address,
metrics_address,
metrics_address: utils::available_local_socket_address(),
json_rpc_address: utils::available_local_socket_address(),
consensus_config: Some(consensus_config),
committee_config: committee_config.clone(),
Expand Down
20 changes: 19 additions & 1 deletion crates/sui-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ use sui_types::crypto::{KeyPair, PublicKeyBytes};
pub struct NodeConfig {
pub key_pair: KeyPair,
pub db_path: PathBuf,
#[serde(default = "default_grpc_address")]
pub network_address: Multiaddr,
pub metrics_address: Multiaddr,
#[serde(default = "default_metrics_address")]
pub metrics_address: SocketAddr,
#[serde(default = "default_json_rpc_address")]
pub json_rpc_address: SocketAddr,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -32,6 +35,21 @@ pub struct NodeConfig {
pub genesis: Genesis,
}

fn default_grpc_address() -> Multiaddr {
use multiaddr::multiaddr;
multiaddr!(Ip4([0, 0, 0, 0]), Tcp(8080u16))
}

fn default_metrics_address() -> SocketAddr {
use std::net::{IpAddr, Ipv4Addr};
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9184)
}

fn default_json_rpc_address() -> SocketAddr {
use std::net::{IpAddr, Ipv4Addr};
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9000)
}

impl Config for NodeConfig {}

impl NodeConfig {
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-config/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl NetworkConfig {
key_pair,
db_path: db_path.join(FULL_NODE_DB_PATH),
network_address: utils::new_network_address(),
metrics_address: utils::new_network_address(),
metrics_address: utils::available_local_socket_address(),
json_rpc_address: utils::available_local_socket_address(),

consensus_config: None,
Expand Down
11 changes: 6 additions & 5 deletions crates/sui-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use std::path::PathBuf;
use sui_config::{NodeConfig, PersistedConfig};
use tracing::info;

const PROM_PORT_ADDR: &str = "0.0.0.0:9184";

#[derive(Parser)]
#[clap(rename_all = "kebab-case")]
struct Args {
Expand Down Expand Up @@ -37,9 +35,12 @@ async fn main() -> Result<()> {
let mut config = PersistedConfig::<NodeConfig>::read(&args.config_path)?;

// TODO: Switch from prometheus exporter. See https://github.com/MystenLabs/sui/issues/1907
let prom_binding = PROM_PORT_ADDR.parse().unwrap();
info!("Starting Prometheus HTTP endpoint at {}", PROM_PORT_ADDR);
prometheus_exporter::start(prom_binding).expect("Failed to start Prometheus exporter");
info!(
"Starting Prometheus HTTP endpoint at {}",
config.metrics_address
);
prometheus_exporter::start(config.metrics_address)
.expect("Failed to start Prometheus exporter");

if let Some(listen_address) = args.listen_address {
config.network_address = listen_address;
Expand Down

0 comments on commit d604a2f

Please sign in to comment.