Skip to content

Commit

Permalink
discovery: update legacy name field when using container tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Yumasi committed Nov 28, 2024
1 parent 7bf22e7 commit d4bb079
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 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,7 @@ 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
events.heartbeat = append(events.heartbeat, *svc)
}
}
Expand Down Expand Up @@ -143,6 +144,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 @@ -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 d4bb079

Please sign in to comment.