Class: Instana::Backend::HostAgentReportingObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/instana/backend/host_agent_reporting_observer.rb

Overview

Process which is responsible for reporting metrics and tracing to the local agent

Since:

  • 1.197.0

Constant Summary collapse

ENTITY_DATA_URL =

Since:

  • 1.197.0

'/com.instana.plugin.ruby.%i'.freeze
RESPONSE_DATA_URL =

Since:

  • 1.197.0

'/com.instana.plugin.ruby/response.%i?messageId=%s'.freeze
TRACES_DATA_URL =

Since:

  • 1.197.0

"/com.instana.plugin.ruby/traces.%i".freeze
TRACE_METRICS_URL =

Since:

  • 1.197.0

"/tracermetrics".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, discovery, logger: ::Instana.logger, timer_class: Concurrent::TimerTask, processor: ::Instana.processor) ⇒ HostAgentReportingObserver

Returns a new instance of HostAgentReportingObserver.

Parameters:

  • client (RequestClient)

    used to make requests to the backend

  • discovery (Concurrent::Atom)

    object used to store discovery response in

Since:

  • 1.197.0



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/instana/backend/host_agent_reporting_observer.rb', line 18

def initialize(client, discovery, logger: ::Instana.logger, timer_class: Concurrent::TimerTask, processor: ::Instana.processor)
  @client = client
  @discovery = discovery
  @logger = logger
  @timer_class = timer_class
  @nonce = Time.now
  @processor = processor

  # Initialize timers with default 1 second interval
  @metrics_timer = @timer_class.new(execution_interval: 1, run_now: true) { report_metrics_to_backend }
  @traces_timer = @timer_class.new(execution_interval: 1, run_now: true) { report_traces_to_backend }
end

Instance Attribute Details

#metrics_timerObject (readonly)

Since:

  • 1.197.0



14
15
16
# File 'lib/instana/backend/host_agent_reporting_observer.rb', line 14

def metrics_timer
  @metrics_timer
end

#traces_timerObject (readonly)

Since:

  • 1.197.0



14
15
16
# File 'lib/instana/backend/host_agent_reporting_observer.rb', line 14

def traces_timer
  @traces_timer
end

Instance Method Details

#update(time, _old_version, new_version) ⇒ Object

Since:

  • 1.197.0



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/instana/backend/host_agent_reporting_observer.rb', line 31

def update(time, _old_version, new_version)
  return unless time > @nonce

  @nonce = time

  if new_version.nil?
    @metrics_timer&.shutdown
    @traces_timer&.shutdown
  else
    # Read poll_rate from discovery payload - it's nested under plugin.ruby.poll_rate
    discovery = @discovery.value
    poll_rate = discovery&.dig('plugin', 'ruby', 'poll_rate') || 1

    # Only recreate metrics_timer if poll_rate is different from current interval
    if @metrics_timer.nil? || @metrics_timer.execution_interval != poll_rate
      @metrics_timer&.shutdown
      @metrics_timer = @timer_class.new(execution_interval: poll_rate, run_now: true) { report_metrics_to_backend }
    end
    @metrics_timer.execute

    # Traces timer always uses 1 second interval
    @traces_timer&.shutdown
    @traces_timer = @timer_class.new(execution_interval: 1, run_now: true) { report_traces_to_backend }
    @traces_timer.execute
  end
end