Skip to content

Commit

Permalink
Configurable Log Lines Number in Healthcheck Log Output
Browse files Browse the repository at this point in the history
  • Loading branch information
rience committed Sep 12, 2023
1 parent 8ddc484 commit 892cf0e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/kamal/commands/healthcheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/kamal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/commands/healthcheck_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")
Expand Down
2 changes: 1 addition & 1 deletion test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 892cf0e

Please sign in to comment.