render sensible labels for processes with little/no metadata

We cope with the absence of the process name and/or container name,
and extract the hostID and pid from the node id rather than metadata
since that way we are guaranteed to get values for them.
This commit is contained in:
Matthias Radestock
2017-12-21 00:04:03 +00:00
parent ec589e08f6
commit e5149aa7cd

View File

@@ -203,19 +203,29 @@ func pseudoNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
}
func processNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
base.Label, _ = n.Latest.Lookup(process.Name)
base.Rank, _ = n.Latest.Lookup(process.Name)
pid, ok := n.Latest.Lookup(process.PID)
if !ok {
return NodeSummary{}, false
var (
hostID, pid, _ = report.ParseProcessNodeID(n.ID)
processName, _ = n.Latest.Lookup(process.Name)
containerName, _ = n.Latest.Lookup(docker.ContainerName)
)
switch {
case processName != "" && containerName != "":
base.Label = processName
base.LabelMinor = fmt.Sprintf("%s (%s:%s)", hostID, containerName, pid)
base.Rank = processName
case processName != "":
base.Label = processName
base.LabelMinor = fmt.Sprintf("%s (%s)", hostID, pid)
base.Rank = processName
case containerName != "":
base.Label = pid
base.LabelMinor = fmt.Sprintf("%s (%s)", hostID, containerName)
base.Rank = hostID
default:
base.Label = pid
base.LabelMinor = hostID
base.Rank = hostID
}
if containerName, ok := n.Latest.Lookup(docker.ContainerName); ok {
base.LabelMinor = fmt.Sprintf("%s (%s:%s)", report.ExtractHostID(n), containerName, pid)
} else {
base.LabelMinor = fmt.Sprintf("%s (%s)", report.ExtractHostID(n), pid)
}
base.Linkable = render.IsConnected(n)
return base, true
}