Skip to content

Commit

Permalink
discovery: put service name generated from container tags in a separa…
Browse files Browse the repository at this point in the history
…te field (#31951)

(cherry picked from commit 14eca6c)
  • Loading branch information
Yumasi authored and github-actions[bot] committed Dec 12, 2024
1 parent 0450ad4 commit 4e6427e
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 111 deletions.
4 changes: 4 additions & 0 deletions pkg/collector/corechecks/servicediscovery/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type eventPayload struct {
ServiceName string `json:"service_name"`
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 @@ -79,6 +81,8 @@ func (ts *telemetrySender) newEvent(t eventType, svc serviceInfo) *event {
ServiceName: svc.meta.Name,
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
52 changes: 34 additions & 18 deletions pkg/collector/corechecks/servicediscovery/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +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",
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 @@ -90,6 +92,8 @@ func Test_telemetrySender(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
ContainerServiceNameSource: "service",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand All @@ -116,6 +120,8 @@ func Test_telemetrySender(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
ContainerServiceNameSource: "service",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand All @@ -142,6 +148,8 @@ func Test_telemetrySender(t *testing.T) {
ServiceName: "test-service",
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 @@ -188,13 +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",
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 @@ -218,6 +228,8 @@ func Test_telemetrySender_name_provided(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
ContainerServiceNameSource: "service",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand All @@ -241,6 +253,8 @@ func Test_telemetrySender_name_provided(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
ContainerServiceNameSource: "service",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand All @@ -264,6 +278,8 @@ func Test_telemetrySender_name_provided(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
ContainerServiceNameSource: "service",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand Down
4 changes: 4 additions & 0 deletions pkg/collector/corechecks/servicediscovery/impl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func (li *linuxImpl) DiscoverServices() (*discoveredServices, error) {
svc.service.CPUCores = service.CPUCores
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 @@ -145,6 +147,8 @@ func (li *linuxImpl) handlePotentialServices(events *serviceEvents, now time.Tim
svc.service.CPUCores = service.CPUCores
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
142 changes: 88 additions & 54 deletions pkg/collector/corechecks/servicediscovery/impl_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,53 @@ var (

var (
portTCP8080 = model.Service{
PID: procTestService1.pid,
Name: "test-service-1",
GeneratedName: "test-service-1-generated",
GeneratedNameSource: "test-service-1-generated-source",
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",
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",
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 @@ -123,25 +129,29 @@ var (
ContainerID: dummyContainerID,
}
portTCP5000 = model.Service{
PID: procPythonService.pid,
Name: "python-service",
GeneratedName: "python-service",
GeneratedNameSource: "python-service-source",
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",
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 @@ -236,6 +246,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
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 @@ -261,6 +273,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
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 @@ -286,6 +300,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
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 @@ -311,6 +327,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "python-service",
GeneratedServiceName: "python-service",
GeneratedServiceNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "app",
ServiceType: "web_service",
HostName: host,
Env: "",
Expand All @@ -332,6 +350,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "python-service",
GeneratedServiceName: "python-service",
GeneratedServiceNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "app",
ServiceType: "web_service",
HostName: host,
Env: "",
Expand Down Expand Up @@ -390,6 +410,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
GeneratedServiceName: "test-service-1",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -410,6 +432,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
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 @@ -435,6 +459,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
GeneratedServiceName: "test-service-1",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -455,6 +481,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
GeneratedServiceName: "test-service-1",
GeneratedServiceNameSource: "test-service-1-generated-source",
ContainerServiceName: "test-service-1-container",
ContainerServiceNameSource: "service",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -475,6 +503,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
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 @@ -535,6 +565,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
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 @@ -560,6 +592,8 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "test-service-1",
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 4e6427e

Please sign in to comment.