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

Improve event sending thread lifecycle management #265

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Changes from all 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
9 changes: 7 additions & 2 deletions lib/riemann/tools/riemann_client_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ def initialize(options)
@draining = false

@worker = Thread.new do
Thread.current.abort_on_exception = true
loop do
events = []

events << @queue.pop
events << @queue.pop while !@queue.empty? && events.size < @max_bulk_size

client.bulk_send(events)
rescue Riemann::Client::Error => e
warn "Dropping #{events.size} event#{'s' if events.size > 1} due to #{e}"
rescue StandardError => e
warn "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
Thread.main.terminate
end
end
@worker.abort_on_exception = true

at_exit { drain }
end
Expand Down Expand Up @@ -60,7 +65,7 @@ def <<(event)

def drain
@draining = true
sleep(1) until @queue.empty?
sleep(1) until @queue.empty? || @worker.stop?
end
end
end
Expand Down