Class: Instana::Backend::HostAgentActivationObserver

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

Overview

Process which is responsible for initiating monitoring of a Ruby program with a local agent.

Since:

  • 1.197.0

Defined Under Namespace

Classes: DiscoveryError

Constant Summary collapse

DISCOVERY_URL =

Since:

  • 1.197.0

'/com.instana.plugin.ruby.discovery'.freeze
ENTITY_DATA_URL =

Since:

  • 1.197.0

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

Instance Method Summary collapse

Constructor Details

#initialize(client, discovery, wait_time: 30, logger: ::Instana.logger, max_wait_tries: 60, proc_table: Sys::ProcTable, socket_proc: default_socket_proc) ⇒ HostAgentActivationObserver

Returns a new instance of HostAgentActivationObserver.

Parameters:

  • client (RequestClient)

    used to make requests to the backend

  • discovery (Concurrent::Atom)

    object used to store discovery response in

Since:

  • 1.197.0



15
16
17
18
19
20
21
22
23
# File 'lib/instana/backend/host_agent_activation_observer.rb', line 15

def initialize(client, discovery, wait_time: 30, logger: ::Instana.logger, max_wait_tries: 60, proc_table: Sys::ProcTable, socket_proc: default_socket_proc) # rubocop:disable Metrics/ParameterLists
  @client = client
  @discovery = discovery
  @wait_time = wait_time
  @logger = logger
  @max_wait_tries = max_wait_tries
  @proc_table = proc_table
  @socket_proc = socket_proc
end

Instance Method Details

#update(_time, _old_version, new_version) ⇒ Object

Since:

  • 1.197.0



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/instana/backend/host_agent_activation_observer.rb', line 25

def update(_time, _old_version, new_version)
  return unless new_version.nil?

  socket = @socket_proc.call(@client)

  try_forever_with_backoff do
    payload = discovery_payload(socket)
    discovery_response = @client.send_request('PUT', DISCOVERY_URL, payload)

    raise DiscoveryError, "Discovery response was #{discovery_response.code} with `#{payload}`." unless discovery_response.ok?

    discovery = discovery_response.json
    raise DiscoveryError, "Expected discovery to be a Hash, not a `#{discovery.class}`." unless discovery.is_a?(Hash)

    @logger.debug("Discovery complete (`#{discovery}`). Waiting for agent.")
    wait_for_backend(discovery['pid'])
    @logger.debug("Agent ready.")
    @discovery.swap { discovery }
  end

  socket.close
end