-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Normalize the exception behaviour for inputs outputs and filters #2386
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be0cf44
make input/output workers not retry on exception
jsvd 23ecd24
assure filter calls teardown when exception is raised
jsvd d0b163c
fix typo
jsvd 3fb8814
code cleanup
jsvd 1b93349
consistent exception logging across pluginworkers
jsvd b36e0fa
make workers retry on StandardError and fail on Exception
jsvd 7ee652d
pipeline:refactored specs. added Exception handling
jsvd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
class LogStash::Pipeline | ||
|
||
FLUSH_EVENT = LogStash::FlushEvent.new | ||
RETRY_INTERVAL = 0.5 # seconds | ||
|
||
def initialize(configstr) | ||
@logger = Cabin::Channel.get(LogStash) | ||
|
@@ -159,9 +160,8 @@ def start_filters | |
|
||
def start_outputs | ||
@outputs.each(&:register) | ||
@output_threads = [ | ||
Thread.new { outputworker } | ||
] | ||
@outputs.each(&:worker_setup) | ||
@output_threads = [ Thread.new { outputworker } ] | ||
end | ||
|
||
def start_input(plugin) | ||
|
@@ -170,71 +170,72 @@ def start_input(plugin) | |
|
||
def inputworker(plugin) | ||
LogStash::Util::set_thread_name("<#{plugin.class.config_name}") | ||
begin | ||
plugin.run(@input_to_filter) | ||
rescue LogStash::ShutdownSignal | ||
return | ||
rescue => e | ||
if @logger.debug? | ||
@logger.error(I18n.t("logstash.pipeline.worker-error-debug", | ||
:plugin => plugin.inspect, :error => e.to_s, | ||
:exception => e.class, | ||
:stacktrace => e.backtrace.join("\n"))) | ||
else | ||
@logger.error(I18n.t("logstash.pipeline.worker-error", | ||
:plugin => plugin.inspect, :error => e)) | ||
end | ||
puts e.backtrace if @logger.debug? | ||
plugin.teardown | ||
sleep 1 | ||
retry | ||
end | ||
plugin.run(@input_to_filter) | ||
rescue LogStash::ShutdownSignal | ||
# nothing | ||
rescue => e | ||
@logger.error exception_information(e) | ||
# TODO: find a way to obtain the event caused the exception | ||
sleep RETRY_INTERVAL | ||
retry | ||
rescue Exception => e | ||
@logger.fatal exception_information(e) | ||
shutdown | ||
ensure | ||
plugin.teardown | ||
end # def inputworker | ||
|
||
def filterworker | ||
LogStash::Util::set_thread_name("|worker") | ||
begin | ||
while true | ||
event = @input_to_filter.pop | ||
|
||
case event | ||
when LogStash::Event | ||
# use events array to guarantee ordering of origin vs created events | ||
# where created events are emitted by filters like split or metrics | ||
events = [] | ||
filter(event) { |newevent| events << newevent } | ||
events.each { |event| @filter_to_output.push(event) } | ||
when LogStash::FlushEvent | ||
# handle filter flushing here so that non threadsafe filters (thus only running one filterworker) | ||
# don't have to deal with thread safety implementing the flush method | ||
@flusher_lock.synchronize { flush_filters_to_output! } | ||
when LogStash::ShutdownEvent | ||
# pass it down to any other filterworker and stop this worker | ||
@input_to_filter.push(event) | ||
break | ||
end | ||
|
||
while(event = @input_to_filter.pop) | ||
case event | ||
when LogStash::Event | ||
# use events array to guarantee ordering of origin vs created events | ||
# where created events are emitted by filters like split or metrics | ||
events = [] | ||
filter(event) { |newevent| events << newevent } | ||
events.each { |event| @filter_to_output.push(event) } | ||
when LogStash::FlushEvent | ||
# handle filter flushing here so that non threadsafe filters (thus only running one filterworker) | ||
# don't have to deal with thread safety implementing the flush method | ||
@flusher_lock.synchronize { flush_filters_to_output! } | ||
when LogStash::ShutdownEvent | ||
# pass it down to any other filterworker and stop this worker | ||
@input_to_filter.push(event) | ||
break | ||
end | ||
rescue => e | ||
@logger.error("Exception in filterworker", "exception" => e, "backtrace" => e.backtrace) | ||
end | ||
|
||
rescue => e | ||
@logger.error exception_information(e) | ||
@logger.warn("Discarded event: #{event.to_hash}") | ||
sleep RETRY_INTERVAL | ||
retry | ||
rescue Exception => e | ||
@logger.fatal exception_information(e) | ||
shutdown | ||
ensure | ||
@filters.each(&:teardown) | ||
end # def filterworker | ||
|
||
def outputworker | ||
LogStash::Util::set_thread_name(">output") | ||
@outputs.each(&:worker_setup) | ||
|
||
while true | ||
event = @filter_to_output.pop | ||
while(event = @filter_to_output.pop) | ||
break if event.is_a?(LogStash::ShutdownEvent) | ||
output(event) | ||
end # while true | ||
|
||
rescue => e | ||
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. rescue StandardError => e |
||
@logger.error exception_information(e) | ||
@logger.warn("Discarded event: #{event.to_hash}") | ||
sleep RETRY_INTERVAL | ||
retry | ||
rescue Exception => e | ||
@logger.fatal exception_information(e) | ||
shutdown | ||
ensure | ||
@outputs.each do |output| | ||
output.worker_plugins.each(&:teardown) | ||
end | ||
|
@@ -302,4 +303,8 @@ def flush_filters_to_output!(options = {}) | |
end | ||
end # flush_filters_to_output! | ||
|
||
private | ||
def exception_information(exception) | ||
"Exception information: #{exception} => #{exception.backtrace}" | ||
end | ||
end # class Pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.