Skip to content

Commit 87f14fc

Browse files
committed
add metrics+health config for indexer v2.
1 parent e5e78e6 commit 87f14fc

File tree

7 files changed

+186
-23
lines changed

7 files changed

+186
-23
lines changed

Cargo.lock

Lines changed: 60 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ hyper-util = { version = "0.1.4" }
359359
tower = { version = "0.5" }
360360
http-body-util = "0.1"
361361
tap = "1.0.1"
362+
prometheus = "0.14.0"
362363

363364
# trying to pin diesel
364365
diesel = { version = "2.2.7", features = ["postgres", "numeric", "r2d2"] }

protocol-units/execution/maptos/util/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ hex = { workspace = true }
2929
tokio = { workspace = true }
3030
url = { workspace = true }
3131
tracing = { workspace = true }
32+
poem = { workspace = true }
33+
prometheus = { workspace = true }
34+
3235

3336
aptos-sdk = { workspace = true }
3437
movement-signer-loader = { workspace = true }

protocol-units/execution/maptos/util/src/config/common.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ env_default!(
246246
HashValue::sha3_256_of(b"maptos").to_hex()
247247
);
248248

249+
env_default!(
250+
default_health_server_hostname,
251+
"HEALTH_SERVER_HOSTNAME",
252+
String,
253+
"0.0.0.0".to_string()
254+
);
255+
256+
env_default!(default_health_server_port, "HEALTH_SERVER_PORT", u16, 18085);
257+
258+
env_default!(
259+
default_metrics_server_hostname,
260+
"METRICS_SERVER_HOSTNAME",
261+
String,
262+
"0.0.0.0".to_string()
263+
);
264+
env_default!(default_metrics_server_port, "METRICS_SERVER_PORT", u16, 18185);
265+
249266
env_default!(default_batch_production_time, "MAPTOS_BATCH_PRODUCTION_TIME_MS", u64, 2000);
250267

251268
env_default!(default_max_transactions_in_flight, "MAPTOS_MAX_TRANSACTIONS_IN_FLIGHT", u64);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use super::common::{default_health_server_hostname, default_health_server_port};
2+
use anyhow::Error;
3+
use poem::listener::TcpListener;
4+
use poem::{get, handler, IntoResponse, Response, Route, Server};
5+
use serde::{Deserialize, Serialize};
6+
7+
// An additional health server to be used by the indexer(or any other service).
8+
// Do not use this with node since it exposes various endpoints to verify the health of the node.
9+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10+
pub struct Config {
11+
#[serde(default = "default_health_server_hostname")]
12+
pub hostname: String,
13+
#[serde(default = "default_health_server_port")]
14+
pub port: u16,
15+
}
16+
17+
impl Default for Config {
18+
fn default() -> Self {
19+
Self { hostname: default_health_server_hostname(), port: default_health_server_port() }
20+
}
21+
}
22+
23+
impl Config {
24+
pub async fn run(self) -> Result<(), anyhow::Error> {
25+
let url = format!("{}:{}", self.hostname, self.port);
26+
run_service(url).await
27+
}
28+
}
29+
30+
pub async fn run_service(url: String) -> Result<(), Error> {
31+
let route = Route::new().at("/health", get(health));
32+
tracing::info!("Start health check access on :{url} .");
33+
Server::new(TcpListener::bind(url)).run(route).await.map_err(Into::into)
34+
}
35+
36+
#[handler]
37+
async fn health() -> Response {
38+
"{\"OK\": \"healthy\"}".into_response()
39+
}

0 commit comments

Comments
 (0)