forked from thepaul/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmxmetrics_test.py
184 lines (168 loc) · 11.6 KB
/
jmxmetrics_test.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
from dtest import Tester
from tools import debug
from jmxutils import JolokiaAgent, make_mbean, remove_perf_disable_shared_mem
# We currently only have attributes that are incrementing.
# MBEAN_VALUES are expressed in tuple with the first value being the class, then the type,
# a dictionary of arguments for make_mbean(), the attribute, and then the value.
# MBEAN_VALUES_PRE are values for up to release 2.2, MBEAN_VALUES_POST are for 3.0 and later.
# In 3.0 "ColumnFamily" has been renamed to "Table" and "Row" to "Partition".
# However, the old names are also supported for backward compatibility and we test them via
# the mbean aliases, see begin_test().
def MBEAN_VALUES_PRE(ks, table):
return [('db', 'Caches', {}, 'CounterCacheKeysToSave', 2147483647),
('db', 'Caches', {}, 'CounterCacheSavePeriodInSeconds', 7200),
('db', 'BatchlogManager', {}, 'TotalBatchesReplayed', 0),
('db', 'Caches', {}, 'RowCacheSavePeriodInSeconds', 0),
('db', 'IndexSummaries', {}, 'MemoryPoolSizeInMB', 'MBeanIncrement'),
('db', 'IndexSummaries', {}, 'IndexIntervals', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'AllMemtablesLiveDataSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'AllMemtablesHeapSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'AllMemtablesOffHeapSize'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'BloomFilterDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'BloomFilterFalsePositives'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'IndexSummaryOffHeapMemoryUsed'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'LiveDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'LiveSSTableCount'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'MemtableColumnsCount'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'MemtableLiveDataSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'MemtableOnHeapSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'MemtableSwitchCount'}, 'Value', 'MBeanIncrement'),
('metrics', 'ColumnFamily', {'name': 'MemtableOffHeapSize'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'PendingCompactions'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'CompressionRatio'}, 'Value', 'MBeanDecrement'),
('metrics', 'ColumnFamily', {'name': 'MaxRowSize'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'MinRowSize'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'MeanRowSize'}, 'Value', 'MBeanDecrement'),
('metrics', 'ColumnFamily', {'name': 'RowCacheHit'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'RowCacheHitOutOfRange'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'RowCacheMiss'}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'EstimatedRowSizeHistogram', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual'),
('metrics', 'ColumnFamily', {'name': 'EstimatedRowCount', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual')]
def MBEAN_VALUES_POST(ks, table):
return [('db', 'Caches', {}, 'CounterCacheKeysToSave', 2147483647),
('db', 'Caches', {}, 'CounterCacheSavePeriodInSeconds', 7200),
('db', 'BatchlogManager', {}, 'TotalBatchesReplayed', 0),
('db', 'Caches', {}, 'RowCacheSavePeriodInSeconds', 0),
('db', 'IndexSummaries', {}, 'MemoryPoolSizeInMB', 'MBeanIncrement'),
('db', 'IndexSummaries', {}, 'IndexIntervals', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'AllMemtablesLiveDataSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'AllMemtablesHeapSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'AllMemtablesOffHeapSize'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'BloomFilterDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'BloomFilterFalsePositives'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'IndexSummaryOffHeapMemoryUsed'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'LiveDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'LiveSSTableCount'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'MemtableColumnsCount'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'MemtableLiveDataSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'MemtableOnHeapSize'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'MemtableSwitchCount'}, 'Value', 'MBeanIncrement'),
('metrics', 'Table', {'name': 'MemtableOffHeapSize'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'PendingCompactions'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'CompressionRatio'}, 'Value', 'MBeanDecrement'),
('metrics', 'Table', {'name': 'MaxPartitionSize'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'MinPartitionSize'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'MeanPartitionSize'}, 'Value', 'MBeanDecrement'),
('metrics', 'Table', {'name': 'RowCacheHit'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'RowCacheHitOutOfRange'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'RowCacheMiss'}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'EstimatedPartitionSizeHistogram', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual'),
('metrics', 'Table', {'name': 'EstimatedPartitionCount', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual')]
class TestJMXMetrics(Tester):
def __init__(self, *args, **kwargs):
Tester.__init__(self, *args, **kwargs)
def begin_test(self):
"""
@jira_ticket CASSANDRA-7436
This test measures the values of MBeans before and after running a load. We expect
the values to change a certain way, and thus deem them as 'MBeanEqual','MBeanDecrement',
'MBeanIncrement', or a constant to experss this expected change. If the value does not reflect
this expected change, then it raises an AssertionError.
@jira_ticket CASSANDRA-9448
This test also makes sure to cover all metrics that were renamed by CASSANDRA-9448, in post 3.0
we also check that the old alias names are the same as the new names.
"""
cluster = self.cluster
cluster.populate(1)
node = cluster.nodelist()[0]
remove_perf_disable_shared_mem(node)
cluster.start(wait_for_binary_proto=True)
session = self.patient_cql_connection(node)
self.create_ks(session, 'keyspace1', 1)
session.execute("""
CREATE TABLE keyspace1.counter1 (
key blob,
column1 ascii,
value counter,
PRIMARY KEY (key, column1)
) WITH COMPACT STORAGE
AND CLUSTERING ORDER BY (column1 ASC)
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
AND compression = {}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = 'NONE';
""")
with JolokiaAgent(node) as jmx:
debug("Cluster version {}".format(cluster.version()))
if cluster.version() <= '2.2.X':
mbean_values = MBEAN_VALUES_PRE('keyspace1', 'counter1')
mbean_aliases = None
else:
mbean_values = MBEAN_VALUES_POST('keyspace1', 'counter1')
mbean_aliases = MBEAN_VALUES_PRE('keyspace1', 'counter1')
before = []
for package, bean, bean_args, attribute, expected in mbean_values:
mbean = make_mbean(package, type=bean, **bean_args)
debug(mbean)
before.append(jmx.read_attribute(mbean, attribute))
if mbean_aliases:
alias_counter = 0
for package, bean, bean_args, attribute, expected in mbean_aliases:
mbean = make_mbean(package, type=bean, **bean_args)
debug(mbean)
self.assertEqual(before[alias_counter], jmx.read_attribute(mbean, attribute))
alias_counter += 1
if cluster.version() < "2.1":
node.stress(['-o', 'insert', '-n', '100000', '-p', '7100'])
else:
node.stress(['write', 'n=100K', '-port jmx=7100'])
errors = []
after = []
attr_counter = 0
for package, bean, bean_args, attribute, expected in mbean_values:
mbean = make_mbean(package, type=bean, **bean_args)
a_value = jmx.read_attribute(mbean, attribute)
after.append(a_value)
b_value = before[attr_counter]
if expected == 'MBeanIncrement':
if b_value >= a_value:
errors.append(mbean + " has a before value of " + str(b_value) + " and after value of " + str(a_value) + " and did not increment" + "\n")
elif expected == 'MBeanDecrement':
if b_value <= a_value:
errors.append(mbean + " has a before value of " + str(b_value) + " and after value of " + str(a_value) + " and did not decrement" + "\n")
elif expected == 'MBeanEqual':
if b_value != a_value:
errors.append(mbean + " has a before value of " + str(b_value) + " and after value of " + str(a_value) + ", which are not equal" + "\n")
elif expected == 'MBeanZero':
if not (b_value == 0 and a_value == 0):
errors.append(mbean + " has a before value of " + str(b_value) + " and after value of " + str(a_value) + " and they do not equal zero" + "\n")
# If expected is none of the above, then expected should be a number.
else:
if a_value != expected:
errors.append(mbean + " has an after value of " + str(a_value) + " which does not equal " + str(expected) + "\n")
attr_counter += 1
self.assertEqual(len(errors), 0, "\n" + "\n".join(errors))
if mbean_aliases:
alias_counter = 0
for package, bean, bean_args, attribute, expected in mbean_aliases:
mbean = make_mbean(package, type=bean, **bean_args)
self.assertEqual(after[alias_counter], jmx.read_attribute(mbean, attribute))
alias_counter += 1