Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

probe: avoid reporting the container ID as its hostname #3746

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 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.
bboreham marked this conversation as resolved.
Show resolved Hide resolved
if strings.HasPrefix(c.container.ID, c.container.Config.Hostname) {
return ""
}
return c.container.Config.Hostname
}

Expand Down Expand Up @@ -375,13 +380,16 @@ 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(),
}).WithParent(report.ContainerImage, report.MakeContainerImageNodeID(c.Image()))
properties := map[string]string{
ContainerID: c.ID(),
ContainerCreated: c.container.Created.Format(time.RFC3339Nano),
ContainerCommand: c.getSanitizedCommand(),
ImageID: c.Image(),
}
if hostname := c.Hostname(); hostname != "" {
properties[ContainerHostname] = hostname
}
result := report.MakeNodeWith(report.MakeContainerNodeID(c.ID()), properties).WithParent(report.ContainerImage, report.MakeContainerImageNodeID(c.Image()))
result = result.AddPrefixPropertyList(LabelPrefix, c.container.Config.Labels)
if !c.noEnvironmentVariables {
result = result.AddPrefixPropertyList(EnvPrefix, c.env())
Expand Down