-
Notifications
You must be signed in to change notification settings - Fork 82
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
Added support for DLQ #110
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,6 +60,9 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base | |||||
# If encountered as response codes this plugin will retry these requests | ||||||
config :retryable_codes, :validate => :number, :list => true, :default => [429, 500, 502, 503, 504] | ||||||
|
||||||
# If encountered as response codes, this plugin will write these events to DLQ | ||||||
config :dlq_retryable_codes, :validate => :number, :list => true, :default => [400, 403, 404, 401] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# If you would like to consider some non-2xx codes to be successes | ||||||
# enumerate them here. Responses returning these codes will be considered successes | ||||||
config :ignorable_codes, :validate => :number, :list => true | ||||||
|
@@ -97,7 +100,7 @@ def register | |||||
# tokens must be added back by the client on success | ||||||
@request_tokens = SizedQueue.new(@pool_max) | ||||||
@pool_max.times {|t| @request_tokens << true } | ||||||
|
||||||
@dlq_writer = dlq_enabled? ? execution_context.dlq_writer : nil | ||||||
@requests = Array.new | ||||||
|
||||||
if @content_type.nil? | ||||||
|
@@ -153,6 +156,25 @@ def log_error_response(response, url, event) | |||||
:event => event | ||||||
) | ||||||
end | ||||||
|
||||||
# To support bwc, we check if DLQ exists. otherwise we log and drop event (previous behavior) | ||||||
def write_to_dlq(url, event, response) | ||||||
if @dlq_writer | ||||||
log_failure( | ||||||
"Sending this non-2xx HTTP code #{response.code} to DLQ", | ||||||
:response_code => response.code, | ||||||
:url => url, | ||||||
:event => event | ||||||
) | ||||||
metadata = event.get("@metadata") | ||||||
metadata.each_pair do |key, value| | ||||||
event.set("[custom_metadata][#{key}]", value) | ||||||
end | ||||||
Comment on lines
+169
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
@dlq_writer.write(event, "Sending #{response.code} erred HTTP request to DLQ, url: #{url}, response: #{response}") | ||||||
else | ||||||
log_error_response(response, url, event) | ||||||
end | ||||||
end | ||||||
|
||||||
def send_events(events) | ||||||
successes = java.util.concurrent.atomic.AtomicInteger.new(0) | ||||||
|
@@ -242,6 +264,9 @@ def send_event(event, attempt) | |||||
if retryable_response?(response) | ||||||
log_retryable_response(response) | ||||||
return :retry, event, attempt | ||||||
elsif dlq_retryable_response?(response) | ||||||
write_to_dlq(url, event, response) | ||||||
return :failure, event, attempt | ||||||
else | ||||||
log_error_response(response, url, event) | ||||||
return :failure, event, attempt | ||||||
|
@@ -287,6 +312,10 @@ def retryable_response?(response) | |||||
@retryable_codes && @retryable_codes.include?(response.code) | ||||||
end | ||||||
|
||||||
def dlq_retryable_response?(response) | ||||||
@dlq_retryable_codes && @dlq_retryable_codes.include?(response.code) | ||||||
end | ||||||
|
||||||
def retryable_exception?(exception) | ||||||
RETRYABLE_MANTICORE_EXCEPTIONS.any? {|me| exception.is_a?(me) } | ||||||
end | ||||||
|
@@ -379,4 +408,11 @@ def validate_format! | |||||
end | ||||||
end | ||||||
end | ||||||
|
||||||
def dlq_enabled? | ||||||
# this is the only way to determine if current logstash is supporting a dlq and dlq is also enabled | ||||||
# Reference: https://github.com/elastic/logstash/issues/8064 | ||||||
respond_to?(:execution_context) && execution_context.respond_to?(:dlq_writer) && | ||||||
!execution_context.dlq_writer.inner_writer.is_a?(::LogStash::Util::DummyDeadLetterQueueWriter) | ||||||
end | ||||||
end |
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' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new feature so it deserve a minor version. Actually
Suggested change
|
||||||
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" | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per later comment