Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Number of Lines in Healthcheck Log Output #444

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion 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", 50, "2>&1"))
pipe container_id, xargs(docker(:logs, "--tail", log_lines, "2>&1"))
end

def stop
Expand Down Expand Up @@ -57,4 +57,8 @@ def health_url
def exposed_port
config.healthcheck["exposed_port"]
end

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" }.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
7 changes: 7 additions & 0 deletions test/commands/healthcheck_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase
new_command.logs.join(" ")
end

test "logs with custom lines number" do
@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(" ")
end

test "logs with destination" do
@destination = "staging"

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" }}
: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", "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
Loading