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