Merge pull request #64 from weaveworks/fix-process-names

Fix deduplicated process names in Application topology
This commit is contained in:
Peter Bourgon
2015-05-20 10:29:50 +02:00
6 changed files with 14 additions and 12 deletions

View File

@@ -24,21 +24,22 @@ func TestAPITopologyApplications(t *testing.T) {
t.Fatalf("JSON parse error: %s", err)
}
equals(t, 4, len(topo.Nodes))
node, ok := topo.Nodes["proc:node-a.local:curl"]
node, ok := topo.Nodes["pid:node-a.local:23128"]
if !ok {
t.Errorf("missing curl node")
}
equals(t, report.NewIDList("proc:node-b.local:apache"), node.Adjacency)
equals(t, 1, len(node.Adjacency))
equals(t, report.NewIDList("pid:node-b.local:215"), node.Adjacency)
equals(t, report.NewIDList("hostA"), node.Origin)
equals(t, "curl", node.LabelMajor)
equals(t, "node-a.local", node.LabelMinor)
equals(t, "curl", node.Rank)
equals(t, "node-a.local (23128)", node.LabelMinor)
equals(t, "23128", node.Rank)
equals(t, false, node.Pseudo)
}
{
// Node detail
body := getRawJSON(t, ts, "/api/topology/applications/proc:node-a.local:curl")
body := getRawJSON(t, ts, "/api/topology/applications/pid:node-a.local:23128")
var node APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatalf("JSON parse error: %s", err)
@@ -48,7 +49,7 @@ func TestAPITopologyApplications(t *testing.T) {
{
// Edge detail
body := getRawJSON(t, ts, "/api/topology/applications/proc:node-a.local:curl/proc:node-b.local:apache")
body := getRawJSON(t, ts, "/api/topology/applications/pid:node-a.local:23128/pid:node-b.local:215")
var edge APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)

View File

@@ -47,6 +47,6 @@ var topologyRegistry = map[string]struct {
hasGrouped bool
typ string
}{
"applications": {"Applications", selectProcess, report.ProcessName, true, "Process"},
"applications": {"Applications", selectProcess, report.ProcessPID, true, "Process"},
"hosts": {"Hosts", selectNetwork, report.NetworkHostname, false, "Network"},
}

View File

@@ -26,13 +26,14 @@ type MappedNode struct {
type MapFunc func(string, NodeMetadata, bool) (MappedNode, bool)
// ProcessPID takes a node NodeMetadata from a Process topology, and returns a
// representation based on the process PID.
// representation with the ID based on the process PID and the labels based
// on the process name.
func ProcessPID(id string, m NodeMetadata, grouped bool) (MappedNode, bool) {
var (
domain = m["domain"]
pid = m["pid"]
name = m["name"]
minor = fmt.Sprintf("%s (%s)", domain, name)
minor = fmt.Sprintf("%s (%s)", domain, pid)
)
if grouped {
@@ -42,7 +43,7 @@ func ProcessPID(id string, m NodeMetadata, grouped bool) (MappedNode, bool) {
return MappedNode{
ID: fmt.Sprintf("pid:%s:%s", domain, pid),
Major: pid,
Major: name,
Minor: minor,
Rank: pid,
}, pid != ""

View File

@@ -73,8 +73,8 @@ func TestMapping(t *testing.T) {
},
wantOK: true,
wantID: "pid:hosta:42",
wantMajor: "42",
wantMinor: "hosta (curl)",
wantMajor: "curl",
wantMinor: "hosta (42)",
wantRank: "42",
},
{