From 689b81014bb5914c9f45f14e18ed0c4731bee6a5 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 21 Feb 2023 09:39:04 +0100 Subject: [PATCH] Print container logs when HealthCheck response_code != 200 The Healthcheck container is shut down right after performing the check, this makes it harder to troubleshoot configuration issues in the healthcheck endpoint, e.g DNS rebinding error. Printing the container logs helps the troubleshooting. --- lib/mrsk/cli/healthcheck.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/mrsk/cli/healthcheck.rb b/lib/mrsk/cli/healthcheck.rb index ffb0805d..eb7bb9ab 100644 --- a/lib/mrsk/cli/healthcheck.rb +++ b/lib/mrsk/cli/healthcheck.rb @@ -1,6 +1,8 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base MAX_ATTEMPTS = 5 + class HealthcheckError < StandardError; end + default_command :perform desc "perform", "Health check current app version" @@ -18,7 +20,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base if status == "200" info "#{target} succeeded with 200 OK!" else - raise "#{target} failed with status #{status}" + raise HealthcheckError, "#{target} failed with status #{status}" end rescue SSHKit::Command::Failed if attempt <= MAX_ATTEMPTS @@ -31,7 +33,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base raise end end - rescue SSHKit::Command::Failed => e + rescue SSHKit::Command::Failed, HealthcheckError => e error capture_with_info(*MRSK.healthcheck.logs) if e.message =~ /curl/