Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
83 changes: 60 additions & 23 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ hyper-util = { version = "0.1.4" }
tower = { version = "0.5" }
http-body-util = "0.1"
tap = "1.0.1"
prometheus = "0.14.0"

# trying to pin diesel
diesel = { version = "2.2.7", features = ["postgres", "numeric", "r2d2"] }
Expand Down
3 changes: 3 additions & 0 deletions protocol-units/execution/maptos/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ hex = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }
tracing = { workspace = true }
poem = { workspace = true }
prometheus = { workspace = true }


aptos-sdk = { workspace = true }
movement-signer-loader = { workspace = true }
Expand Down
17 changes: 17 additions & 0 deletions protocol-units/execution/maptos/util/src/config/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,23 @@ env_default!(
HashValue::sha3_256_of(b"maptos").to_hex()
);

env_default!(
default_health_server_hostname,
"HEALTH_SERVER_HOSTNAME",
String,
"0.0.0.0".to_string()
);

env_default!(default_health_server_port, "HEALTH_SERVER_PORT", u16, 18085);

env_default!(
default_metrics_server_hostname,
"METRICS_SERVER_HOSTNAME",
String,
"0.0.0.0".to_string()
);
env_default!(default_metrics_server_port, "METRICS_SERVER_PORT", u16, 18185);

env_default!(default_batch_production_time, "MAPTOS_BATCH_PRODUCTION_TIME_MS", u64, 2000);

env_default!(default_max_transactions_in_flight, "MAPTOS_MAX_TRANSACTIONS_IN_FLIGHT", u64);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use super::common::{default_health_server_hostname, default_health_server_port};
use anyhow::Error;
use poem::listener::TcpListener;
use poem::{get, handler, IntoResponse, Response, Route, Server};
use serde::{Deserialize, Serialize};

// An additional health server to be used by the indexer(or any other service).
// Do not use this with node since it exposes various endpoints to verify the health of the node.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Config {
#[serde(default = "default_health_server_hostname")]
pub hostname: String,
#[serde(default = "default_health_server_port")]
pub port: u16,
}

impl Default for Config {
fn default() -> Self {
Self { hostname: default_health_server_hostname(), port: default_health_server_port() }
}
}

impl Config {
pub async fn run(self) -> Result<(), anyhow::Error> {
let url = format!("{}:{}", self.hostname, self.port);
run_service(url).await
}
}

pub async fn run_service(url: String) -> Result<(), Error> {
let route = Route::new().at("/health", get(health));
tracing::info!("Start health check access on :{url} .");
Server::new(TcpListener::bind(url)).run(route).await.map_err(Into::into)
}

#[handler]
async fn health() -> Response {
"{\"OK\": \"healthy\"}".into_response()
}
Loading
Loading