Class: Instana::Backend::HostAgentActivationObserver
- Inherits:
-
Object
- Object
- Instana::Backend::HostAgentActivationObserver
- 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.
Defined Under Namespace
Classes: DiscoveryError
Constant Summary collapse
- DISCOVERY_URL =
'/com.instana.plugin.ruby.discovery'.freeze
- ENTITY_DATA_URL =
'/com.instana.plugin.ruby.%i'.freeze
Instance Method Summary collapse
-
#initialize(client, discovery, wait_time: 30, logger: ::Instana.logger, max_wait_tries: 60, proc_table: Sys::ProcTable, socket_proc: default_socket_proc) ⇒ HostAgentActivationObserver
constructor
A new instance of HostAgentActivationObserver.
- #update(_time, _old_version, new_version) ⇒ Object
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.
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
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 |