-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
test_zookeeper.py
110 lines (88 loc) · 3.42 KB
/
test_zookeeper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import metricbeat
import os
import pytest
import sys
import unittest
ZK_FIELDS = metricbeat.COMMON_FIELDS + ["zookeeper"]
MNTR_FIELDS = ["latency.avg", "latency.max",
"latency.min", "packets.received", "packets.sent",
"outstanding_requests", "server_state", "znode_count",
"watch_count", "ephemerals_count",
"approximate_data_size", "num_alive_connections"]
@metricbeat.parameterized_with_supported_versions
class ZooKeeperMntrTest(metricbeat.BaseTest):
COMPOSE_SERVICES = ['zookeeper']
@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
@pytest.mark.tag('integration')
def test_output(self):
"""
ZooKeeper mntr module outputs an event.
"""
self.render_config_template(modules=[{
"name": "zookeeper",
"metricsets": ["mntr"],
"hosts": self.get_hosts(),
"period": "5s"
}])
proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0)
proc.check_kill_and_wait()
self.assert_no_logged_warnings()
output = self.read_output_json()
self.assertEqual(len(output), 1)
evt = output[0]
self.assertCountEqual(self.de_dot(ZK_FIELDS), evt.keys())
zk_mntr = evt["zookeeper"]["mntr"]
zk_mntr.pop("pending_syncs", None)
zk_mntr.pop("open_file_descriptor_count", None)
zk_mntr.pop("synced_followers", None)
zk_mntr.pop("max_file_descriptor_count", None)
zk_mntr.pop("followers", None)
self.assertCountEqual(self.de_dot(MNTR_FIELDS), zk_mntr.keys())
self.assert_fields_are_documented(evt)
@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
@pytest.mark.tag('integration')
def test_output(self):
"""
ZooKeeper server module outputs an event.
"""
self.render_config_template(modules=[{
"name": "zookeeper",
"metricsets": ["server"],
"hosts": self.get_hosts(),
"period": "5s"
}])
proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0)
proc.check_kill_and_wait()
self.assert_no_logged_warnings()
output = self.read_output_json()
self.assertEqual(len(output), 1)
evt = output[0]
self.assertCountEqual(self.de_dot(ZK_FIELDS), evt.keys())
zk_srvr = evt["zookeeper"]["server"]
assert zk_srvr["connections"] >= 0
self.assert_fields_are_documented(evt)
@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
@pytest.mark.tag('integration')
def test_connection(self):
"""
ZooKeeper server module outputs an event.
"""
self.render_config_template(modules=[{
"name": "zookeeper",
"metricsets": ["connection"],
"hosts": self.get_hosts(),
"period": "5s"
}])
proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0)
proc.check_kill_and_wait()
self.assert_no_logged_warnings()
output = self.read_output_json()
self.assertEqual(len(output), 1)
evt = output[0]
self.assertCountEqual(self.de_dot(ZK_FIELDS + ["client"]), evt.keys())
zk_conns = evt["zookeeper"]["connection"]
assert zk_conns["queued"] >= 0
self.assert_fields_are_documented(evt)