Skip to content

Commit

Permalink
Add field docs check to heartbeat (#7276)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin authored and jsoriano committed Jun 12, 2018
1 parent 4a41587 commit 5443c8a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 27 deletions.
12 changes: 0 additions & 12 deletions filebeat/tests/system/filebeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,3 @@ def get_registry_entry_by_path(self, path):
tmp_entry = entry

return tmp_entry

def assert_fields_are_documented(self, evt):
"""
Assert that all keys present in evt are documented in fields.yml.
This reads from the global fields.yml, means `make collect` has to be run before the check.
"""
expected_fields, dict_fields = self.load_fields()
flat = self.flatten_object(evt, dict_fields)

for key in flat.keys():
if key not in expected_fields:
raise Exception("Key '{}' found in event is not documented!".format(key))
2 changes: 2 additions & 0 deletions heartbeat/_meta/fields.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: "Common heartbeat monitor"
description:
fields:
- name: type
type: keyword
- name: monitor
type: group
description: >
Expand Down
16 changes: 16 additions & 0 deletions heartbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ Region in which this host is running.
None
*`type`*::
+
--
type: keyword
--
[float]
== monitor fields
Expand Down Expand Up @@ -573,6 +580,15 @@ Duration in microseconds
--
*`http.rtt.content.us`*::
+
--
type: long
Time required to retrieved the content in micro seconds.
--
[float]
== total fields
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/include/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions heartbeat/monitors/active/http/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
type: long
description: Duration in microseconds

- name: content.us
type: long
description:
Time required to retrieved the content in micro seconds.

- name: total
type: group
description: |
Expand Down
11 changes: 11 additions & 0 deletions heartbeat/tests/system/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import BaseHTTPServer
import threading
from parameterized import parameterized
import os
from nose.plugins.skip import SkipTest


class Test(BaseTest):
Expand Down Expand Up @@ -35,6 +37,11 @@ def test_http(self, status_code):
output = self.read_output()
assert status_code == output[0]["http.response.status_code"]

if os.name == "nt":
# Currently skipped on Windows as fields.yml not generated
raise SkipTest
self.assert_fields_are_documented(output[0])

@parameterized.expand([
("8181", "up"),
("8182", "down"),
Expand Down Expand Up @@ -63,6 +70,10 @@ def test_tcp(self, port, status):

output = self.read_output()
assert status == output[0]["monitor.status"]
if os.name == "nt":
# Currently skipped on Windows as fields.yml not generated
raise SkipTest
self.assert_fields_are_documented(output[0])

def start_server(self, content, status_code):
class HTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
Expand Down
14 changes: 14 additions & 0 deletions libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,17 @@ def get_kibana_url(self):
host=os.getenv("KIBANA_HOST", "localhost"),
port=os.getenv("KIBANA_PORT", "5601"),
)

def assert_fields_are_documented(self, evt):
"""
Assert that all keys present in evt are documented in fields.yml.
This reads from the global fields.yml, means `make collect` has to be run before the check.
"""
expected_fields, dict_fields = self.load_fields()
flat = self.flatten_object(evt, dict_fields)

for key in flat.keys():
documented = key in expected_fields
metaKey = key.startswith('@metadata.')
if not(documented or metaKey):
raise Exception("Key '{}' found in event is not documented!".format(key))
14 changes: 0 additions & 14 deletions metricbeat/tests/system/metricbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ def setUpClass(self):
self.beat_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
super(BaseTest, self).setUpClass()

def assert_fields_are_documented(self, evt):
"""
Assert that all keys present in evt are documented in fields.yml.
This reads from the global fields.yml, means `make collect` has to be run before the check.
"""
expected_fields, _ = self.load_fields()
flat = self.flatten_object(evt, [])

for key in flat.keys():
documented = key in expected_fields
metaKey = key.startswith('@metadata.')
if not(documented or metaKey):
raise Exception("Key '{}' found in event is not documented!".format(key))

def de_dot(self, existing_fields):
fields = {}

Expand Down

0 comments on commit 5443c8a

Please sign in to comment.