Skip to content

Commit

Permalink
Check field mapping with wildcards (#7941)
Browse files Browse the repository at this point in the history
System tests that check field mapping fail with correct fields that are
defined as dynamic fields with wildcards.
  • Loading branch information
jsoriano authored and ruflin committed Aug 13, 2018
1 parent 2df792e commit 606bd1d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
23 changes: 21 additions & 2 deletions libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,27 @@ def assert_fields_are_documented(self, evt):
expected_fields, dict_fields = self.load_fields()
flat = self.flatten_object(evt, dict_fields)

def field_pattern_match(pattern, key):
pattern_fields = pattern.split(".")
key_fields = key.split(".")
if len(pattern_fields) != len(key_fields):
return False
for i in range(len(pattern_fields)):
if pattern_fields[i] == "*":
continue
if pattern_fields[i] != key_fields[i]:
return False
return True

def is_documented(key):
if key in expected_fields:
return True
for pattern in (f for f in expected_fields if "*" in f):
if field_pattern_match(pattern, key):
return True
return False

for key in flat.keys():
documented = key in expected_fields
metaKey = key.startswith('@metadata.')
if not(documented or metaKey):
if not(is_documented(key) or metaKey):
raise Exception("Key '{}' found in event is not documented!".format(key))
2 changes: 1 addition & 1 deletion metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19647,7 +19647,7 @@ Average response time in microseconds
--
*`traefik.health.response.status_code`*::
*`traefik.health.response.status_codes.*`*::
+
--
type: object
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/traefik/fields.go

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

2 changes: 1 addition & 1 deletion metricbeat/module/traefik/health/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
type: long
description: >
Average response time in microseconds
- name: status_code
- name: status_codes.*
type: object
object_type: long
description: >
Expand Down

0 comments on commit 606bd1d

Please sign in to comment.