Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discovery: put service name generated from container tags in a separate field #31951

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/collector/corechecks/servicediscovery/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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"`
Yumasi marked this conversation as resolved.
Show resolved Hide resolved
Yumasi marked this conversation as resolved.
Show resolved Hide resolved
DDService string `json:"dd_service,omitempty"`
HostName string `json:"host_name"`
Env string `json:"env"`
Expand Down Expand Up @@ -79,6 +80,7 @@ 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,
DDService: svc.service.DDService,
HostName: host,
Env: env,
Expand Down
44 changes: 26 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,18 @@ 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",
DDService: "dd-service",
DDServiceInjected: true,
CPUCores: 1.5,
ContainerID: "abcd",
},
meta: ServiceMetadata{
Name: "test-service",
Expand All @@ -90,6 +91,7 @@ func Test_telemetrySender(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand All @@ -116,6 +118,7 @@ func Test_telemetrySender(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand All @@ -142,6 +145,7 @@ func Test_telemetrySender(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
ContainerServiceName: "container-service-name",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Expand Down Expand Up @@ -188,13 +192,14 @@ 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",
DDService: "dd-service-provided",
ContainerID: "abcd",
},
meta: ServiceMetadata{
Name: "test-service",
Expand All @@ -218,6 +223,7 @@ func Test_telemetrySender_name_provided(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand All @@ -241,6 +247,7 @@ func Test_telemetrySender_name_provided(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Expand All @@ -264,6 +271,7 @@ func Test_telemetrySender_name_provided(t *testing.T) {
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
ContainerServiceName: "container-service-name2",
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 @@ -128,6 +128,7 @@ 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.Name = service.Name
svc.meta.Name = service.Name
events.heartbeat = append(events.heartbeat, *svc)
Expand Down Expand Up @@ -167,6 +168,7 @@ 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.Name = service.Name
svc.meta.Name = service.Name

Expand Down
125 changes: 71 additions & 54 deletions pkg/collector/corechecks/servicediscovery/impl_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,47 +71,50 @@ 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",
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",
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",
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 @@ -122,25 +125,27 @@ 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",
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",
Ports: []uint16{5432},
CommandLine: []string{"test-service-1"},
StartTimeMilli: procLaunchedMilli,
ContainerID: dummyContainerID,
}
)

Expand Down Expand Up @@ -235,6 +240,7 @@ 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",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -260,6 +266,7 @@ 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",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -285,6 +292,7 @@ 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",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -310,6 +318,7 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "python-service",
GeneratedServiceName: "python-service",
GeneratedServiceNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
ServiceType: "web_service",
HostName: host,
Env: "",
Expand All @@ -331,6 +340,7 @@ func Test_linuxImpl(t *testing.T) {
ServiceName: "python-service",
GeneratedServiceName: "python-service",
GeneratedServiceNameSource: "python-service-source",
ContainerServiceName: "test-service-1-container",
ServiceType: "web_service",
HostName: host,
Env: "",
Expand Down Expand Up @@ -389,6 +399,7 @@ 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",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -409,6 +420,7 @@ 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",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -434,6 +446,7 @@ 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",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -454,6 +467,7 @@ 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",
ServiceType: "db",
HostName: host,
Env: "",
Expand All @@ -474,6 +488,7 @@ 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",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand Down Expand Up @@ -534,6 +549,7 @@ 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",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand All @@ -559,6 +575,7 @@ 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",
DDService: "test-service-1",
ServiceNameSource: "injected",
ServiceType: "web_service",
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/corechecks/servicediscovery/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Service struct {
Name string `json:"name"`
GeneratedName string `json:"generated_name"`
GeneratedNameSource string `json:"generated_name_source"`
ContainerServiceName string `json:"container_service_name"`
DDService string `json:"dd_service"`
DDServiceInjected bool `json:"dd_service_injected"`
CheckedContainerData bool `json:"checked_container_data"`
Expand Down
Loading
Loading