Skip to content

Commit

Permalink
add source tag name for container service name
Browse files Browse the repository at this point in the history
  • Loading branch information
Yumasi committed Dec 11, 2024
1 parent e7627c3 commit 3aaed1d
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 100 deletions.
2 changes: 2 additions & 0 deletions pkg/collector/corechecks/servicediscovery/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type eventPayload struct {
GeneratedServiceName string `json:"generated_service_name"`
GeneratedServiceNameSource string `json:"generated_service_name_source,omitempty"`
ContainerServiceName string `json:"container_service_name,omitempty"`
ContainerServiceNameSource string `json:"container_service_name_source,omitempty"`
DDService string `json:"dd_service,omitempty"`
HostName string `json:"host_name"`
Env string `json:"env"`
Expand Down Expand Up @@ -81,6 +82,7 @@ func (ts *telemetrySender) newEvent(t eventType, svc serviceInfo) *event {
GeneratedServiceName: svc.service.GeneratedName,
GeneratedServiceNameSource: svc.service.GeneratedNameSource,
ContainerServiceName: svc.service.ContainerServiceName,
ContainerServiceNameSource: svc.service.ContainerServiceNameSource,
DDService: svc.service.DDService,
HostName: host,
Env: env,
Expand Down
48 changes: 28 additions & 20 deletions pkg/collector/corechecks/servicediscovery/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ func Test_telemetrySender(t *testing.T) {

svc := serviceInfo{
service: model.Service{
PID: 99,
CommandLine: []string{"test-service", "--args"},
Ports: []uint16{80, 8080},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
RSS: 500 * 1024 * 1024,
GeneratedName: "generated-name",
GeneratedNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
DDService: "dd-service",
DDServiceInjected: true,
CPUCores: 1.5,
ContainerID: "abcd",
PID: 99,
CommandLine: []string{"test-service", "--args"},
Ports: []uint16{80, 8080},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
RSS: 500 * 1024 * 1024,
GeneratedName: "generated-name",
GeneratedNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
ContainerServiceNameSource: "service",
DDService: "dd-service",
DDServiceInjected: true,
CPUCores: 1.5,
ContainerID: "abcd",
},
meta: ServiceMetadata{
Name: "test-service",
Expand All @@ -92,6 +93,7 @@ func Test_telemetrySender(t *testing.T) {
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
ContainerServiceNameSource: "service",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand Down Expand Up @@ -119,6 +121,7 @@ func Test_telemetrySender(t *testing.T) {
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
ContainerServiceNameSource: "service",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand Down Expand Up @@ -146,6 +149,7 @@ func Test_telemetrySender(t *testing.T) {
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
ContainerServiceNameSource: "service",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand Down Expand Up @@ -192,14 +196,15 @@ func Test_telemetrySender_name_provided(t *testing.T) {

svc := serviceInfo{
service: model.Service{
PID: 55,
CommandLine: []string{"foo", "--option"},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
GeneratedName: "generated-name2",
GeneratedNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
DDService: "dd-service-provided",
ContainerID: "abcd",
PID: 55,
CommandLine: []string{"foo", "--option"},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
GeneratedName: "generated-name2",
GeneratedNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
ContainerServiceNameSource: "service",
DDService: "dd-service-provided",
ContainerID: "abcd",
},
meta: ServiceMetadata{
Name: "test-service",
Expand All @@ -224,6 +229,7 @@ func Test_telemetrySender_name_provided(t *testing.T) {
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
ContainerServiceNameSource: "service",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand All @@ -248,6 +254,7 @@ func Test_telemetrySender_name_provided(t *testing.T) {
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
ContainerServiceNameSource: "service",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand All @@ -272,6 +279,7 @@ func Test_telemetrySender_name_provided(t *testing.T) {
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
ContainerServiceNameSource: "service",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand Down
2 changes: 2 additions & 0 deletions pkg/collector/corechecks/servicediscovery/impl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (li *linuxImpl) DiscoverServices() (*discoveredServices, error) {
svc.service.ContainerID = service.ContainerID
svc.service.GeneratedName = service.GeneratedName
svc.service.ContainerServiceName = service.ContainerServiceName
svc.service.ContainerServiceNameSource = service.ContainerServiceNameSource
svc.service.Name = service.Name
svc.meta.Name = service.Name
events.heartbeat = append(events.heartbeat, *svc)
Expand Down Expand Up @@ -169,6 +170,7 @@ func (li *linuxImpl) handlePotentialServices(events *serviceEvents, now time.Tim
svc.service.ContainerID = service.ContainerID
svc.service.GeneratedName = service.GeneratedName
svc.service.ContainerServiceName = service.ContainerServiceName
svc.service.ContainerServiceNameSource = service.ContainerServiceNameSource
svc.service.Name = service.Name
svc.meta.Name = service.Name

Expand Down
135 changes: 76 additions & 59 deletions pkg/collector/corechecks/servicediscovery/impl_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,50 +71,53 @@ var (

var (
portTCP8080 = model.Service{
PID: procTestService1.pid,
Name: "test-service-1",
GeneratedName: "test-service-1-generated",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
DDService: "test-service-1",
DDServiceInjected: true,
Ports: []uint16{8080},
APMInstrumentation: string(apm.None),
RSS: 100 * 1024 * 1024,
CPUCores: 1.5,
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
PID: procTestService1.pid,
Name: "test-service-1",
GeneratedName: "test-service-1-generated",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
DDServiceInjected: true,
Ports: []uint16{8080},
APMInstrumentation: string(apm.None),
RSS: 100 * 1024 * 1024,
CPUCores: 1.5,
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
}
portTCP8080UpdatedRSS = model.Service{
PID: procTestService1.pid,
Name: "test-service-1",
GeneratedName: "test-service-1-generated",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
DDService: "test-service-1",
DDServiceInjected: true,
Ports: []uint16{8080},
APMInstrumentation: string(apm.None),
RSS: 200 * 1024 * 1024,
CPUCores: 1.5,
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
PID: procTestService1.pid,
Name: "test-service-1",
GeneratedName: "test-service-1-generated",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
DDServiceInjected: true,
Ports: []uint16{8080},
APMInstrumentation: string(apm.None),
RSS: 200 * 1024 * 1024,
CPUCores: 1.5,
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
}
portTCP8080DifferentPID = model.Service{
PID: procTestService1DifferentPID.pid,
Name: "test-service-1",
GeneratedName: "test-service-1-generated",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
DDService: "test-service-1",
DDServiceInjected: true,
Ports: []uint16{8080},
APMInstrumentation: string(apm.Injected),
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
PID: procTestService1DifferentPID.pid,
Name: "test-service-1",
GeneratedName: "test-service-1-generated",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
DDServiceInjected: true,
Ports: []uint16{8080},
APMInstrumentation: string(apm.Injected),
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
}
portTCP8081 = model.Service{
PID: procIgnoreService1.pid,
Expand All @@ -125,27 +128,29 @@ var (
ContainerID: dummyContainerID,
}
portTCP5000 = model.Service{
PID: procPythonService.pid,
Name: "python-service",
GeneratedName: "python-service",
GeneratedNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
Language: "python",
Ports: []uint16{5000},
CommandLine: pythonCommandLine,
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
PID: procPythonService.pid,
Name: "python-service",
GeneratedName: "python-service",
GeneratedNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "app",
Language: "python",
Ports: []uint16{5000},
CommandLine: pythonCommandLine,
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
}
portTCP5432 = model.Service{
PID: procTestService1Repeat.pid,
Name: "test-service-1",
GeneratedName: "test-service-1",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
Ports: []uint16{5432},
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
PID: procTestService1Repeat.pid,
Name: "test-service-1",
GeneratedName: "test-service-1",
GeneratedNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
Ports: []uint16{5432},
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
}
)

Expand Down Expand Up @@ -241,6 +246,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1-generated",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -267,6 +273,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1-generated",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -293,6 +300,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1-generated",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -319,6 +327,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "python-service",
GeneratedServiceNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "app",
ServiceType: "web_service",
HostName: host,
Env: "",
Expand All @@ -341,6 +350,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "python-service",
GeneratedServiceNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "app",
ServiceType: "web_service",
HostName: host,
Env: "",
Expand Down Expand Up @@ -400,6 +410,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -421,6 +432,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1-generated",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -447,6 +459,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -468,6 +481,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -489,6 +503,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1-generated",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand Down Expand Up @@ -550,6 +565,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1-generated",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -576,6 +592,7 @@ func Test_linuxImpl(t *testing.T) {
GeneratedServiceName: "test-service-1-generated",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand Down
Loading

0 comments on commit 3aaed1d

Please sign in to comment.