Class: NewRelic::Agent::Harvester

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/harvester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events, after_forker = NewRelic::Agent) ⇒ Harvester

Inject target for after_fork call to avoid spawning thread in tests



11
12
13
14
15
16
17
18
# File 'lib/new_relic/agent/harvester.rb', line 11

def initialize(events, after_forker = NewRelic::Agent)
  # We intentionally don't set our pid as started at this point.
  # Startup routines must call mark_started when they consider us set!
  @starting_pid = nil
  @after_forker = after_forker

  events&.subscribe(:start_transaction, &method(:on_transaction))
end

Instance Attribute Details

#starting_pidObject



8
9
10
# File 'lib/new_relic/agent/harvester.rb', line 8

def starting_pid
  @starting_pid
end

Instance Method Details

#harvest_thread_enabled?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/new_relic/agent/harvester.rb', line 40

def harvest_thread_enabled?
  !NewRelic::Agent.config[:disable_harvest_thread]
end

#mark_started(pid = Process.pid) ⇒ Object



28
29
30
# File 'lib/new_relic/agent/harvester.rb', line 28

def mark_started(pid = Process.pid)
  @starting_pid = pid
end

#needs_restart?(pid = Process.pid) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/new_relic/agent/harvester.rb', line 32

def needs_restart?(pid = Process.pid)
  @starting_pid != pid
end

#on_transaction(*_) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/new_relic/agent/harvester.rb', line 20

def on_transaction(*_)
  return unless restart_in_children_enabled? &&
    needs_restart? &&
    harvest_thread_enabled?

  restart_harvest_thread
end

#restart_harvest_threadObject



44
45
46
# File 'lib/new_relic/agent/harvester.rb', line 44

def restart_harvest_thread
  @after_forker.after_fork(:force_reconnect => true)
end

#restart_in_children_enabled?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/new_relic/agent/harvester.rb', line 36

def restart_in_children_enabled?
  NewRelic::Agent.config[:restart_thread_in_children]
end