Skip to content

Commit 24c40a6

Browse files
committed
probe: avoid reporting the container ID as its 'hostname'
If hostname isn't set on a container it defaults to a random hex number which we don't want to show in the UI.
1 parent 53297eb commit 24c40a6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

probe/docker/container.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func (c *container) PID() int {
108108

109109
func (c *container) Hostname() string {
110110
if c.container.Config.Domainname == "" {
111+
// If hostname isn't set on a container it defaults to a random hex
112+
// number which we don't want to show in the UI.
113+
if strings.HasPrefix(c.container.ID, c.container.Config.Hostname) {
114+
return ""
115+
}
111116
return c.container.Config.Hostname
112117
}
113118

@@ -376,12 +381,14 @@ func (c *container) getSanitizedCommand() string {
376381

377382
func (c *container) getBaseNode() report.Node {
378383
result := report.MakeNodeWith(report.MakeContainerNodeID(c.ID()), map[string]string{
379-
ContainerID: c.ID(),
380-
ContainerCreated: c.container.Created.Format(time.RFC3339Nano),
381-
ContainerCommand: c.getSanitizedCommand(),
382-
ImageID: c.Image(),
383-
ContainerHostname: c.Hostname(),
384+
ContainerID: c.ID(),
385+
ContainerCreated: c.container.Created.Format(time.RFC3339Nano),
386+
ContainerCommand: c.getSanitizedCommand(),
387+
ImageID: c.Image(),
384388
}).WithParent(report.ContainerImage, report.MakeContainerImageNodeID(c.Image()))
389+
if hostname := c.Hostname(); hostname != "" {
390+
result = result.WithLatest(ContainerHostname, hostname)
391+
}
385392
result = result.AddPrefixPropertyList(LabelPrefix, c.container.Config.Labels)
386393
if !c.noEnvironmentVariables {
387394
result = result.AddPrefixPropertyList(EnvPrefix, c.env())

0 commit comments

Comments
 (0)