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

Fix Health Monitor JSON plugin + add error logging #2530

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/bosh-monitor/lib/bosh/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Monitor
require 'async'
require 'async/http'
require 'async/io'
require 'async/io/stream'
require 'logging'
require 'nats/io/client'
require 'puma'
Expand Down
9 changes: 6 additions & 3 deletions src/bosh-monitor/lib/bosh/monitor/plugins/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def restart_process(bin)

def start_process(bin)
process = Bosh::Monitor::Plugins::DeferrableChildProcess.open(bin)
process.errback do
process.errback do |exception|
if exception
@logger.error("JSON Plugin: Unexpected error occurred for #{bin}: #{exception} - #{exception.backtrace.join("\n")}")
end
Async do
sleep(@restart_wait)
restart_process bin
Expand Down Expand Up @@ -117,12 +120,12 @@ def run
status = @wait_thr.value
unless status.success?
@errback.each do |errback|
errback.call
errback.call(nil)
end
end
rescue => e
@errback.each do |errback|
errback.call
errback.call(e)
end
ensure
@stdin.close if @stdin
Expand Down
11 changes: 11 additions & 0 deletions src/bosh-monitor/spec/unit/bosh/monitor/plugins/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
context 'when the event loop is running' do
include_context Async::RSpec::Reactor

it 'works' do
allow(Dir).to receive(:[]).with('/*/json-plugin/*').and_return(['echo "hello"'])
expect(Bosh::Monitor::Plugins::DeferrableChildProcess).to receive(:open).once.with('echo "hello"').and_call_original
expect(Open3).to receive(:popen3).with('echo "hello"').and_call_original

process_manager.start

# Wait to ensure that the process isn't restarted due to an internal error
sleep restart_wait * 2
end

it 'starts processes that match the glob' do
allow(Dir).to receive(:[]).with('/*/json-plugin/*').and_return(['/plugin'])

Expand Down