8
8
"fmt"
9
9
"net/http"
10
10
"strings"
11
- "sync"
12
11
"time"
13
12
14
13
coreconfig "github.com/DataDog/datadog-agent/comp/core/config"
@@ -37,12 +36,12 @@ import (
37
36
)
38
37
39
38
type (
40
- // APIKeyValidator is a function that validates the API key, provided to newExtension for mocking
41
- APIKeyValidator func (context.Context , string , * zap.Logger , * datadog.APIClient ) error
42
- // SourceProviderGetter is a function that returns a source.Provider, provided to newExtension for mocking
43
- SourceProviderGetter func (component.TelemetrySettings , string , time.Duration ) (source.Provider , error )
44
- // ForwarderGetter is a function that returns a defaultforwarder.Forwarder, provided to newExtension for mocking
45
- ForwarderGetter func (coreconfig.Component , corelog.Component ) defaultforwarder.Forwarder
39
+ // apiKeyValidator is a function that validates the API key, provided to newExtension for mocking
40
+ apiKeyValidator func (context.Context , string , * zap.Logger , * datadog.APIClient ) error
41
+ // sourceProviderGetter is a function that returns a source.Provider, provided to newExtension for mocking
42
+ sourceProviderGetter func (component.TelemetrySettings , string , time.Duration ) (source.Provider , error )
43
+ // forwarderGetter is a function that returns a defaultforwarder.Forwarder, provided to newExtension for mocking
44
+ forwarderGetter func (coreconfig.Component , corelog.Component ) defaultforwarder.Forwarder
46
45
)
47
46
48
47
// defaultForwarderInterface is wrapper for methods in datadog-agent DefaultForwarder struct
@@ -69,14 +68,12 @@ type fleetAutomationExtension struct {
69
68
collectorConfigStringMap map [string ]any
70
69
ticker * time.Ticker
71
70
done chan bool
72
- mu sync.RWMutex
73
71
uuid uuid.UUID
74
72
75
- buildInfo payload.CustomBuildInfo
76
- moduleInfo service.ModuleInfos
77
- ModuleInfoJSON * payload.ModuleInfoJSON
78
- activeComponentsJSON * payload.ActiveComponentsJSON
79
- version string
73
+ buildInfo payload.CustomBuildInfo
74
+ moduleInfo service.ModuleInfos
75
+ ModuleInfoJSON * payload.ModuleInfoJSON
76
+ version string
80
77
81
78
forwarder defaultForwarderInterface
82
79
compressor * compression.Compressor
@@ -111,14 +108,15 @@ var (
111
108
// This method is called during the startup process by the Collector's Service right after
112
109
// calling Start.
113
110
func (e * fleetAutomationExtension ) NotifyConfig (ctx context.Context , conf * confmap.Conf ) error {
114
- e .mu .Lock ()
115
- defer e .mu .Unlock ()
116
111
117
112
e .collectorConfig = conf
118
113
e .telemetry .Logger .Info ("Received new collector configuration" )
119
114
e .collectorConfigStringMap = e .collectorConfig .ToStringMap ()
120
115
121
116
e .updateHostname (ctx )
117
+ if e .hostnameSource == "unset" {
118
+ return fmt .Errorf ("collector hostname is unset, please set hostname manually in config" )
119
+ }
122
120
123
121
// create agent metadata payload. most fields are not relevant to OSS collector.
124
122
e .agentMetadataPayload = payload .PrepareAgentMetadataPayload (
@@ -165,7 +163,6 @@ func (e *fleetAutomationExtension) NotifyConfig(ctx context.Context, conf *confm
165
163
e .otelCollectorPayload ,
166
164
)
167
165
if err != nil {
168
- e .telemetry .Logger .Error ("Failed to prepare and send fleet automation payloads" , zap .Error (err ))
169
166
return err
170
167
}
171
168
@@ -174,12 +171,9 @@ func (e *fleetAutomationExtension) NotifyConfig(ctx context.Context, conf *confm
174
171
175
172
// Start starts the extension via the component interface.
176
173
func (e * fleetAutomationExtension ) Start (_ context.Context , host component.Host ) error {
177
- if e .forwarder != nil {
178
- err := e .forwarder .Start ()
179
- if err != nil {
180
- e .telemetry .Logger .Error ("Failed to start forwarder" , zap .Error (err ))
181
- return err
182
- }
174
+ err := e .forwarder .Start ()
175
+ if err != nil {
176
+ return err
183
177
}
184
178
185
179
// Store the host for component status tracking
@@ -194,7 +188,6 @@ func (e *fleetAutomationExtension) Start(_ context.Context, host component.Host)
194
188
// Create and start HTTP server
195
189
e .httpServer = httpserver .NewServer (e .telemetry .Logger , e .serializer , e .forwarder )
196
190
if e .httpServer == nil {
197
- e .telemetry .Logger .Error ("Failed to create HTTP server" )
198
191
return fmt .Errorf ("failed to create HTTP server" )
199
192
}
200
193
e .httpServer .Start (func (w http.ResponseWriter , r * http.Request ) {
@@ -265,8 +258,6 @@ func (e *fleetAutomationExtension) processComponentStatusEvents() {
265
258
266
259
// updateComponentStatus updates the componentStatus map with the latest status
267
260
func (e * fleetAutomationExtension ) updateComponentStatus (esp * eventSourcePair ) {
268
- e .mu .Lock ()
269
- defer e .mu .Unlock ()
270
261
271
262
if e .componentStatus == nil {
272
263
e .componentStatus = make (map [string ]any )
@@ -351,9 +342,9 @@ func newExtension(
351
342
ctx context.Context ,
352
343
config * Config ,
353
344
settings extension.Settings ,
354
- apiKeyValidator APIKeyValidator ,
355
- sourceProviderGetter SourceProviderGetter ,
356
- forwarderGetter ForwarderGetter ,
345
+ apiKeyValidator apiKeyValidator ,
346
+ sourceProviderGetter sourceProviderGetter ,
347
+ forwarderGetter forwarderGetter ,
357
348
) (* fleetAutomationExtension , error ) {
358
349
// API Key validation
359
350
// TODO: consider moving common logic to pkg/datadog or internal/datadog
@@ -412,7 +403,7 @@ func newExtension(
412
403
serializer : serializer ,
413
404
buildInfo : buildInfo ,
414
405
version : version ,
415
- ticker : time .NewTicker (config . ReporterPeriod ),
406
+ ticker : time .NewTicker (defaultReporterPeriod ),
416
407
done : make (chan bool ),
417
408
hostnameProvider : sp ,
418
409
hostnameSource : hostnameSource ,
0 commit comments