Skip to content

Commit

Permalink
Change default line limit back to a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshenny committed Feb 11, 2021
1 parent e7c0beb commit 2162e96
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Remove resources that are targeted by side-effect-inducing mutating admission webhooks from the serverside dry run batch [#798](https://github.com/Shopify/krane/pull/798)

*Enhancements*
- ENV["LOG_LINE_LIMIT"] allows the number of container logs printed for failures to be configurable from the 25 line default [#803](https://github.com/Shopify/krane/pull/803).
- ENV["KRANE_LOG_LINE_LIMIT"] allows the number of container logs printed for failures to be configurable from the 25 line default [#803](https://github.com/Shopify/krane/pull/803).

## 2.1.5

Expand Down
6 changes: 2 additions & 4 deletions lib/krane/container_logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module Krane
class ContainerLogs
attr_reader :lines, :container_name

def self.default_line_limit
Integer(ENV["LOG_LINE_LIMIT"], exception: false) || 25
end
DEFAULT_LINE_LIMIT = Integer(ENV.fetch('KRANE_LOG_LINE_LIMIT', 25))

def initialize(parent_id:, container_name:, namespace:, context:, logger:)
@parent_id = parent_id
Expand Down Expand Up @@ -54,7 +52,7 @@ def fetch_latest
cmd << if @last_timestamp.present?
"--since-time=#{rfc3339_timestamp(@last_timestamp)}"
else
"--tail=#{self.class.default_line_limit}"
"--tail=#{DEFAULT_LINE_LIMIT}"
end
out, _err, _st = kubectl.run(*cmd, log_failure: false)
out.split("\n")
Expand Down
4 changes: 2 additions & 2 deletions lib/krane/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ def debug_message(cause = nil, info_hash = {})
next
end

if logs.lines.length == ContainerLogs.default_line_limit
truncated = " (last #{ContainerLogs.default_line_limit} lines shown)"
if logs.lines.length == ContainerLogs::DEFAULT_LINE_LIMIT
truncated = " (last #{ContainerLogs::DEFAULT_LINE_LIMIT} lines shown)"
end
helpful_info << " - Logs from container '#{logs.container_name}'#{truncated}:"
logs.lines.each do |line|
Expand Down
11 changes: 0 additions & 11 deletions test/unit/container_logs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ def test_sync_handles_cycles_where_no_new_logs_available
assert_equal(generate_log_messages(1..10), @logs.lines)
end

def test_can_configure_default_line_limit
original_env = ENV["LOG_LINE_LIMIT"]
assert_equal(25, Krane::ContainerLogs.default_line_limit)

line_limit = 2
ENV["LOG_LINE_LIMIT"] = line_limit.to_s
assert_equal(line_limit, Krane::ContainerLogs.default_line_limit)
ensure
ENV["LOG_LINE_LIMIT"] = original_env
end

def test_empty_delegated_to_lines
Krane::Kubectl.any_instance.stubs(:run).returns([logs_response_1, "", ""])
assert_predicate(@logs, :empty?)
Expand Down

0 comments on commit 2162e96

Please sign in to comment.