Skip to content

Commit

Permalink
probe: avoid reporting the container ID as its 'hostname'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bboreham committed Jan 27, 2020
1 parent 53297eb commit 24c40a6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions probe/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (c *container) PID() int {

func (c *container) Hostname() string {
if c.container.Config.Domainname == "" {
// 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.
if strings.HasPrefix(c.container.ID, c.container.Config.Hostname) {
return ""
}
return c.container.Config.Hostname
}

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

func (c *container) getBaseNode() report.Node {
result := report.MakeNodeWith(report.MakeContainerNodeID(c.ID()), map[string]string{
ContainerID: c.ID(),
ContainerCreated: c.container.Created.Format(time.RFC3339Nano),
ContainerCommand: c.getSanitizedCommand(),
ImageID: c.Image(),
ContainerHostname: c.Hostname(),
ContainerID: c.ID(),
ContainerCreated: c.container.Created.Format(time.RFC3339Nano),
ContainerCommand: c.getSanitizedCommand(),
ImageID: c.Image(),
}).WithParent(report.ContainerImage, report.MakeContainerImageNodeID(c.Image()))
if hostname := c.Hostname(); hostname != "" {
result = result.WithLatest(ContainerHostname, hostname)
}
result = result.AddPrefixPropertyList(LabelPrefix, c.container.Config.Labels)
if !c.noEnvironmentVariables {
result = result.AddPrefixPropertyList(EnvPrefix, c.env())
Expand Down

0 comments on commit 24c40a6

Please sign in to comment.