lib/contrast/agent/thread_watcher.rb in contrast-agent-4.13.1 vs lib/contrast/agent/thread_watcher.rb in contrast-agent-4.14.0
- old
+ new
@@ -2,10 +2,11 @@
# frozen_string_literal: true
require 'contrast/components/logger'
require 'contrast/agent/service_heartbeat'
require 'contrast/api/communication/messaging_queue'
+require 'contrast/agent/reporting/report'
require 'contrast/agent/telemetry'
module Contrast
module Agent
# This class used to ensure that our worker threads are running in multi-process environments
@@ -22,25 +23,30 @@
@pids = {}
@heapdump_util = Contrast::Utils::HeapDumpUtil.new
@heartbeat = Contrast::Agent::ServiceHeartbeat.new
@messaging_queue = Contrast::Api::Communication::MessagingQueue.new
@telemetry = Contrast::Agent::Telemetry.new if Contrast::Agent::Telemetry.enabled?
+ @reporter = Contrast::Agent::Reporter.new if Contrast::Agent::Reporter.enabled?
end
def startup!
return unless ::Contrast::AGENT.enabled?
- telemetry_thread_status = telemetry_thread_init
- heartbeat_thread_status = heartbeat_thread_init
- messaging_thread_status = messaging_thread_init
+ telemetry_status = telemetry_thread_init
+ heartbeat_status = heartbeat_thread_init
+ messaging_status = messaging_thread_init
+ reporter_status = reporter_thread_init
logger.debug('ThreadWatcher started threads')
- @pids[Process.pid] = messaging_thread_status && heartbeat_thread_status
+ @pids[Process.pid] = messaging_status && heartbeat_status
return @pids unless Contrast::Agent::Telemetry.enabled?
- @pids[Process.pid] = messaging_thread_status && heartbeat_thread_status && telemetry_thread_status
+ @pids[Process.pid] = @pids[Process.pid] && telemetry_status
+ return @pids unless Contrast::Agent::Reporter.enabled?
+
+ @pids[Process.pid] = @pids[Process.pid] && reporter_status
end
def ensure_running?
return if @pids[Process.pid] == true
@@ -51,10 +57,11 @@
def shutdown!
heartbeat.stop!
messaging_queue.stop!
heapdump_util.stop!
telemetry_queue&.stop!
+ reporter_queue&.stop!
end
def heartbeat_thread_init
unless heartbeat.running?
logger.debug('Attempting to start heartbeat thread')
@@ -80,13 +87,32 @@
messaging_result = messaging_queue.running?
logger.debug('Messaging thread status', alive: messaging_result)
messaging_result
end
+ def reporter_thread_init
+ @reporter.start_thread! if @reporter&.attempt_to_start?
+ unless @reporter&.running?
+ logger.debug('Attempting to start reporter thread')
+ @reporter&.start_thread!
+ end
+ reporter_result = @reporter&.running?
+ logger.debug('Reporter thread status', alive: reporter_result)
+ reporter_result
+ end
+
+ # @return [Contrast::Agent::Telemetry]
def telemetry_queue
return if @telemetry.nil?
@telemetry
+ end
+
+ # @return [Contrast::Agent::Reporter]
+ def reporter_queue
+ return if @reporter.nil?
+
+ @reporter
end
end
end
end