Class: Contrast::Agent::ThreadWatcher

Inherits:
Object
  • Object
show all
Includes:
Components::Logger::InstanceMethods
Defined in:
lib/contrast/agent/thread/thread_watcher.rb

Overview

This class used to ensure that our worker threads are running in multi-process environments

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initializeThreadWatcher

Returns a new instance of ThreadWatcher.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 31

def initialize
  if Contrast::AGENT.disabled? || Contrast::Utils::JobServersRunning.job_servers_running?
    logger.info('Agent Disabled, shutting down all threads...')
    return
  end

  @heapdump_util = Contrast::Utils::HeapDumpUtil.new
  @reporter = Contrast::Agent::Reporter.new
  @reporter_heartbeat = Contrast::Agent::ReportingWorkers::ReporterHeartbeat.new
  @reporter_settings_worker = Contrast::Agent::ReportingWorkers::ServerSettingsWorker.new
  @reporter_app_settings_worker = Contrast::Agent::ReportingWorkers::ApplicationServerWorker.new
  @telemetry = Contrast::Agent::Telemetry::Base.new if Contrast::Agent::Telemetry::Base.enabled?
  @worth_watching_analyzer = Contrast::Agent::Protect::WorthWatchingInputAnalyzer.new unless protect_disabled?
end

Instance Attribute Details

#heapdump_utilContrast::Utils::HeapDumpUtil (readonly)



19
20
21
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 19

def heapdump_util
  @heapdump_util
end

#reporterContrast::Agent::Reporter (readonly)



21
22
23
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 21

def reporter
  @reporter
end

#reporter_app_settings_workerContrast::Agent::ReportingWorkers::ApplicationServerWorker (readonly)



29
30
31
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 29

def reporter_app_settings_worker
  @reporter_app_settings_worker
end

#reporter_heartbeatContrast::Agent::ReportingWorkers::ReporterHeartbeat (readonly)



23
24
25
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 23

def reporter_heartbeat
  @reporter_heartbeat
end

#reporter_settings_workerContrast::Agent::ReportingWorkers::ServerSettingsWorker (readonly)



27
28
29
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 27

def reporter_settings_worker
  @reporter_settings_worker
end

#worth_watching_analyzerContrast::Agent::Protect::WorthWatchingInputAnalyzer (readonly)



25
26
27
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 25

def worth_watching_analyzer
  @worth_watching_analyzer
end

Instance Method Details

#ensure_running?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 59

def ensure_running?
  return if desired_threads.all?(&:running?)

  logger.debug('ThreadWatcher - threads not running')
  startup!
end

#shutdown!Object



66
67
68
69
70
71
72
73
74
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 66

def shutdown!
  heapdump_util&.stop!
  telemetry_queue&.stop!
  reporter&.stop!
  reporter_heartbeat&.stop!
  worth_watching_analyzer&.stop!
  reporter_settings_worker&.stop!
  reporter_app_settings_worker&.stop!
end

#startup!Array<Contrast::Agent::WorkerThread>

Returns map of process to thread startup status.

Returns:



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 47

def startup!
  check_before_start

  return unless ::Contrast::AGENT.enabled?

  logger.debug('ThreadWatcher started threads')

  desired_threads.each do |thread|
    init_thread(thread)
  end
end

#telemetry_queueContrast::Agent::Telemetry::Base



77
78
79
# File 'lib/contrast/agent/thread/thread_watcher.rb', line 77

def telemetry_queue
  @telemetry
end