From cb3c5a53f49de022052c333b9424b4358941ee28 Mon Sep 17 00:00:00 2001 From: Arturo Ojeda Date: Sat, 8 Apr 2023 19:52:53 -0600 Subject: [PATCH 1/5] Configurable max_attempts for healthcheck --- lib/mrsk/cli/healthcheck.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mrsk/cli/healthcheck.rb b/lib/mrsk/cli/healthcheck.rb index 3fda7754..94950373 100644 --- a/lib/mrsk/cli/healthcheck.rb +++ b/lib/mrsk/cli/healthcheck.rb @@ -1,5 +1,5 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base - MAX_ATTEMPTS = 7 + DEFAULT_MAX_ATTEMPTS = 7 class HealthcheckError < StandardError; end @@ -13,6 +13,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base target = "Health check against #{MRSK.config.healthcheck["path"]}" attempt = 1 + max_attempts = MRSK.config.healthcheck["max_attempts"] || DEFAULT_MAX_ATTEMPTS begin status = capture_with_info(*MRSK.healthcheck.curl) @@ -23,7 +24,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base raise HealthcheckError, "#{target} failed with status #{status}" end rescue SSHKit::Command::Failed - if attempt <= MAX_ATTEMPTS + if attempt <= max_attempts info "#{target} failed to respond, retrying in #{attempt}s..." sleep attempt attempt += 1 From 3969f56fa62eecab4e8f8fb9a2bed3457348ec84 Mon Sep 17 00:00:00 2001 From: Arturo Ojeda Date: Sun, 9 Apr 2023 12:07:27 -0600 Subject: [PATCH 2/5] Improved: configurable max_attempts for healthcheck --- lib/mrsk/cli/healthcheck.rb | 5 ++--- lib/mrsk/configuration.rb | 2 +- test/configuration_test.rb | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/mrsk/cli/healthcheck.rb b/lib/mrsk/cli/healthcheck.rb index 94950373..5e9f42dc 100644 --- a/lib/mrsk/cli/healthcheck.rb +++ b/lib/mrsk/cli/healthcheck.rb @@ -1,5 +1,4 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base - DEFAULT_MAX_ATTEMPTS = 7 class HealthcheckError < StandardError; end @@ -13,7 +12,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base target = "Health check against #{MRSK.config.healthcheck["path"]}" attempt = 1 - max_attempts = MRSK.config.healthcheck["max_attempts"] || DEFAULT_MAX_ATTEMPTS + max_attempts = MRSK.config.healthcheck["max_attempts"] begin status = capture_with_info(*MRSK.healthcheck.curl) @@ -25,7 +24,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base end rescue SSHKit::Command::Failed if attempt <= max_attempts - info "#{target} failed to respond, retrying in #{attempt}s..." + info "#{target} failed to respond, retrying in #{attempt}s (attempt #{attempt}/#{max_attempts})..." sleep attempt attempt += 1 diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index d6cf09f1..3e58a85a 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -156,7 +156,7 @@ class Mrsk::Configuration end def healthcheck - { "path" => "/up", "port" => 3000 }.merge(raw_config.healthcheck || {}) + { "path" => "/up", "port" => 3000, "max_attempts" => 7 }.merge(raw_config.healthcheck || {}) end def readiness_delay diff --git a/test/configuration_test.rb b/test/configuration_test.rb index ec65686d..2697673b 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -249,6 +249,6 @@ class ConfigurationTest < ActiveSupport::TestCase end test "to_h" do - assert_equal({ :roles=>["web"], :hosts=>["1.1.1.1", "1.1.1.2"], :primary_host=>"1.1.1.1", :version=>"missing", :repository=>"dhh/app", :absolute_image=>"dhh/app:missing", :service_with_version=>"app-missing", :env_args=>["-e", "REDIS_URL=\"redis://x/y\""], :ssh_options=>{:user=>"root", :auth_methods=>["publickey"]}, :volume_args=>["--volume", "/local/path:/container/path"], :logging=>["--log-opt", "max-size=\"10m\""], :healthcheck=>{"path"=>"/up", "port"=>3000 }}, @config.to_h) + assert_equal({ :roles=>["web"], :hosts=>["1.1.1.1", "1.1.1.2"], :primary_host=>"1.1.1.1", :version=>"missing", :repository=>"dhh/app", :absolute_image=>"dhh/app:missing", :service_with_version=>"app-missing", :env_args=>["-e", "REDIS_URL=\"redis://x/y\""], :ssh_options=>{:user=>"root", :auth_methods=>["publickey"]}, :volume_args=>["--volume", "/local/path:/container/path"], :logging=>["--log-opt", "max-size=\"10m\""], :healthcheck=>{"path"=>"/up", "port"=>3000, "max_attempts" => 7 }}, @config.to_h) end end From 514b2aa24391864595f8212b34edc16c08dfa209 Mon Sep 17 00:00:00 2001 From: Arturo Ojeda Date: Mon, 10 Apr 2023 09:29:19 -0600 Subject: [PATCH 3/5] Fix test case: console output message was not updated to display the current/total attempts --- test/cli/healthcheck_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cli/healthcheck_test.rb b/test/cli/healthcheck_test.rb index 7a9df6eb..a3441a7e 100644 --- a/test/cli/healthcheck_test.rb +++ b/test/cli/healthcheck_test.rb @@ -23,8 +23,8 @@ class CliHealthcheckTest < CliTestCase .returns("200") run_command("perform").tap do |output| - assert_match "Health check against /up failed to respond, retrying in 1s...", output - assert_match "Health check against /up failed to respond, retrying in 2s...", output + assert_match "Health check against /up failed to respond, retrying in 1s (attempt 1/7)...", output + assert_match "Health check against /up failed to respond, retrying in 2s (attempt 2/7)...", output assert_match "Health check against /up succeeded with 200 OK!", output end end From 161ebe4bc16fd51c69f7e9efa2e446aaddde19e5 Mon Sep 17 00:00:00 2001 From: Arturo Ojeda Date: Mon, 10 Apr 2023 22:26:10 -0600 Subject: [PATCH 4/5] Updated README.md with new healthcheck.max_attempts option --- .idea/.gitignore | 8 ++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/mrsk.iml | 14 ++++++++++++++ .idea/vcs.xml | 6 ++++++ README.md | 7 +++++-- 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/mrsk.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..9fd148f6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..812d9104 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/mrsk.iml b/.idea/mrsk.iml new file mode 100644 index 00000000..2d83225c --- /dev/null +++ b/.idea/mrsk.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 531b2408..32988c32 100644 --- a/README.md +++ b/README.md @@ -610,18 +610,21 @@ That'll post a line like follows to a preconfigured chatbot in Basecamp: [My App] [dhh] Rolled back to version d264c4e92470ad1bd18590f04466787262f605de ``` -### Using custom healthcheck path or port +### Custom healthcheck -MRSK defaults to checking the health of your application again `/up` on port 3000. You can tailor both with the `healthcheck` setting: +MRSK defaults to checking the health of your application again `/up` on port 3000 up to 7 times. You can tailor the behaviour with the `healthcheck` setting: ```yaml healthcheck: path: /healthz port: 4000 + max_attempts: 7 ``` This will ensure your application is configured with a traefik label for the healthcheck against `/healthz` and that the pre-deploy healthcheck that MRSK performs is done against the same path on port 4000. +The healthcheck also allows for an optional `max_attempts` setting, which will attempt the healthcheck up to the specified number of times before failing the deploy. This is useful for applications that take a while to start up. The default is 7. + ## Commands ### Running commands on servers From cfc8fa0590298fb88a290fd6f5514aadb39d3d5f Mon Sep 17 00:00:00 2001 From: Arturo Ojeda Date: Mon, 10 Apr 2023 22:33:20 -0600 Subject: [PATCH 5/5] Remove .idea folder --- .idea/.gitignore | 8 -------- .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/mrsk.iml | 14 -------------- .idea/vcs.xml | 6 ------ 5 files changed, 42 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/mrsk.iml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9fd148f6..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 812d9104..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/mrsk.iml b/.idea/mrsk.iml deleted file mode 100644 index 2d83225c..00000000 --- a/.idea/mrsk.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file