Skip to content

Commit

Permalink
Configurable Number of Lines in Healthcheck Log Output
Browse files Browse the repository at this point in the history
  • Loading branch information
rience committed Sep 5, 2023
1 parent 9363b6a commit 60b6cee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/kamal/commands/healthcheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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
Expand All @@ -54,4 +54,8 @@ def container_id
def health_url
"http://localhost:#{EXPOSED_PORT}#{config.healthcheck["path"]}"
end

def lines
config.healthcheck["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 @@ -145,7 +145,7 @@ def sshkit


def healthcheck
{ "path" => "/up", "port" => 3000, "max_attempts" => 7 }.merge(raw_config.healthcheck || {})
{ "path" => "/up", "port" => 3000, "max_attempts" => 7, "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 @@ -91,6 +91,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"

Expand Down

0 comments on commit 60b6cee

Please sign in to comment.