Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(node): refactor how monitoring server is spawned #871

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions crates/papyrus_monitoring_gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ impl MonitoringServer {
})
}

/// Spawns a monitoring server.
pub async fn spawn_server(self) -> tokio::task::JoinHandle<Result<(), hyper::Error>> {
tokio::spawn(async move { self.run_server().await })
}

#[instrument(
skip(self),
fields(
Expand All @@ -167,7 +162,7 @@ impl MonitoringServer {
public_general_config_presentation = %self.public_general_config_presentation,
present_full_config_secret = %self.config.present_full_config_secret),
level = "debug")]
async fn run_server(&self) -> std::result::Result<(), hyper::Error> {
pub async fn run_server(&self) -> std::result::Result<(), hyper::Error> {
let server_address = SocketAddr::from_str(&self.config.server_address)
.expect("Configuration value for monitor server address should be valid");
let app = app(
Expand Down
26 changes: 19 additions & 7 deletions crates/papyrus_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ async fn spawn_rpc_server(
Ok(tokio::spawn(pending()))
}

fn spawn_monitoring_server(
storage_reader: StorageReader,
local_peer_id: String,
config: &NodeConfig,
) -> anyhow::Result<JoinHandle<anyhow::Result<()>>> {
let monitoring_server = MonitoringServer::new(
config.monitoring_gateway.clone(),
get_config_presentation(config, true)?,
get_config_presentation(config, false)?,
storage_reader,
VERSION_FULL,
local_peer_id,
)?;
Ok(tokio::spawn(async move { Ok(monitoring_server.run_server().await?) }))
}

fn spawn_consensus(
config: Option<&ConsensusConfig>,
storage_reader: StorageReader,
Expand Down Expand Up @@ -336,15 +352,11 @@ async fn run_threads(config: NodeConfig, mut resources: PapyrusResources) -> any
);

// Monitoring server.
let monitoring_server = MonitoringServer::new(
config.monitoring_gateway.clone(),
get_config_presentation(&config, true)?,
get_config_presentation(&config, false)?,
let monitoring_server_handle = spawn_monitoring_server(
resources.storage_reader.clone(),
VERSION_FULL,
resources.local_peer_id,
resources.local_peer_id.clone(),
&config,
)?;
let monitoring_server_handle = monitoring_server.spawn_server().await;

// JSON-RPC server.
let rpc_server_handle = spawn_rpc_server(
Expand Down
Loading