From f979e16b9543ee0312bb0c4ec57700be207e4001 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Mon, 16 Jan 2023 16:56:55 +0100 Subject: [PATCH] server: Fix healthcheck return code The healthcheck was not returning a non-zero code when failing, due to an extra layer of Results --- server/src/infra/healthcheck.rs | 1 + server/src/main.rs | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/server/src/infra/healthcheck.rs b/server/src/infra/healthcheck.rs index 0fdd997..40089a0 100644 --- a/server/src/infra/healthcheck.rs +++ b/server/src/infra/healthcheck.rs @@ -99,6 +99,7 @@ fn get_tls_connector() -> Result { #[instrument(skip_all, level = "info", err)] pub async fn check_ldaps(ldaps_options: &LdapsOptions) -> Result<()> { if !ldaps_options.enabled { + info!("LDAPS not enabled"); return Ok(()); }; let tls_connector = get_tls_connector()?; diff --git a/server/src/main.rs b/server/src/main.rs index 005e0ce..2c67bd9 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -158,6 +158,8 @@ fn run_healthcheck(opts: RunOpts) -> Result<()> { .enable_all() .build()?; + info!("Starting healthchecks"); + use tokio::time::timeout; let delay = Duration::from_millis(3000); let (ldap, ldaps, api) = runtime.block_on(async { @@ -168,14 +170,18 @@ fn run_healthcheck(opts: RunOpts) -> Result<()> { ) }); - let mut failure = false; - [ldap, ldaps, api] + let failure = [ldap, ldaps, api] .into_iter() - .filter_map(Result::err) - .for_each(|e| { - failure = true; - error!("{:#}", e) - }); + .flat_map(|res| { + if let Err(e) = &res { + error!("Error running the health check: {:#}", e); + } + res + }) + .any(|r| r.is_err()); + if failure { + error!("Healthcheck failed"); + } std::process::exit(i32::from(failure)) }