From e5149aa7cd3e27d44426999893f5dd9415e8fdf8 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 21 Dec 2017 00:04:03 +0000 Subject: [PATCH] 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. --- render/detailed/summary.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/render/detailed/summary.go b/render/detailed/summary.go index ee00f2d59..2f9e10fd0 100644 --- a/render/detailed/summary.go +++ b/render/detailed/summary.go @@ -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 }