@@ -13,9 +13,11 @@ module Remote
13
13
# Configures the HTTP transport to communicate with the agent
14
14
# to fetch and sync the remote configuration
15
15
class Component
16
- attr_reader :client , :healthy
16
+ attr_reader :logger , :client , :healthy
17
+
18
+ def initialize ( settings , capabilities , agent_settings , logger :)
19
+ @logger = logger
17
20
18
- def initialize ( settings , capabilities , agent_settings )
19
21
transport_options = { }
20
22
transport_options [ :agent_settings ] = agent_settings if agent_settings
21
23
@@ -26,9 +28,9 @@ def initialize(settings, capabilities, agent_settings)
26
28
27
29
@client = Client . new ( transport_v7 , capabilities )
28
30
@healthy = false
29
- Datadog . logger . debug { "new remote configuration client: #{ @client . id } " }
31
+ logger . debug { "new remote configuration client: #{ @client . id } " }
30
32
31
- @worker = Worker . new ( interval : settings . remote . poll_interval_seconds ) do
33
+ @worker = Worker . new ( interval : settings . remote . poll_interval_seconds , logger : logger ) do
32
34
unless @healthy || negotiation . endpoint? ( '/v0.7/config' )
33
35
@barrier . lift
34
36
@@ -40,7 +42,7 @@ def initialize(settings, capabilities, agent_settings)
40
42
@healthy ||= true
41
43
rescue Client ::SyncError => e
42
44
# Transient errors due to network or agent. Logged the error but not via telemetry
43
- Datadog . logger . error do
45
+ logger . error do
44
46
"remote worker client sync error: #{ e . message } location: #{ Array ( e . backtrace ) . first } . skipping sync"
45
47
end
46
48
rescue StandardError => e
@@ -50,15 +52,15 @@ def initialize(settings, capabilities, agent_settings)
50
52
negotiation = Negotiation . new ( settings , agent_settings )
51
53
52
54
# Transient errors due to network or agent. Logged the error but not via telemetry
53
- Datadog . logger . error do
55
+ logger . error do
54
56
"remote worker error: #{ e . class . name } #{ e . message } location: #{ Array ( e . backtrace ) . first } . " \
55
57
'reseting client state'
56
58
end
57
59
58
60
# client state is unknown, state might be corrupted
59
61
@client = Client . new ( transport_v7 , capabilities )
60
62
@healthy = false
61
- Datadog . logger . debug { "new remote configuration client: #{ @client . id } " }
63
+ logger . debug { "new remote configuration client: #{ @client . id } " }
62
64
63
65
# TODO: bail out if too many errors?
64
66
end
@@ -152,10 +154,10 @@ class << self
152
154
#
153
155
# Those checks are instead performed inside the worker loop.
154
156
# This allows users to upgrade their agent while keeping their application running.
155
- def build ( settings , agent_settings , telemetry :)
157
+ def build ( settings , agent_settings , logger : , telemetry :)
156
158
return unless settings . remote . enabled
157
159
158
- new ( settings , Client ::Capabilities . new ( settings , telemetry ) , agent_settings )
160
+ new ( settings , Client ::Capabilities . new ( settings , telemetry ) , agent_settings , logger : logger )
159
161
end
160
162
end
161
163
end
0 commit comments