Merge pull request #376 from weaveworks/no-empty-proc-rows

Don't report empty fields from process
This commit is contained in:
Alfonso Acosta
2015-08-19 18:39:05 +01:00
2 changed files with 18 additions and 9 deletions

View File

@@ -45,12 +45,17 @@ func (r *Reporter) processTopology() (report.Topology, error) {
err := r.walker.Walk(func(p Process) {
pidstr := strconv.Itoa(p.PID)
nodeID := report.MakeProcessNodeID(r.scope, pidstr)
t.NodeMetadatas[nodeID] = report.MakeNodeMetadataWith(map[string]string{
PID: pidstr,
Comm: p.Comm,
Cmdline: p.Cmdline,
Threads: strconv.Itoa(p.Threads),
})
t.NodeMetadatas[nodeID] = report.MakeNodeMetadata()
for _, tuple := range []struct{ key, value string }{
{PID, pidstr},
{Comm, p.Comm},
{Cmdline, p.Cmdline},
{Threads, strconv.Itoa(p.Threads)},
} {
if tuple.value != "" {
t.NodeMetadatas[nodeID].Metadata[tuple.key] = tuple.value
}
}
if p.PPID > 0 {
t.NodeMetadatas[nodeID].Metadata[PPID] = strconv.Itoa(p.PPID)
}

View File

@@ -27,6 +27,7 @@ func TestReporter(t *testing.T) {
{PID: 2, PPID: 1, Comm: "bash"},
{PID: 3, PPID: 1, Comm: "apache", Threads: 2},
{PID: 4, PPID: 2, Comm: "ping", Cmdline: "ping foo.bar.local"},
{PID: 5, PPID: 1, Cmdline: "tail -f /var/log/syslog"},
},
}
@@ -39,21 +40,18 @@ func TestReporter(t *testing.T) {
report.MakeProcessNodeID("", "1"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "1",
process.Comm: "init",
process.Cmdline: "",
process.Threads: "0",
}),
report.MakeProcessNodeID("", "2"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "2",
process.Comm: "bash",
process.PPID: "1",
process.Cmdline: "",
process.Threads: "0",
}),
report.MakeProcessNodeID("", "3"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "3",
process.Comm: "apache",
process.PPID: "1",
process.Cmdline: "",
process.Threads: "2",
}),
report.MakeProcessNodeID("", "4"): report.MakeNodeMetadataWith(map[string]string{
@@ -63,6 +61,12 @@ func TestReporter(t *testing.T) {
process.Cmdline: "ping foo.bar.local",
process.Threads: "0",
}),
report.MakeProcessNodeID("", "5"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "5",
process.PPID: "1",
process.Cmdline: "tail -f /var/log/syslog",
process.Threads: "0",
}),
},
}