From e46fc3c95c22e6933f5a3b5ef2eb9cee95a3d65e Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Wed, 5 Apr 2023 23:39:29 +0200 Subject: [PATCH 1/2] Add crude remote configuration agent requirements check --- lib/datadog/core/remote/component.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/datadog/core/remote/component.rb b/lib/datadog/core/remote/component.rb index c5cbc749b9a..cc6826b8c84 100644 --- a/lib/datadog/core/remote/component.rb +++ b/lib/datadog/core/remote/component.rb @@ -20,6 +20,28 @@ def initialize(settings, agent_settings) transport_options = {} transport_options[:agent_settings] = agent_settings if agent_settings + transport_root = Datadog::Core::Transport::HTTP.root(**transport_options.dup) + + res = transport_root.send_info + if res.ok? + if res.endpoints.include?('/v0.7/config') + Datadog.logger.debug { 'agent reachable and reports remote configuration endpoint' } + else + Datadog.logger.error do + 'agent reachable but does not report remote configuration endpoint: ' \ + 'disabling remote configuration for this process.' + end + + return + end + else + Datadog.logger.error do + 'agent unreachable: disabling remote configuration for this process.' + end + + return + end + transport_v7 = Datadog::Core::Transport::HTTP.v7(**transport_options.dup) capabilities = Client::Capabilities.new(settings) From 2795b2f739f29ad75c8db286fdb0a2ee0f862d81 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 14 Apr 2023 15:52:35 +0200 Subject: [PATCH 2/2] Move negotiation out of remote component initialize This avoids getting a partially initialized instance of component --- lib/datadog/core/remote/component.rb | 47 +++++++++++++++------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/datadog/core/remote/component.rb b/lib/datadog/core/remote/component.rb index cc6826b8c84..a8d4dd8a16b 100644 --- a/lib/datadog/core/remote/component.rb +++ b/lib/datadog/core/remote/component.rb @@ -20,28 +20,6 @@ def initialize(settings, agent_settings) transport_options = {} transport_options[:agent_settings] = agent_settings if agent_settings - transport_root = Datadog::Core::Transport::HTTP.root(**transport_options.dup) - - res = transport_root.send_info - if res.ok? - if res.endpoints.include?('/v0.7/config') - Datadog.logger.debug { 'agent reachable and reports remote configuration endpoint' } - else - Datadog.logger.error do - 'agent reachable but does not report remote configuration endpoint: ' \ - 'disabling remote configuration for this process.' - end - - return - end - else - Datadog.logger.error do - 'agent unreachable: disabling remote configuration for this process.' - end - - return - end - transport_v7 = Datadog::Core::Transport::HTTP.v7(**transport_options.dup) capabilities = Client::Capabilities.new(settings) @@ -138,6 +116,31 @@ class << self def build(settings, agent_settings) return unless settings.remote.enabled + transport_options = {} + transport_options[:agent_settings] = agent_settings if agent_settings + + transport_root = Datadog::Core::Transport::HTTP.root(**transport_options.dup) + + res = transport_root.send_info + if res.ok? + if res.endpoints.include?('/v0.7/config') + Datadog.logger.debug { 'agent reachable and reports remote configuration endpoint' } + else + Datadog.logger.error do + 'agent reachable but does not report remote configuration endpoint: ' \ + 'disabling remote configuration for this process.' + end + + return + end + else + Datadog.logger.error do + 'agent unreachable: disabling remote configuration for this process.' + end + + return + end + new(settings, agent_settings) end end