Class: Datadog::Core::Remote::Component
- Inherits:
-
Object
- Object
- Datadog::Core::Remote::Component
- Defined in:
- lib/datadog/core/remote/component.rb
Overview
Configures the HTTP transport to communicate with the agent to fetch and sync the remote configuration
Defined Under Namespace
Classes: Barrier
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#healthy ⇒ Object
readonly
Returns the value of attribute healthy.
Class Method Summary collapse
-
.build(settings, agent_settings, telemetry:) ⇒ Object
Because the agent might not be available yet, we can’t perform agent-specific checks yet, as they would prevent remote configuration from ever running.
Instance Method Summary collapse
-
#barrier(_kind) ⇒ Object
If the worker is not initialized, initialize it.
-
#initialize(settings, capabilities, agent_settings) ⇒ Component
constructor
A new instance of Component.
- #shutdown! ⇒ Object
-
#start ⇒ Object
Starts the Remote Configuration worker without waiting for first run.
-
#started? ⇒ Boolean
Is the Remote Configuration worker running?.
Constructor Details
#initialize(settings, capabilities, agent_settings) ⇒ Component
Returns a new instance of Component.
18 19 20 21 22 23 24 25 26 27 28 29 30 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 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/datadog/core/remote/component.rb', line 18 def initialize(settings, capabilities, agent_settings) = {} [:agent_settings] = agent_settings if agent_settings negotiation = Negotiation.new(settings, agent_settings) transport_v7 = Datadog::Core::Remote::Transport::HTTP.v7(**.dup) @barrier = Barrier.new(settings.remote.boot_timeout_seconds) @client = Client.new(transport_v7, capabilities) @healthy = false Datadog.logger.debug { "new remote configuration client: #{@client.id}" } @worker = Worker.new(interval: settings.remote.poll_interval_seconds) do unless @healthy || negotiation.endpoint?('/v0.7/config') @barrier.lift next end begin @client.sync @healthy ||= true rescue Client::SyncError => e # Transient errors due to network or agent. Logged the error but not via telemetry Datadog.logger.error do "remote worker client sync error: #{e.} location: #{Array(e.backtrace).first}. skipping sync" end rescue StandardError => e # In case of unexpected errors, reset the negotiation object # given external conditions have changed and the negotiation # negotiation object stores error logging state that should be reset. negotiation = Negotiation.new(settings, agent_settings) # Transient errors due to network or agent. Logged the error but not via telemetry Datadog.logger.error do "remote worker error: #{e.class.name} #{e.} location: #{Array(e.backtrace).first}. "\ 'reseting client state' end # client state is unknown, state might be corrupted @client = Client.new(transport_v7, capabilities) @healthy = false Datadog.logger.debug { "new remote configuration client: #{@client.id}" } # TODO: bail out if too many errors? end @barrier.lift end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
16 17 18 |
# File 'lib/datadog/core/remote/component.rb', line 16 def client @client end |
#healthy ⇒ Object (readonly)
Returns the value of attribute healthy.
16 17 18 |
# File 'lib/datadog/core/remote/component.rb', line 16 def healthy @healthy end |
Class Method Details
.build(settings, agent_settings, telemetry:) ⇒ Object
Because the agent might not be available yet, we can’t perform agent-specific checks yet, as they would prevent remote configuration from ever running.
Those checks are instead performed inside the worker loop. This allows users to upgrade their agent while keeping their application running.
155 156 157 158 159 |
# File 'lib/datadog/core/remote/component.rb', line 155 def build(settings, agent_settings, telemetry:) return unless settings.remote.enabled new(settings, Client::Capabilities.new(settings, telemetry), agent_settings) end |
Instance Method Details
#barrier(_kind) ⇒ Object
If the worker is not initialized, initialize it.
Then, waits for one client sync to be executed if ‘kind` is `:once`.
83 84 85 86 |
# File 'lib/datadog/core/remote/component.rb', line 83 def (_kind) start @barrier.wait_once end |
#shutdown! ⇒ Object
88 89 90 |
# File 'lib/datadog/core/remote/component.rb', line 88 def shutdown! @worker.stop end |
#start ⇒ Object
Starts the Remote Configuration worker without waiting for first run
71 72 73 |
# File 'lib/datadog/core/remote/component.rb', line 71 def start @worker.start end |
#started? ⇒ Boolean
Is the Remote Configuration worker running?
76 77 78 |
# File 'lib/datadog/core/remote/component.rb', line 76 def started? @worker.started? end |