From 2247234a190d607c84dbaed7dcb87f2865e4026f Mon Sep 17 00:00:00 2001 From: Guillaume Pagnoux Date: Thu, 28 Nov 2024 16:49:14 +0100 Subject: [PATCH 1/2] discovery: update legacy name field when using container tags --- pkg/collector/corechecks/servicediscovery/impl_linux.go | 4 ++++ .../corechecks/servicediscovery/module/impl_linux.go | 4 ++++ .../corechecks/servicediscovery/module/impl_linux_test.go | 1 + 3 files changed, 9 insertions(+) diff --git a/pkg/collector/corechecks/servicediscovery/impl_linux.go b/pkg/collector/corechecks/servicediscovery/impl_linux.go index c85e66d380a1a..c9d4e66bd0406 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.Name = service.Name + svc.meta.Name = service.Name events.heartbeat = append(events.heartbeat, *svc) } } @@ -143,6 +145,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.Name = service.Name + svc.meta.Name = service.Name li.aliveServices[pid] = svc events.start = append(events.start, *svc) diff --git a/pkg/collector/corechecks/servicediscovery/module/impl_linux.go b/pkg/collector/corechecks/servicediscovery/module/impl_linux.go index dd02e8a13c2f4..181c22b662aaa 100644 --- a/pkg/collector/corechecks/servicediscovery/module/impl_linux.go +++ b/pkg/collector/corechecks/servicediscovery/module/impl_linux.go @@ -685,6 +685,10 @@ func (s *discovery) enrichContainerData(service *model.Service, containers map[s if serviceName != "" { service.GeneratedName = serviceName + // Update the legacy name field as well + if service.DDService == "" { + service.Name = serviceName + } } service.CheckedContainerData = true diff --git a/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go b/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go index a8154ea1b7925..81c5bdb6a9f3a 100644 --- a/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go +++ b/pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go @@ -840,6 +840,7 @@ 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") } From 3866c313b6ec8a6e18db19cfb063f8321deeea61 Mon Sep 17 00:00:00 2001 From: Guillaume Pagnoux Date: Thu, 28 Nov 2024 17:59:40 +0100 Subject: [PATCH 2/2] test: add missing name field --- pkg/collector/corechecks/servicediscovery/impl_linux_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/collector/corechecks/servicediscovery/impl_linux_test.go b/pkg/collector/corechecks/servicediscovery/impl_linux_test.go index 07c7810d7230f..b2ae5d1d4f962 100644 --- a/pkg/collector/corechecks/servicediscovery/impl_linux_test.go +++ b/pkg/collector/corechecks/servicediscovery/impl_linux_test.go @@ -87,6 +87,7 @@ var ( } portTCP8080UpdatedRSS = model.Service{ PID: procTestService1.pid, + Name: "test-service-1", GeneratedName: "test-service-1-generated", DDService: "test-service-1", DDServiceInjected: true,