From 4e6427e8fbaf8265c00a07be5bfe55ff8831c024 Mon Sep 17 00:00:00 2001 From: Guillaume Pagnoux Date: Wed, 11 Dec 2024 18:48:34 +0100 Subject: [PATCH] discovery: put service name generated from container tags in a separate field (#31951) (cherry picked from commit 14eca6c8f963050fdd58e759a8bb78404fe884d4) --- .../corechecks/servicediscovery/events.go | 4 + .../servicediscovery/events_test.go | 52 ++++--- .../corechecks/servicediscovery/impl_linux.go | 4 + .../servicediscovery/impl_linux_test.go | 142 +++++++++++------- .../servicediscovery/model/model.go | 32 ++-- .../servicediscovery/module/impl_linux.go | 27 ++-- .../module/impl_linux_test.go | 26 +++- .../servicediscovery/usm/service.go | 2 - 8 files changed, 178 insertions(+), 111 deletions(-) diff --git a/pkg/collector/corechecks/servicediscovery/events.go b/pkg/collector/corechecks/servicediscovery/events.go index fba57253ad552..f1d040dacefcb 100644 --- a/pkg/collector/corechecks/servicediscovery/events.go +++ b/pkg/collector/corechecks/servicediscovery/events.go @@ -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"` @@ -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, diff --git a/pkg/collector/corechecks/servicediscovery/events_test.go b/pkg/collector/corechecks/servicediscovery/events_test.go index f8b7fc92bcfb3..b38dc5ddf084f 100644 --- a/pkg/collector/corechecks/servicediscovery/events_test.go +++ b/pkg/collector/corechecks/servicediscovery/events_test.go @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/pkg/collector/corechecks/servicediscovery/impl_linux.go b/pkg/collector/corechecks/servicediscovery/impl_linux.go index c9d4e66bd0406..376b4a0855868 100644 --- a/pkg/collector/corechecks/servicediscovery/impl_linux.go +++ b/pkg/collector/corechecks/servicediscovery/impl_linux.go @@ -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) @@ -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 diff --git a/pkg/collector/corechecks/servicediscovery/impl_linux_test.go b/pkg/collector/corechecks/servicediscovery/impl_linux_test.go index f3f7d4baaeb66..2d0cb277e2028 100644 --- a/pkg/collector/corechecks/servicediscovery/impl_linux_test.go +++ b/pkg/collector/corechecks/servicediscovery/impl_linux_test.go @@ -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, @@ -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, } ) @@ -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", @@ -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", @@ -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", @@ -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: "", @@ -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: "", @@ -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: "", @@ -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", @@ -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: "", @@ -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: "", @@ -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", @@ -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", @@ -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", diff --git a/pkg/collector/corechecks/servicediscovery/model/model.go b/pkg/collector/corechecks/servicediscovery/model/model.go index ccaa3fc2a961c..9a99681fe6cfc 100644 --- a/pkg/collector/corechecks/servicediscovery/model/model.go +++ b/pkg/collector/corechecks/servicediscovery/model/model.go @@ -8,21 +8,23 @@ package model // Service represents a listening process. type Service struct { - PID int `json:"pid"` - Name string `json:"name"` - GeneratedName string `json:"generated_name"` - GeneratedNameSource string `json:"generated_name_source"` - DDService string `json:"dd_service"` - DDServiceInjected bool `json:"dd_service_injected"` - CheckedContainerData bool `json:"checked_container_data"` - Ports []uint16 `json:"ports"` - APMInstrumentation string `json:"apm_instrumentation"` - Language string `json:"language"` - RSS uint64 `json:"rss"` - CommandLine []string `json:"cmdline"` - StartTimeMilli uint64 `json:"start_time"` - CPUCores float64 `json:"cpu_cores"` - ContainerID string `json:"container_id"` + PID int `json:"pid"` + Name string `json:"name"` + GeneratedName string `json:"generated_name"` + GeneratedNameSource string `json:"generated_name_source"` + ContainerServiceName string `json:"container_service_name"` + ContainerServiceNameSource string `json:"container_service_name_source"` + DDService string `json:"dd_service"` + DDServiceInjected bool `json:"dd_service_injected"` + CheckedContainerData bool `json:"checked_container_data"` + Ports []uint16 `json:"ports"` + APMInstrumentation string `json:"apm_instrumentation"` + Language string `json:"language"` + RSS uint64 `json:"rss"` + CommandLine []string `json:"cmdline"` + StartTimeMilli uint64 `json:"start_time"` + CPUCores float64 `json:"cpu_cores"` + ContainerID string `json:"container_id"` } // ServicesResponse is the response for the system-probe /discovery/services endpoint. diff --git a/pkg/collector/corechecks/servicediscovery/module/impl_linux.go b/pkg/collector/corechecks/servicediscovery/module/impl_linux.go index d92bb8c0c807b..d296df2c8fd1d 100644 --- a/pkg/collector/corechecks/servicediscovery/module/impl_linux.go +++ b/pkg/collector/corechecks/servicediscovery/module/impl_linux.go @@ -51,6 +51,7 @@ var _ module.Module = &discovery{} type serviceInfo struct { generatedName string generatedNameSource string + containerServiceName string ddServiceName string ddServiceInjected bool checkedContainerData bool @@ -600,7 +601,7 @@ func (s *discovery) updateServicesCPUStats(services []model.Service) error { return nil } -func getServiceNameFromContainerTags(tags []string) string { +func getServiceNameFromContainerTags(tags []string) (string, string) { // The tags we look for service name generation, in their priority order. // The map entries will be filled as we go through the containers tags. tagsPriority := []struct { @@ -641,10 +642,10 @@ func getServiceNameFromContainerTags(tags []string) string { } log.Debugf("Using %v:%v tag for service name", tag.tagName, *tag.tagValue) - return *tag.tagValue + return tag.tagName, *tag.tagValue } - return "" + return "", "" } func (s *discovery) enrichContainerData(service *model.Service, containers map[string]*agentPayload.Container, pidToCid map[int]string) { @@ -655,7 +656,7 @@ func (s *discovery) enrichContainerData(service *model.Service, containers map[s service.ContainerID = id - // We got the service name from container tags before, no need to do it again. + // We checked the container tags before, no need to do it again. if service.CheckedContainerData { return } @@ -665,25 +666,15 @@ func (s *discovery) enrichContainerData(service *model.Service, containers map[s return } - serviceName := getServiceNameFromContainerTags(container.Tags) - - if serviceName != "" { - service.GeneratedName = serviceName - // Update the legacy name field as well - if service.DDService == "" { - service.Name = serviceName - } - service.GeneratedNameSource = string(usm.Container) - } + tagName, serviceName := getServiceNameFromContainerTags(container.Tags) + service.ContainerServiceName = serviceName + service.ContainerServiceNameSource = tagName service.CheckedContainerData = true s.mux.Lock() serviceInfo, ok := s.cache[int32(service.PID)] if ok { - if serviceName != "" { - serviceInfo.generatedName = serviceName - serviceInfo.generatedNameSource = string(usm.Container) - } + serviceInfo.containerServiceName = serviceName serviceInfo.checkedContainerData = true } s.mux.Unlock() diff --git a/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go b/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go index bdef0ee75b5db..37c28b1cb3b5d 100644 --- a/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go +++ b/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go @@ -844,9 +844,11 @@ func TestDocker(t *testing.T) { require.Contains(t, portMap, pid1111) require.Contains(t, portMap[pid1111].Ports, uint16(1234)) require.Contains(t, portMap[pid1111].ContainerID, "dummyCID") - require.Contains(t, portMap[pid1111].Name, "foo_from_app_tag") - require.Contains(t, portMap[pid1111].GeneratedName, "foo_from_app_tag") - require.Contains(t, portMap[pid1111].GeneratedNameSource, string(usm.Container)) + require.Contains(t, portMap[pid1111].Name, "http.server") + require.Contains(t, portMap[pid1111].GeneratedName, "http.server") + require.Contains(t, portMap[pid1111].GeneratedNameSource, string(usm.CommandLine)) + require.Contains(t, portMap[pid1111].ContainerServiceName, "foo_from_app_tag") + require.Contains(t, portMap[pid1111].ContainerServiceNameSource, "app") } // Check that the cache is cleaned when procceses die. @@ -919,56 +921,67 @@ func TestTagsPriority(t *testing.T) { cases := []struct { name string tags []string + expectedTagName string expectedServiceName string }{ { "nil tag list", nil, "", + "", }, { "empty tag list", []string{}, "", + "", }, { "no useful tags", []string{"foo:bar"}, "", + "", }, { "malformed tag", []string{"foobar"}, "", + "", }, { "service tag", []string{"service:foo"}, + "service", "foo", }, { "app tag", []string{"app:foo"}, + "app", "foo", }, { "short_image tag", []string{"short_image:foo"}, + "short_image", "foo", }, { "kube_container_name tag", []string{"kube_container_name:foo"}, + "kube_container_name", "foo", }, { "kube_deployment tag", []string{"kube_deployment:foo"}, + "kube_deployment", "foo", }, { "kube_service tag", []string{"kube_service:foo"}, + "kube_service", "foo", }, { @@ -979,6 +992,7 @@ func TestTagsPriority(t *testing.T) { "service:my_service", "malformed", }, + "service", "my_service", }, { @@ -987,6 +1001,7 @@ func TestTagsPriority(t *testing.T) { "service:", "app:foo", }, + "app", "foo", }, { @@ -998,6 +1013,7 @@ func TestTagsPriority(t *testing.T) { "service:my_service", "malformed", }, + "service", "my_service", }, { @@ -1010,14 +1026,16 @@ func TestTagsPriority(t *testing.T) { "app:my_app", "service:my_service", }, + "service", "my_service", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { - name := getServiceNameFromContainerTags(c.tags) + tagName, name := getServiceNameFromContainerTags(c.tags) require.Equalf(t, c.expectedServiceName, name, "got wrong service name from container tags") + require.Equalf(t, c.expectedTagName, tagName, "got wrong tag name for service naming") }) } } diff --git a/pkg/collector/corechecks/servicediscovery/usm/service.go b/pkg/collector/corechecks/servicediscovery/usm/service.go index 407b77179dfb7..89bfd3cfb6003 100644 --- a/pkg/collector/corechecks/servicediscovery/usm/service.go +++ b/pkg/collector/corechecks/servicediscovery/usm/service.go @@ -64,8 +64,6 @@ type ServiceNameSource string const ( // CommandLine indicates that the name comes from the command line CommandLine ServiceNameSource = "command-line" - // Container indicates the name comes from the container tags - Container ServiceNameSource = "container" // Laravel indicates that the name comes from the Laravel application name Laravel ServiceNameSource = "laravel" // Python indicates that the name comes from the Python package name