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

Skip collecting logs and events on failure via env var #239

Merged
merged 7 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions lib/kubernetes-deploy/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class KubernetesResource
TIMEOUT = 5.minutes
LOG_LINE_COUNT = 250

NO_DEBUG_INFO_MESSAGE = "Event and log collection is disabled by the NO_DEBUG_INFO env var."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let's make the env var string itself a constant too, since it's used in three places.

DEBUG_RESOURCE_NOT_FOUND_MESSAGE = "None found. Please check your usual logging service (e.g. Splunk)."
UNUSUAL_FAILURE_MESSAGE = <<~MSG
It is very unusual for this resource type to fail to deploy. Please try the deploy again.
Expand Down Expand Up @@ -141,6 +142,7 @@ def deploy_method
end

def sync_debug_info
return if ENV['NO_DEBUG_INFO']
@events = fetch_events
@logs = fetch_logs if supports_logs?
@debug_info_synced = true
Expand All @@ -164,6 +166,11 @@ def debug_message
end
helpful_info << " - Final status: #{status}"

if ENV['NO_DEBUG_INFO']
helpful_info << NO_DEBUG_INFO_MESSAGE
return helpful_info.join("\n")
end

if @events.present?
helpful_info << " - Events (common success events excluded):"
@events.each do |identifier, event_hashes|
Expand Down
12 changes: 12 additions & 0 deletions test/unit/kubernetes-deploy/kubernetes_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ def test_deploy_timed_out_respects_annotation_based_timeouts
end
end

def test_debug_message_with_no_debug_info
ENV['NO_DEBUG_INFO'] = 'true'
dummy = DummyResource.new
dummy.expects(:deploy_failed?).returns(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a stub, let's make this settable the same way we have done for deploy_succeeded? (add an attribute and a write for that attribute)


assert_match dummy.debug_message,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also refute that it matches - Logs or - Events

"DummyResource/test: FAILED\n - Final status: Unknown\n" +
KubernetesDeploy::KubernetesResource::NO_DEBUG_INFO_MESSAGE
ensure
ENV['NO_DEBUG_INFO'] = nil
end

private

def timeout_override_err_prefix
Expand Down