Skip to content

Commit 7219851

Browse files
hanabi1224LesnyRumcajselmattic
authored
fix: readyz returns 503 (#5516)
Co-authored-by: Hubert <[email protected]> Co-authored-by: Guillaume Potier <[email protected]>
1 parent 6b64e1b commit 7219851

File tree

7 files changed

+52
-19
lines changed

7 files changed

+52
-19
lines changed

scripts/tests/api_compare/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
command:
1818
- |
1919
set -euxo pipefail
20+
forest --version
2021
# fetch parameter files
2122
forest-tool fetch-params --keys
2223
# if there are some files in the data directory, then we don't need to fetch the snapshot

scripts/tests/calibnet_eth_mapping_check.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set -eu
66

77
source "$(dirname "$0")/harness.sh"
88

9-
export FOREST_CHAIN_INDEXER_ENABLED=1
109
forest_init
1110

1211
FOREST_URL='http://127.0.0.1:2345/rpc/v1'

scripts/tests/calibnet_other_check.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ echo "Test subcommand: net info"
4141
$FOREST_CLI_PATH net info
4242

4343
$FOREST_CLI_PATH sync wait # allow the node to re-sync
44+
45+
echo "Test subcommand: healthcheck live"
46+
$FOREST_CLI_PATH healthcheck live --wait
47+
48+
echo "Test subcommand: healthcheck healthy"
49+
$FOREST_CLI_PATH healthcheck healthy --wait
50+
51+
echo "Test subcommand: healthcheck ready"
52+
$FOREST_CLI_PATH healthcheck ready --wait

scripts/tests/harness.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
# the Forest tests. It is meant to be sourced by other scripts and not
44
# executed directly.
55

6-
FOREST_PATH="forest"
7-
FOREST_CLI_PATH="forest-cli"
8-
FOREST_WALLET_PATH="forest-wallet"
9-
FOREST_TOOL_PATH="forest-tool"
6+
export FOREST_CHAIN_INDEXER_ENABLED="1"
7+
8+
export FOREST_PATH="forest"
9+
export FOREST_CLI_PATH="forest-cli"
10+
export FOREST_WALLET_PATH="forest-wallet"
11+
export FOREST_TOOL_PATH="forest-tool"
1012

1113
TMP_DIR=$(mktemp --directory)
1214
LOG_DIRECTORY=$TMP_DIR/logs
1315

1416
export TMP_DIR
1517
export LOG_DIRECTORY
16-
export FOREST_WALLET_PATH
1718

1819
function forest_import_non_calibnet_snapshot {
1920
echo "Importing a non calibnet snapshot"

src/cli/subcommands/healthcheck_cmd.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,24 @@ impl HealthcheckCommand {
7676
);
7777

7878
for _ in ticker {
79-
let response = reqwest::get(&url).await?;
80-
let status = response.status();
81-
let text = response.text().await?;
79+
let (status, text) = {
80+
match reqwest::get(&url).await {
81+
Ok(response) => {
82+
let status = response.status();
83+
let text = match response.text().await {
84+
Ok(t) => t,
85+
Err(e) if wait => e.to_string(),
86+
Err(e) => anyhow::bail!("{e}"),
87+
};
88+
(status, text)
89+
}
90+
Err(e) if wait => {
91+
eprintln!("{e}");
92+
(http::StatusCode::INTERNAL_SERVER_ERROR, "".into())
93+
}
94+
Err(e) => anyhow::bail!("{e}"),
95+
}
96+
};
8297

8398
println!("{}", text);
8499

src/daemon/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,16 @@ async fn maybe_start_health_check_service(
387387
peer_manager: p2p_service.peer_manager().clone(),
388388
settings_store: ctx.db.writer().clone(),
389389
};
390-
let listener =
391-
tokio::net::TcpListener::bind(forest_state.config.client.healthcheck_address).await?;
390+
let healthcheck_address = forest_state.config.client.healthcheck_address;
391+
info!("Healthcheck endpoint will listen at {healthcheck_address}");
392+
let listener = tokio::net::TcpListener::bind(healthcheck_address).await?;
392393
services.spawn(async move {
393394
crate::health::init_healthcheck_server(forest_state, listener)
394395
.await
395396
.context("Failed to initiate healthcheck server")
396397
});
398+
} else {
399+
info!("Healthcheck service is disabled");
397400
}
398401
Ok(())
399402
}

src/health/endpoints.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,20 @@ fn check_peers_connected(state: &ForestState, acc: &mut MessageAccumulator) -> b
165165
}
166166

167167
fn check_eth_mappings_up_to_date(state: &ForestState, acc: &mut MessageAccumulator) -> bool {
168-
match state.settings_store.eth_mapping_up_to_date() {
169-
Ok(Some(true)) => {
170-
acc.push_ok("eth mappings up to date");
171-
true
172-
}
173-
Ok(None) | Ok(Some(false)) | Err(_) => {
174-
acc.push_err("no eth mappings");
175-
false
168+
if state.config.chain_indexer.enable_indexer {
169+
match state.settings_store.eth_mapping_up_to_date() {
170+
Ok(Some(true)) => {
171+
acc.push_ok("eth mappings up to date");
172+
true
173+
}
174+
Ok(None) | Ok(Some(false)) | Err(_) => {
175+
acc.push_err("no eth mappings");
176+
false
177+
}
176178
}
179+
} else {
180+
acc.push_err("eth mappings disabled");
181+
true
177182
}
178183
}
179184

0 commit comments

Comments
 (0)