Skip to content

Commit 3be6fcc

Browse files
[Process] Attach discovered log file paths to services (#43515)
### What does this PR do? This [PR](https://datadoghq.atlassian.net/browse/DSCVR-236) populates the ServiceDiscovery.resources protobuf field with log file information collected during service discovery. The field was introduced in agent-payload v5.0.176 ([PR](DataDog/agent-payload#426)), which was added to the Agent in the corresponding payload [bump](#43442). The change adds the required data structures and mapping logic to propagate log file paths from workloadmeta → procutil → process check → protobuf payload, representing each entry as a Resource containing a LogResource. This enables better log collection automation and log–service correlation on the backend. In the future, we may want to enrich these log resources with additional metadata (e.g., log size, write rate, or other attributes) depending on upcoming use cases. More details are available in the referenced [RFC](https://datadoghq.atlassian.net/wiki/spaces/DSCVR/pages/5580787035/Processes+have+logs+attached). ### Motivation https://datadoghq.atlassian.net/browse/DSCVR-236 ### Describe how you validated your changes. Added unit tests covering normal cases and edge cases for log file propagation. [DSCVR-236]: https://datadoghq.atlassian.net/browse/DSCVR-236?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: marta.vicentenavarro <marta.vicentenavarro@datadoghq.com>
1 parent 413fc04 commit 3be6fcc

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

pkg/process/checks/process_linux.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func mapWLMProcToProc(wlmProc *workloadmetacomp.Process, stats *procutil.Stats)
9999
TracerMetadata: wlmProc.Service.TracerMetadata,
100100
DDService: wlmProc.Service.UST.Service,
101101
APMInstrumentation: wlmProc.Service.APMInstrumentation,
102+
LogFiles: wlmProc.Service.LogFiles,
102103
}
103104
tcpPorts = wlmProc.Service.TCPPorts
104105
udpPorts = wlmProc.Service.UDPPorts
@@ -230,11 +231,23 @@ func formatServiceDiscovery(service *procutil.Service) *model.ServiceDiscovery {
230231
})
231232
}
232233

234+
var resources []*model.Resource
235+
for _, logPath := range service.LogFiles {
236+
resources = append(resources, &model.Resource{
237+
Resource: &model.Resource_Logs{
238+
Logs: &model.LogResource{
239+
Path: logPath,
240+
},
241+
},
242+
})
243+
}
244+
233245
return &model.ServiceDiscovery{
234246
GeneratedServiceName: generatedServiceName,
235247
DdServiceName: ddServiceName,
236248
AdditionalGeneratedNames: additionalGeneratedNames,
237249
TracerMetadata: tracerMetadata,
238250
ApmInstrumentation: service.APMInstrumentation,
251+
Resources: resources,
239252
}
240253
}

pkg/process/checks/process_linux_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ func TestFormatServiceDiscovery(t *testing.T) {
365365
},
366366
DDService: "dd_service_name",
367367
APMInstrumentation: true,
368+
LogFiles: []string{"/var/log/app.log", "/var/log/error.log"},
368369
},
369370
expectedService: &model.ServiceDiscovery{
370371
GeneratedServiceName: &model.ServiceName{
@@ -396,6 +397,22 @@ func TestFormatServiceDiscovery(t *testing.T) {
396397
},
397398
},
398399
ApmInstrumentation: true,
400+
Resources: []*model.Resource{
401+
{
402+
Resource: &model.Resource_Logs{
403+
Logs: &model.LogResource{
404+
Path: "/var/log/app.log",
405+
},
406+
},
407+
},
408+
{
409+
Resource: &model.Resource_Logs{
410+
Logs: &model.LogResource{
411+
Path: "/var/log/error.log",
412+
},
413+
},
414+
},
415+
},
399416
},
400417
},
401418
{
@@ -419,6 +436,87 @@ func TestFormatServiceDiscovery(t *testing.T) {
419436
service: &procutil.Service{},
420437
expectedService: &model.ServiceDiscovery{},
421438
},
439+
{
440+
description: "service with log files only",
441+
service: &procutil.Service{
442+
LogFiles: []string{"/var/log/nginx/access.log", "/var/log/nginx/error.log", "/var/log/app/application.log"},
443+
},
444+
expectedService: &model.ServiceDiscovery{
445+
Resources: []*model.Resource{
446+
{
447+
Resource: &model.Resource_Logs{
448+
Logs: &model.LogResource{
449+
Path: "/var/log/nginx/access.log",
450+
},
451+
},
452+
},
453+
{
454+
Resource: &model.Resource_Logs{
455+
Logs: &model.LogResource{
456+
Path: "/var/log/nginx/error.log",
457+
},
458+
},
459+
},
460+
{
461+
Resource: &model.Resource_Logs{
462+
Logs: &model.LogResource{
463+
Path: "/var/log/app/application.log",
464+
},
465+
},
466+
},
467+
},
468+
},
469+
},
470+
{
471+
description: "service with single log file",
472+
service: &procutil.Service{
473+
GeneratedName: "my-service",
474+
LogFiles: []string{"/var/log/service.log"},
475+
},
476+
expectedService: &model.ServiceDiscovery{
477+
GeneratedServiceName: &model.ServiceName{
478+
Name: "my-service",
479+
Source: model.ServiceNameSource_SERVICE_NAME_SOURCE_UNKNOWN,
480+
},
481+
Resources: []*model.Resource{
482+
{
483+
Resource: &model.Resource_Logs{
484+
Logs: &model.LogResource{
485+
Path: "/var/log/service.log",
486+
},
487+
},
488+
},
489+
},
490+
},
491+
},
492+
{
493+
description: "service with nil log files",
494+
service: &procutil.Service{
495+
GeneratedName: "my-service",
496+
LogFiles: nil,
497+
},
498+
expectedService: &model.ServiceDiscovery{
499+
GeneratedServiceName: &model.ServiceName{
500+
Name: "my-service",
501+
Source: model.ServiceNameSource_SERVICE_NAME_SOURCE_UNKNOWN,
502+
},
503+
Resources: nil,
504+
},
505+
},
506+
{
507+
description: "service with empty log files slice",
508+
service: &procutil.Service{
509+
GeneratedName: "my-service",
510+
LogFiles: []string{},
511+
},
512+
expectedService: &model.ServiceDiscovery{
513+
GeneratedServiceName: &model.ServiceName{
514+
Name: "my-service",
515+
Source: model.ServiceNameSource_SERVICE_NAME_SOURCE_UNKNOWN,
516+
},
517+
Resources: nil,
518+
},
519+
},
422520
{
423521
description: "service not collected",
424522
service: nil,

pkg/process/procutil/process_model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ type Service struct {
151151

152152
// APMInstrumentation indicates the APM instrumentation status
153153
APMInstrumentation bool
154+
155+
// LogFiles contains paths to log files associated with this service
156+
LogFiles []string
154157
}
155158

156159
// DeepCopy creates a deep copy of Stats

0 commit comments

Comments
 (0)