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