Skip to content

Commit

Permalink
discovery: update legacy name field when using container tags (#31574)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yumasi authored Nov 28, 2024
1 parent b5f2511 commit bd7c058
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
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.Name = service.Name
svc.meta.Name = service.Name
events.heartbeat = append(events.heartbeat, *svc)
}
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit bd7c058

Please sign in to comment.