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