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.
This commit is contained in:
Jacopo
2023-02-21 09:39:04 +01:00
parent 01a4eecf98
commit 689b81014b

View File

@@ -1,6 +1,8 @@
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
MAX_ATTEMPTS = 5 MAX_ATTEMPTS = 5
class HealthcheckError < StandardError; end
default_command :perform default_command :perform
desc "perform", "Health check current app version" desc "perform", "Health check current app version"
@@ -18,7 +20,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
if status == "200" if status == "200"
info "#{target} succeeded with 200 OK!" info "#{target} succeeded with 200 OK!"
else else
raise "#{target} failed with status #{status}" raise HealthcheckError, "#{target} failed with status #{status}"
end end
rescue SSHKit::Command::Failed rescue SSHKit::Command::Failed
if attempt <= MAX_ATTEMPTS if attempt <= MAX_ATTEMPTS
@@ -31,7 +33,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
raise raise
end end
end end
rescue SSHKit::Command::Failed => e rescue SSHKit::Command::Failed, HealthcheckError => e
error capture_with_info(*MRSK.healthcheck.logs) error capture_with_info(*MRSK.healthcheck.logs)
if e.message =~ /curl/ if e.message =~ /curl/