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

reduce amount of default logging on a failed request #122

Merged
merged 5 commits into from
May 26, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 5.2.5
- Reduce amount of default logging on a failed request [#122](https://github.com/logstash-plugins/logstash-output-http/pull/122)

## 5.2.4
- Relax dependency on http_client mixin since current major works on both

Expand Down
26 changes: 16 additions & 10 deletions lib/logstash/outputs/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,22 @@ def send_event(event, attempt)

rescue => exception
will_retry = retryable_exception?(exception)
log_failure("Could not fetch URL",
:url => url,
:method => @http_method,
:body => body,
:headers => headers,
:message => exception.message,
:class => exception.class.name,
:backtrace => exception.backtrace,
:will_retry => will_retry
)
log_params = {
:url => url,
:method => @http_method,
:message => exception.message,
:class => exception.class.name,
:will_retry => will_retry
}
if @logger.debug?
# backtraces are big
log_params[:backtrace] = exception.backtrace
# headers can have sensitive data
log_params[:headers] = headers
# body can be big and may have sensitive data
log_params[:body] = body
end
log_failure("Could not fetch URL", log_params)

if will_retry
return :retry, event, attempt
Expand Down
2 changes: 1 addition & 1 deletion logstash-output-http.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'logstash-output-http'
s.version = '5.2.4'
s.version = '5.2.5'
s.licenses = ['Apache License (2.0)']
s.summary = "Sends events to a generic HTTP or HTTPS endpoint"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
36 changes: 36 additions & 0 deletions spec/outputs/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,44 @@ def sinatra_run_wait(app, opts)
it "should make three total requests" do
expect(subject).to have_received(:send_event).exactly(3).times
end

end
end
context "on exception" do
before :each do
jsvd marked this conversation as resolved.
Show resolved Hide resolved
allow(subject.client).to receive(:send).and_raise RuntimeError
subject.multi_receive([event])
end

it "should not log headers" do
expect(subject).to have_received(:log_failure).with(anything, hash_not_including(:headers))
end

it "should not log the body" do
expect(subject).to have_received(:log_failure).with(anything, hash_not_including(:body))
end

context "with debug log level" do
before :all do
@current_log_level = LogStash::Logging::Logger.get_logging_context.get_root_logger.get_level.to_s.downcase
LogStash::Logging::Logger.configure_logging "debug"
end
after :all do
LogStash::Logging::Logger.configure_logging @current_log_level
end

it "should log a failure" do
expect(subject).to have_received(:log_failure).with(any_args)
end

it "should not log headers" do
expect(subject).to have_received(:log_failure).with(anything, hash_including(:headers))
end

it "should not log the body" do
expect(subject).to have_received(:log_failure).with(anything, hash_including(:body))
end
end
end
end

Expand Down