mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-06 09:18:27 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user