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.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
-
.build(settings, agent_settings, logger:, 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, logger:) ⇒ 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, logger:) ⇒ 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 |
# File 'lib/datadog/core/remote/component.rb', line 18 def initialize(settings, capabilities, agent_settings, logger:) @logger = logger negotiation = Negotiation.new(settings, agent_settings, logger: logger) transport_v7 = Datadog::Core::Remote::Transport::HTTP.v7(agent_settings: agent_settings, logger: logger) @barrier = Barrier.new(settings.remote.boot_timeout_seconds) @client = Client.new(transport_v7, capabilities, logger: logger) @healthy = false logger.debug { "new remote configuration client: #{@client.id}" } @worker = Worker.new(interval: settings.remote.poll_interval_seconds, logger: logger) 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 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, logger: logger) # Transient errors due to network or agent. Logged the error but not via telemetry 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, logger: logger) @healthy = false 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 |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/datadog/core/remote/component.rb', line 16 def logger @logger end |
Class Method Details
.build(settings, agent_settings, logger:, 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.
154 155 156 157 158 |
# File 'lib/datadog/core/remote/component.rb', line 154 def build(settings, agent_settings, logger:, telemetry:) return unless settings.remote.enabled new(settings, Client::Capabilities.new(settings, telemetry), agent_settings, logger: logger) 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`.
82 83 84 85 |
# File 'lib/datadog/core/remote/component.rb', line 82 def (_kind) start @barrier.wait_once end |
#shutdown! ⇒ Object
87 88 89 |
# File 'lib/datadog/core/remote/component.rb', line 87 def shutdown! @worker.stop end |
#start ⇒ Object
Starts the Remote Configuration worker without waiting for first run
70 71 72 |
# File 'lib/datadog/core/remote/component.rb', line 70 def start @worker.start end |
#started? ⇒ Boolean
Is the Remote Configuration worker running?
75 76 77 |
# File 'lib/datadog/core/remote/component.rb', line 75 def started? @worker.started? end |