Skip to content

Rely on ActiveSupport::Notifications and ActiveSupport::LogSubscriber for logging and instrumentation #208

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

Merged
merged 12 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Instrument process shutdown and add some more info to replaced fork e…
…vent

So we at least can tell when it received a SIGKILL or when it exited normally.
  • Loading branch information
rosa committed May 1, 2024
commit b9db22d40a8b6b4eecfe86a638a2dd045c98bd7b
20 changes: 18 additions & 2 deletions lib/solid_queue/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def start_process(event)
info formatted_event(event, action: "Started #{process.kind}", **attributes)
end

def shutdown_process(event)
process = event.payload[:process]

attributes = {
pid: process.pid,
hostname: process.hostname
}.merge(process.metadata)

info formatted_event(event, action: "Shut down #{process.kind}", **attributes)
end

def register_process(event)
process_kind = event.payload[:kind]
attributes = event.payload.slice(:pid, :hostname)
Expand Down Expand Up @@ -119,10 +130,15 @@ def unhandled_signal_error(event)

def replace_fork(event)
status = event.payload[:status]
attributes = event.payload.slice(:pid).merge(status: status.exitstatus, pid_from_status: status.pid)
attributes = event.payload.slice(:pid).merge \
status: (status.exitstatus || "no exit status set"),
pid_from_status: status.pid,
signaled: status.signaled?,
stopsig: status.stopsig,
termsig: status.termsig

if replaced_fork = event.payload[:fork]
info formatted_event(event, action: "Replaced #{replaced_fork.kind}", **attributes.merge(hostname: replaced_fork.hostname))
info formatted_event(event, action: "Replaced terminated #{replaced_fork.kind}", **attributes.merge(hostname: replaced_fork.hostname))
else
warn formatted_event(event, action: "Tried to replace forked process but it had already died", **attributes)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/solid_queue/processes/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def start_loop
end
end
ensure
run_callbacks(:shutdown) { shutdown }
SolidQueue.instrument(:shutdown_process, process: self) do
run_callbacks(:shutdown) { shutdown }
end
end

def poll
Expand Down
8 changes: 4 additions & 4 deletions test/integration/instrumentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class InstrumentationTest < ActiveSupport::TestCase
events = subscribed(/release.*_claimed\.solid_queue/) do
worker = SolidQueue::Worker.new.tap(&:start)

wait_while_with_timeout(1.seconds) { SolidQueue::ReadyExecution.any? }
wait_while_with_timeout(3.seconds) { SolidQueue::ReadyExecution.any? }
process = SolidQueue::Process.last

worker.stop
wait_for_registered_processes(0, timeout: 1.second)
wait_for_registered_processes(0, timeout: 3.second)
end

assert_equal 2, events.size
Expand Down Expand Up @@ -59,12 +59,12 @@ class InstrumentationTest < ActiveSupport::TestCase

events = subscribed(/(register|deregister)_process\.solid_queue/) do
worker = SolidQueue::Worker.new.tap(&:start)
wait_while_with_timeout(1.seconds) { SolidQueue::ReadyExecution.any? }
wait_while_with_timeout(3.seconds) { SolidQueue::ReadyExecution.any? }

process = SolidQueue::Process.last

worker.stop
wait_for_registered_processes(0, timeout: 1.second)
wait_for_registered_processes(0, timeout: 3.second)
end

assert_equal 2, events.size
Expand Down
Loading