Skip to content

Commit 02bc2d4

Browse files
ruflinjsoriano
authored andcommitted
Add tests to verify template content (#7606)
We recently started to move fields.yml into the Golang binary to be used internally. To make sure the loading important and loading of all the data into the binary works as expected for Metricbeat, this adds some basic tests. Related to #7605.
1 parent 3a0ab98 commit 02bc2d4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import metricbeat
3+
import json
4+
from nose.plugins.skip import SkipTest
5+
6+
7+
class Test(metricbeat.BaseTest):
8+
9+
def test_export_template(self):
10+
"""
11+
Test export template works and contains all fields
12+
"""
13+
14+
if os.name == "nt":
15+
raise SkipTest
16+
17+
self.render_config_template("metricbeat",
18+
os.path.join(self.working_dir,
19+
"metricbeat.yml"),
20+
)
21+
22+
# Remove fields.yml to make sure template is built from internal binary data
23+
os.remove(os.path.join(self.working_dir, "fields.yml"))
24+
25+
exit_code = self.run_beat(
26+
logging_args=[],
27+
extra_args=["export", "template"],
28+
config="metricbeat.yml",
29+
output="template.json"
30+
)
31+
assert exit_code == 0
32+
33+
template_path = os.path.join(self.working_dir, "template.json")
34+
template_content = ""
35+
36+
# Read in all json lines and discard the coverage info
37+
with open(template_path) as f:
38+
for line in f:
39+
template_content += line
40+
if line.startswith("}"):
41+
break
42+
43+
t = json.loads(template_content)
44+
45+
properties = t["mappings"]["doc"]["properties"]
46+
47+
# Check libbeat fields
48+
assert properties["@timestamp"] == {"type": "date"}
49+
assert properties["host"]["properties"]["name"] == {"type": "keyword", "ignore_above": 1024}
50+
51+
# Check metricbeat generic field
52+
assert properties["metricset"]["properties"]["host"] == {"type": "keyword", "ignore_above": 1024}
53+
54+
# Check module specific field
55+
assert properties["system"]["properties"]["cpu"]["properties"]["cores"] == {"type": "long"}

0 commit comments

Comments
 (0)