Skip to content

Commit a11e4ec

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 a11e4ec

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Diff for: probe/docker/container.go

+15-7
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

@@ -375,13 +380,16 @@ func (c *container) getSanitizedCommand() string {
375380
}
376381

377382
func (c *container) getBaseNode() report.Node {
378-
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-
}).WithParent(report.ContainerImage, report.MakeContainerImageNodeID(c.Image()))
383+
properties := map[string]string{
384+
ContainerID: c.ID(),
385+
ContainerCreated: c.container.Created.Format(time.RFC3339Nano),
386+
ContainerCommand: c.getSanitizedCommand(),
387+
ImageID: c.Image(),
388+
}
389+
if hostname := c.Hostname(); hostname != "" {
390+
properties[ContainerHostname] = hostname
391+
}
392+
result := report.MakeNodeWith(report.MakeContainerNodeID(c.ID()), properties).WithParent(report.ContainerImage, report.MakeContainerImageNodeID(c.Image()))
385393
result = result.AddPrefixPropertyList(LabelPrefix, c.container.Config.Labels)
386394
if !c.noEnvironmentVariables {
387395
result = result.AddPrefixPropertyList(EnvPrefix, c.env())

0 commit comments

Comments
 (0)