Skip to content

Commit

Permalink
Improve system process metricset test
Browse files Browse the repository at this point in the history
The system process test would often fail if it were executed on Linux outside of Docker (`make system-tests`). The `cwd` and `cgroup` fields would cause problems. `cwd` does not exist for kernel processes. And `cgroup` usually doesn't exist for all processes, plus `cgroup` can contain some dynamic fields like `system.process.cgroup.cpuacct.percpu.[1-N]`.
  • Loading branch information
andrewkroh authored and stevea78 committed May 20, 2018
1 parent 66239fa commit b32f92d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions metricbeat/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# is not available on all OSes and requires root to read for all processes.
# cgroup is only available on linux.
SYSTEM_PROCESS_FIELDS = ["cpu", "memory", "name", "pid", "ppid", "pgid",
"state", "username", "cgroup", "cwd"]
"state", "username"]


class Test(metricbeat.BaseTest):
Expand Down Expand Up @@ -366,12 +366,6 @@ def test_process(self):
"""
Test system/process output.
"""
if not sys.platform.startswith("linux") and "cgroup" in SYSTEM_PROCESS_FIELDS:
SYSTEM_PROCESS_FIELDS.remove("cgroup")

if not sys.platform.startswith("linux") and "cwd" in SYSTEM_PROCESS_FIELDS:
SYSTEM_PROCESS_FIELDS.remove("cwd")

self.render_config_template(modules=[{
"name": "system",
"metricsets": ["process"],
Expand All @@ -391,6 +385,7 @@ def test_process(self):
found_cmdline = False
found_env = False
found_fd = False
found_cwd = not sys.platform.startswith("linux")
for evt in output:
process = evt["system"]["process"]

Expand All @@ -399,15 +394,23 @@ def test_process(self):
if env is not None:
found_env = True

# Remove 'percpu' prior to checking documented fields because its keys are dynamic.
if "cgroup" in process and "cpuacct" in process["cgroup"]:
del process["cgroup"]["cpuacct"]["percpu"]

self.assert_fields_are_documented(evt)

# Remove optional keys.
process.pop("cgroup", None)
cmdline = process.pop("cmdline", None)
if cmdline is not None:
found_cmdline = True
fd = process.pop("fd", None)
if fd is not None:
found_fd = True
cwd = process.pop("cwd", None)
if cwd is not None:
found_cwd = True

self.assertItemsEqual(SYSTEM_PROCESS_FIELDS, process.keys())

Expand Down

0 comments on commit b32f92d

Please sign in to comment.