@@ -58,7 +58,7 @@ type fleetAutomationExtension struct {
58
58
mu sync.RWMutex
59
59
uuid uuid.UUID
60
60
61
- buildInfo component. BuildInfo
61
+ buildInfo CustomBuildInfo
62
62
moduleInfo service.ModuleInfos
63
63
moduleInfoJSON * moduleInfoJSON
64
64
activeComponentsJSON * activeComponentsJSON
@@ -70,6 +70,7 @@ type fleetAutomationExtension struct {
70
70
71
71
agentMetadataPayload AgentMetadata
72
72
otelMetadataPayload OtelMetadata
73
+ otelCollectorPayload OtelCollector
73
74
74
75
httpServer * http.Server
75
76
healthCheckV2Enabled bool
@@ -123,6 +124,16 @@ func (e *fleetAutomationExtension) NotifyConfig(ctx context.Context, conf *confm
123
124
fullConfig ,
124
125
)
125
126
127
+ e .otelCollectorPayload = prepareOtelCollectorPayload (
128
+ e .hostname ,
129
+ e .hostnameSource ,
130
+ e .uuid .String (),
131
+ e .version ,
132
+ e .extensionConfig .API .Site ,
133
+ fullConfig ,
134
+ e .buildInfo ,
135
+ )
136
+
126
137
// send payloads to Datadog backend
127
138
_ , err := e .prepareAndSendFleetAutomationPayloads ()
128
139
if err != nil {
@@ -197,31 +208,36 @@ func getHostname(ctx context.Context, providedHostname string, sp source.Provide
197
208
func (e * fleetAutomationExtension ) updateHostname (ctx context.Context ) {
198
209
// check for new hostname in extension config
199
210
// TODO: switch to conf.Sub() method on refactor
200
- eCfg , err := e .collectorConfig .Sub (e .extensionID .String ())
211
+ extensionsConfig , err := e .collectorConfig .Sub (extensionsKind )
212
+ if err != nil || len (extensionsConfig .AllKeys ()) == 0 {
213
+ e .telemetry .Logger .Error ("Failed to get extensions config" )
214
+ return
215
+ }
216
+ eCfg , err := extensionsConfig .Sub (e .extensionID .String ())
201
217
if err != nil || len (eCfg .AllKeys ()) == 0 {
202
- e .telemetry .Logger .Error ("Failed to get extension config" , zap .Error (err ))
203
- } else {
204
- hostname := eCfg .Get ("hostname" )
205
- if hostname , ok := hostname .(string ); ok {
206
- if hostname != "" {
207
- if hostname != e .hostname {
208
- e .hostname = hostname
209
- e .hostnameSource = "config"
210
- }
211
- } else {
212
- e .telemetry .Logger .Info ("Hostname in config is empty, inferring hostname" )
213
- hn , source , err := getHostname (ctx , e .hostname , e .hostnameProvider )
214
- if err != nil {
215
- e .telemetry .Logger .Error ("Failed to infer hostname, collector will not show in Fleet Automation" , zap .Error (err ))
216
- e .hostname = ""
217
- e .hostnameSource = "unset"
218
- } else {
219
- e .hostname = hn
220
- e .telemetry .Logger .Info ("Inferred hostname" , zap .String ("hostname" , e .hostname ))
221
- e .hostnameSource = source
222
- }
218
+ e .telemetry .Logger .Error ("Failed to get datadogfleetautomationextension config" , zap .Error (err ))
219
+ return
220
+ }
221
+ hostname := eCfg .Get ("hostname" )
222
+ if hostname , ok := hostname .(string ); ok {
223
+ if hostname != "" {
224
+ if hostname != e .hostname {
225
+ e .hostname = hostname
223
226
}
227
+ e .hostnameSource = "config"
228
+ return
229
+ }
230
+ e .telemetry .Logger .Info ("Hostname in config is empty, inferring hostname" )
231
+ hn , source , err := getHostname (ctx , e .hostname , e .hostnameProvider )
232
+ if err != nil {
233
+ e .telemetry .Logger .Error ("Failed to infer hostname, collector will not show in Fleet Automation" , zap .Error (err ))
234
+ e .hostname = ""
235
+ e .hostnameSource = "unset"
236
+ return
224
237
}
238
+ e .hostname = hn
239
+ e .telemetry .Logger .Info ("Inferred hostname" , zap .String ("hostname" , e .hostname ))
240
+ e .hostnameSource = source
225
241
}
226
242
}
227
243
@@ -307,6 +323,11 @@ func newExtension(
307
323
compressor := newCompressor ()
308
324
serializer := newSerializer (forwarder , compressor , cfg , log , hostname )
309
325
version := settings .BuildInfo .Version
326
+ buildInfo := CustomBuildInfo {
327
+ Command : settings .BuildInfo .Command ,
328
+ Description : settings .BuildInfo .Description ,
329
+ Version : settings .BuildInfo .Version ,
330
+ }
310
331
return & fleetAutomationExtension {
311
332
extensionID : settings .ID ,
312
333
extensionConfig : config ,
@@ -315,7 +336,7 @@ func newExtension(
315
336
forwarder : forwarder ,
316
337
compressor : & compressor ,
317
338
serializer : serializer ,
318
- buildInfo : settings . BuildInfo ,
339
+ buildInfo : buildInfo ,
319
340
version : version ,
320
341
ticker : time .NewTicker (config .ReporterPeriod ),
321
342
done : make (chan bool ),
@@ -354,3 +375,24 @@ func prepareOtelMetadataPayload(version, extensionVersion, command, fullConfig s
354
375
FullConfiguration : fullConfig ,
355
376
}
356
377
}
378
+
379
+ func prepareOtelCollectorPayload (
380
+ hostname ,
381
+ hostnameSource ,
382
+ extensionUUID ,
383
+ version ,
384
+ site ,
385
+ fullConfig string ,
386
+ buildInfo CustomBuildInfo ) OtelCollector {
387
+ return OtelCollector {
388
+ HostKey : "" ,
389
+ Hostname : hostname ,
390
+ HostnameSource : hostnameSource ,
391
+ CollectorID : hostname + "-" + extensionUUID ,
392
+ CollectorVersion : version ,
393
+ ConfigSite : site ,
394
+ APIKeyUUID : "" ,
395
+ BuildInfo : buildInfo ,
396
+ FullConfiguration : fullConfig ,
397
+ }
398
+ }
0 commit comments