1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver;
19
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.CompatibilityFactory;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.apache.hadoop.hbase.test.MetricsAssertHelper;
29 import org.apache.hadoop.hbase.util.JvmPauseMonitor;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
34
35
36
37
38 @Category(SmallTests.class)
39 public class TestMetricsRegionServer {
40 public static MetricsAssertHelper HELPER =
41 CompatibilityFactory.getInstance(MetricsAssertHelper.class);
42
43 private MetricsRegionServerWrapperStub wrapper;
44 private MetricsRegionServer rsm;
45 private MetricsRegionServerSource serverSource;
46
47 @BeforeClass
48 public static void classSetUp() {
49 HELPER.init();
50 }
51
52 @Before
53 public void setUp() {
54 wrapper = new MetricsRegionServerWrapperStub();
55 Configuration conf = new Configuration(false);
56 conf.setBoolean(MetricsRegionServer.RS_ENABLE_SERVER_QUERY_METER_METRICS_KEY, false);
57 rsm = new MetricsRegionServer(wrapper, conf);
58 serverSource = rsm.getMetricsSource();
59 }
60
61 @Test
62 public void testWrapperSource() {
63 HELPER.assertTag("serverName", "test", serverSource);
64 HELPER.assertTag("clusterId", "tClusterId", serverSource);
65 HELPER.assertTag("zookeeperQuorum", "zk", serverSource);
66 HELPER.assertGauge("regionServerStartTime", 100, serverSource);
67 HELPER.assertGauge("regionCount", 101, serverSource);
68 HELPER.assertGauge("storeCount", 2, serverSource);
69 HELPER.assertGauge("maxStoreFileAge", 2, serverSource);
70 HELPER.assertGauge("minStoreFileAge", 2, serverSource);
71 HELPER.assertGauge("avgStoreFileAge", 2, serverSource);
72 HELPER.assertGauge("numReferenceFiles", 2, serverSource);
73 HELPER.assertGauge("hlogFileCount", 10, serverSource);
74 HELPER.assertGauge("hlogFileSize", 1024000, serverSource);
75 HELPER.assertGauge("storeFileCount", 300, serverSource);
76 HELPER.assertGauge("memstoreSize", 1025, serverSource);
77 HELPER.assertGauge("storeFileSize", 1900, serverSource);
78 HELPER.assertCounter("totalRequestCount", 899, serverSource);
79 HELPER.assertCounter("totalRowActionRequestCount",
80 HELPER.getCounter("readRequestCount", serverSource)
81 + HELPER.getCounter("writeRequestCount", serverSource),
82 serverSource);
83 HELPER.assertCounter("readRequestCount", 997, serverSource);
84 HELPER.assertCounter("writeRequestCount", 707, serverSource);
85 HELPER.assertCounter("checkMutateFailedCount", 401, serverSource);
86 HELPER.assertCounter("checkMutatePassedCount", 405, serverSource);
87 HELPER.assertGauge("storeFileIndexSize", 406, serverSource);
88 HELPER.assertGauge("staticIndexSize", 407, serverSource);
89 HELPER.assertGauge("staticBloomSize", 408, serverSource);
90 HELPER.assertGauge("mutationsWithoutWALCount", 409, serverSource);
91 HELPER.assertGauge("mutationsWithoutWALSize", 410, serverSource);
92 HELPER.assertGauge("percentFilesLocal", 99, serverSource);
93 HELPER.assertGauge("percentFilesLocalSecondaryRegions", 99, serverSource);
94 HELPER.assertGauge("compactionQueueLength", 411, serverSource);
95 HELPER.assertGauge("flushQueueLength", 412, serverSource);
96 HELPER.assertGauge("blockCacheFreeSize", 413, serverSource);
97 HELPER.assertGauge("blockCacheCount", 414, serverSource);
98 HELPER.assertGauge("blockCacheSize", 415, serverSource);
99 HELPER.assertCounter("blockCacheHitCount", 416, serverSource);
100 HELPER.assertCounter("blockCacheMissCount", 417, serverSource);
101 HELPER.assertCounter("blockCacheEvictionCount", 418, serverSource);
102 HELPER.assertGauge("blockCacheCountHitPercent", 98, serverSource);
103 HELPER.assertGauge("blockCacheExpressHitPercent", 97, serverSource);
104 HELPER.assertCounter("blockCacheFailedInsertionCount", 36, serverSource);
105 HELPER.assertGauge("l1CacheHitCount", 200, serverSource);
106 HELPER.assertGauge("l1CacheMissCount", 100, serverSource);
107 HELPER.assertGauge("l1CacheHitRatio", 80, serverSource);
108 HELPER.assertGauge("l1CacheMissRatio", 20, serverSource);
109 HELPER.assertGauge("l2CacheHitCount", 800, serverSource);
110 HELPER.assertGauge("l2CacheMissCount", 200, serverSource);
111 HELPER.assertGauge("l2CacheHitRatio", 90, serverSource);
112 HELPER.assertGauge("l2CacheMissRatio", 10, serverSource);
113 HELPER.assertCounter("updatesBlockedTime", 419, serverSource);
114 }
115
116 @Test
117 public void testConstuctor() {
118 assertNotNull("There should be a hadoop1/hadoop2 metrics source", rsm.getMetricsSource() );
119 assertNotNull("The RegionServerMetricsWrapper should be accessable", rsm.getRegionServerWrapper());
120 }
121
122 @Test
123 public void testSlowCount() {
124 for (int i=0; i < 12; i ++) {
125 rsm.updateAppend(null, 12);
126 rsm.updateAppend(null, 1002);
127 }
128 for (int i=0; i < 13; i ++) {
129 rsm.updateDeleteBatch(null, 13);
130 rsm.updateDeleteBatch(null, 1003);
131 }
132 for (int i=0; i < 14; i ++) {
133 rsm.updateGet(null, 14);
134 rsm.updateGet(null, 1004);
135 }
136 for (int i=0; i < 15; i ++) {
137 rsm.updateIncrement(null, 15);
138 rsm.updateIncrement(null, 1005);
139 }
140 for (int i=0; i < 16; i ++) {
141 rsm.updatePutBatch(null, 16);
142 rsm.updatePutBatch(null, 1006);
143 }
144
145 for (int i=0; i < 17; i ++) {
146 rsm.updatePut(null, 17);
147 rsm.updateDelete(null, 17);
148 rsm.updateCheckAndDelete(null, 17);
149 rsm.updateCheckAndPut(null, 17);
150 }
151
152 HELPER.assertCounter("appendNumOps", 24, serverSource);
153 HELPER.assertCounter("deleteBatchNumOps", 26, serverSource);
154 HELPER.assertCounter("getNumOps", 28, serverSource);
155 HELPER.assertCounter("incrementNumOps", 30, serverSource);
156 HELPER.assertCounter("putBatchNumOps", 32, serverSource);
157 HELPER.assertCounter("putNumOps", 17, serverSource);
158 HELPER.assertCounter("deleteNumOps", 17, serverSource);
159 HELPER.assertCounter("checkAndDeleteNumOps", 17, serverSource);
160 HELPER.assertCounter("checkAndPutNumOps", 17, serverSource);
161
162
163 HELPER.assertCounter("slowAppendCount", 12, serverSource);
164 HELPER.assertCounter("slowDeleteCount", 13, serverSource);
165 HELPER.assertCounter("slowGetCount", 14, serverSource);
166 HELPER.assertCounter("slowIncrementCount", 15, serverSource);
167 HELPER.assertCounter("slowPutCount", 16, serverSource);
168 }
169
170 @Test
171 public void testFlush() {
172 rsm.updateFlush(1, 2, 3);
173 HELPER.assertCounter("flushTime_num_ops", 1, serverSource);
174 HELPER.assertCounter("flushMemstoreSize_num_ops", 1, serverSource);
175 HELPER.assertCounter("flushOutputSize_num_ops", 1, serverSource);
176 HELPER.assertCounter("flushedMemstoreBytes", 2, serverSource);
177 HELPER.assertCounter("flushedOutputBytes", 3, serverSource);
178
179 rsm.updateFlush(10, 20, 30);
180 HELPER.assertCounter("flushTimeNumOps", 2, serverSource);
181 HELPER.assertCounter("flushMemstoreSize_num_ops", 2, serverSource);
182 HELPER.assertCounter("flushOutputSize_num_ops", 2, serverSource);
183 HELPER.assertCounter("flushedMemstoreBytes", 22, serverSource);
184 HELPER.assertCounter("flushedOutputBytes", 33, serverSource);
185 }
186
187 @Test
188 public void testCompaction() {
189 rsm.updateCompaction(false, 1, 2, 3, 4, 5);
190 HELPER.assertCounter("compactionTime_num_ops", 1, serverSource);
191 HELPER.assertCounter("compactionInputFileCount_num_ops", 1, serverSource);
192 HELPER.assertCounter("compactionInputSize_num_ops", 1, serverSource);
193 HELPER.assertCounter("compactionOutputFileCount_num_ops", 1, serverSource);
194 HELPER.assertCounter("compactedInputBytes", 4, serverSource);
195 HELPER.assertCounter("compactedoutputBytes", 5, serverSource);
196
197 rsm.updateCompaction(false, 10, 20, 30, 40, 50);
198 HELPER.assertCounter("compactionTime_num_ops", 2, serverSource);
199 HELPER.assertCounter("compactionInputFileCount_num_ops", 2, serverSource);
200 HELPER.assertCounter("compactionInputSize_num_ops", 2, serverSource);
201 HELPER.assertCounter("compactionOutputFileCount_num_ops", 2, serverSource);
202 HELPER.assertCounter("compactedInputBytes", 44, serverSource);
203 HELPER.assertCounter("compactedoutputBytes", 55, serverSource);
204
205
206 rsm.updateCompaction(true, 100, 200, 300, 400, 500);
207
208 HELPER.assertCounter("compactionTime_num_ops", 3, serverSource);
209 HELPER.assertCounter("compactionInputFileCount_num_ops", 3, serverSource);
210 HELPER.assertCounter("compactionInputSize_num_ops", 3, serverSource);
211 HELPER.assertCounter("compactionOutputFileCount_num_ops", 3, serverSource);
212 HELPER.assertCounter("compactedInputBytes", 444, serverSource);
213 HELPER.assertCounter("compactedoutputBytes", 555, serverSource);
214
215 HELPER.assertCounter("majorCompactionTime_num_ops", 1, serverSource);
216 HELPER.assertCounter("majorCompactionInputFileCount_num_ops", 1, serverSource);
217 HELPER.assertCounter("majorCompactionInputSize_num_ops", 1, serverSource);
218 HELPER.assertCounter("majorCompactionOutputFileCount_num_ops", 1, serverSource);
219 HELPER.assertCounter("majorCompactedInputBytes", 400, serverSource);
220 HELPER.assertCounter("majorCompactedoutputBytes", 500, serverSource);
221 }
222
223 @Test
224 public void testPauseMonitor() {
225 Configuration conf = new Configuration();
226 conf.setLong(JvmPauseMonitor.INFO_THRESHOLD_KEY, 1000L);
227 conf.setLong(JvmPauseMonitor.WARN_THRESHOLD_KEY, 10000L);
228 JvmPauseMonitor monitor = new JvmPauseMonitor(conf, serverSource);
229 monitor.updateMetrics(1500, false);
230 HELPER.assertCounter("pauseInfoThresholdExceeded", 1, serverSource);
231 HELPER.assertCounter("pauseWarnThresholdExceeded", 0, serverSource);
232 HELPER.assertCounter("pauseTimeWithoutGc_num_ops", 1, serverSource);
233 HELPER.assertCounter("pauseTimeWithGc_num_ops", 0, serverSource);
234 monitor.updateMetrics(15000, true);
235 HELPER.assertCounter("pauseInfoThresholdExceeded", 1, serverSource);
236 HELPER.assertCounter("pauseWarnThresholdExceeded", 1, serverSource);
237 HELPER.assertCounter("pauseTimeWithoutGc_num_ops", 1, serverSource);
238 HELPER.assertCounter("pauseTimeWithGc_num_ops", 1, serverSource);
239 }
240
241 @Test
242 public void testServerQueryMeterSwitch() {
243 TableName tn1 = TableName.valueOf("table1");
244
245 rsm.updateReadQueryMeter(tn1, 500L);
246 assertFalse(HELPER.checkGaugeExists("ServerReadQueryPerSecond_count", serverSource));
247 rsm.updateWriteQueryMeter(tn1, 500L);
248 assertFalse(HELPER.checkGaugeExists("ServerWriteQueryPerSecond_count", serverSource));
249
250
251 Configuration conf = new Configuration(false);
252 conf.setBoolean(MetricsRegionServer.RS_ENABLE_SERVER_QUERY_METER_METRICS_KEY, true);
253 rsm = new MetricsRegionServer(wrapper, conf);
254 serverSource = rsm.getMetricsSource();
255 rsm.updateReadQueryMeter(tn1, 500L);
256 assertTrue(HELPER.checkGaugeExists("ServerWriteQueryPerSecond_count", serverSource));
257 HELPER.assertGauge("ServerReadQueryPerSecond_count", 500L, serverSource);
258 assertTrue(HELPER.checkGaugeExists("ServerWriteQueryPerSecond_count", serverSource));
259 rsm.updateWriteQueryMeter(tn1, 500L);
260 HELPER.assertGauge("ServerWriteQueryPerSecond_count", 500L, serverSource);
261 }
262 }
263