From bdd886a28f40472c3a73d455d4bd1a84a028971d Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Wed, 19 Aug 2015 15:54:11 +0000 Subject: [PATCH] Don't report empty fields from process --- probe/process/reporter.go | 17 +++++++++++------ probe/process/reporter_test.go | 10 +++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/probe/process/reporter.go b/probe/process/reporter.go index 6ab7db82f..dd595cbc2 100644 --- a/probe/process/reporter.go +++ b/probe/process/reporter.go @@ -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) } diff --git a/probe/process/reporter_test.go b/probe/process/reporter_test.go index 2780d7ff0..1e4bf4858 100644 --- a/probe/process/reporter_test.go +++ b/probe/process/reporter_test.go @@ -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", + }), }, }