From 8ddc484ce62290d4a5fd3dbc1299d1ed562d83e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Wed, 6 Sep 2023 10:54:30 +0200 Subject: [PATCH 1/2] Configurable Lines Number in Healthcheck Log Output --- lib/kamal/commands/healthcheck.rb | 6 +++++- lib/kamal/configuration.rb | 2 +- test/commands/healthcheck_test.rb | 7 +++++++ test/configuration_test.rb | 2 +- test/integration/main_test.rb | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/kamal/commands/healthcheck.rb b/lib/kamal/commands/healthcheck.rb index fa050b9cb..b61ad3dfc 100644 --- a/lib/kamal/commands/healthcheck.rb +++ b/lib/kamal/commands/healthcheck.rb @@ -26,7 +26,7 @@ def container_health_log end def logs - pipe container_id, xargs(docker(:logs, "--tail", 50, "2>&1")) + pipe container_id, xargs(docker(:logs, "--tail", lines, "2>&1")) end def stop @@ -57,4 +57,8 @@ def health_url def exposed_port config.healthcheck["exposed_port"] end + + def lines + config.healthcheck["lines"] + end end diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index af6e46c5f..a076e9918 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -149,7 +149,7 @@ def sshkit def healthcheck - { "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord" }.merge(raw_config.healthcheck || {}) + { "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "lines" => 50 }.merge(raw_config.healthcheck || {}) end def readiness_delay diff --git a/test/commands/healthcheck_test.rb b/test/commands/healthcheck_test.rb index 5ef7fc03d..21a8876df 100644 --- a/test/commands/healthcheck_test.rb +++ b/test/commands/healthcheck_test.rb @@ -92,6 +92,13 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase new_command.logs.join(" ") end + test "logs with custom lines number" do + @config[:healthcheck] = { "lines" => 150 } + assert_equal \ + "docker container ls --all --filter name=^healthcheck-app-123$ --quiet | xargs docker logs --tail 150 2>&1", + new_command.logs.join(" ") + end + test "logs with destination" do @destination = "staging" diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 59046760c..be448fcfb 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -224,7 +224,7 @@ class ConfigurationTest < ActiveSupport::TestCase :volume_args=>["--volume", "/local/path:/container/path"], :builder=>{}, :logging=>["--log-opt", "max-size=\"10m\""], - :healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord" }} + :healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "lines" => 50 }} assert_equal expected_config, @config.to_h end diff --git a/test/integration/main_test.rb b/test/integration/main_test.rb index e10d9e526..bd9c10651 100644 --- a/test/integration/main_test.rb +++ b/test/integration/main_test.rb @@ -54,7 +54,7 @@ class MainTest < IntegrationTest assert_equal({ user: "root", auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30, log_level: :fatal }, config[:ssh_options]) assert_equal({ "multiarch" => false, "args" => { "COMMIT_SHA" => version } }, config[:builder]) assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging] - assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord"=>"/tmp/kamal-cord", "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1" }, config[:healthcheck]) + assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord"=>"/tmp/kamal-cord", "lines" => 50, "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1" }, config[:healthcheck]) end private From 892cf0e66b6702df6edd3152a73de7055a3becf6 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Tue, 12 Sep 2023 21:06:36 +0200 Subject: [PATCH 2/2] Configurable Log Lines Number in Healthcheck Log Output --- lib/kamal/commands/healthcheck.rb | 6 +++--- lib/kamal/configuration.rb | 2 +- test/commands/healthcheck_test.rb | 2 +- test/configuration_test.rb | 2 +- test/integration/main_test.rb | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/kamal/commands/healthcheck.rb b/lib/kamal/commands/healthcheck.rb index b61ad3dfc..9d7853263 100644 --- a/lib/kamal/commands/healthcheck.rb +++ b/lib/kamal/commands/healthcheck.rb @@ -26,7 +26,7 @@ def container_health_log end def logs - pipe container_id, xargs(docker(:logs, "--tail", lines, "2>&1")) + pipe container_id, xargs(docker(:logs, "--tail", log_lines, "2>&1")) end def stop @@ -58,7 +58,7 @@ def exposed_port config.healthcheck["exposed_port"] end - def lines - config.healthcheck["lines"] + def log_lines + config.healthcheck["log_lines"] end end diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index a076e9918..4809ec8e0 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -149,7 +149,7 @@ def sshkit def healthcheck - { "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "lines" => 50 }.merge(raw_config.healthcheck || {}) + { "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }.merge(raw_config.healthcheck || {}) end def readiness_delay diff --git a/test/commands/healthcheck_test.rb b/test/commands/healthcheck_test.rb index 21a8876df..66cdda6b4 100644 --- a/test/commands/healthcheck_test.rb +++ b/test/commands/healthcheck_test.rb @@ -93,7 +93,7 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase end test "logs with custom lines number" do - @config[:healthcheck] = { "lines" => 150 } + @config[:healthcheck] = { "log_lines" => 150 } assert_equal \ "docker container ls --all --filter name=^healthcheck-app-123$ --quiet | xargs docker logs --tail 150 2>&1", new_command.logs.join(" ") diff --git a/test/configuration_test.rb b/test/configuration_test.rb index be448fcfb..a1e892762 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -224,7 +224,7 @@ class ConfigurationTest < ActiveSupport::TestCase :volume_args=>["--volume", "/local/path:/container/path"], :builder=>{}, :logging=>["--log-opt", "max-size=\"10m\""], - :healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "lines" => 50 }} + :healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }} assert_equal expected_config, @config.to_h end diff --git a/test/integration/main_test.rb b/test/integration/main_test.rb index bd9c10651..50bc7560b 100644 --- a/test/integration/main_test.rb +++ b/test/integration/main_test.rb @@ -54,7 +54,7 @@ class MainTest < IntegrationTest assert_equal({ user: "root", auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30, log_level: :fatal }, config[:ssh_options]) assert_equal({ "multiarch" => false, "args" => { "COMMIT_SHA" => version } }, config[:builder]) assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging] - assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord"=>"/tmp/kamal-cord", "lines" => 50, "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1" }, config[:healthcheck]) + assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord"=>"/tmp/kamal-cord", "log_lines" => 50, "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1" }, config[:healthcheck]) end private