2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.regionserver
;
20 import static org
.junit
.Assert
.assertNotNull
;
22 import org
.apache
.hadoop
.conf
.Configuration
;
23 import org
.apache
.hadoop
.hbase
.CompatibilityFactory
;
24 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
25 import org
.apache
.hadoop
.hbase
.test
.MetricsAssertHelper
;
26 import org
.apache
.hadoop
.hbase
.testclassification
.RegionServerTests
;
27 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
28 import org
.apache
.hadoop
.hbase
.util
.JvmPauseMonitor
;
29 import org
.junit
.Before
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Test
;
33 import org
.junit
.experimental
.categories
.Category
;
36 * Unit test version of rs metrics tests.
38 @Category({RegionServerTests
.class, SmallTests
.class})
39 public class TestMetricsRegionServer
{
42 public static final HBaseClassTestRule CLASS_RULE
=
43 HBaseClassTestRule
.forClass(TestMetricsRegionServer
.class);
45 public static MetricsAssertHelper HELPER
=
46 CompatibilityFactory
.getInstance(MetricsAssertHelper
.class);
48 private MetricsRegionServerWrapperStub wrapper
;
49 private MetricsRegionServer rsm
;
50 private MetricsRegionServerSource serverSource
;
53 public static void classSetUp() {
59 wrapper
= new MetricsRegionServerWrapperStub();
60 rsm
= new MetricsRegionServer(wrapper
, new Configuration(false), null);
61 serverSource
= rsm
.getMetricsSource();
65 public void testWrapperSource() {
66 HELPER
.assertTag("serverName", "test", serverSource
);
67 HELPER
.assertTag("clusterId", "tClusterId", serverSource
);
68 HELPER
.assertTag("zookeeperQuorum", "zk", serverSource
);
69 HELPER
.assertGauge("regionServerStartTime", 100, serverSource
);
70 HELPER
.assertGauge("regionCount", 101, serverSource
);
71 HELPER
.assertGauge("storeCount", 2, serverSource
);
72 HELPER
.assertGauge("maxStoreFileAge", 2, serverSource
);
73 HELPER
.assertGauge("minStoreFileAge", 2, serverSource
);
74 HELPER
.assertGauge("avgStoreFileAge", 2, serverSource
);
75 HELPER
.assertGauge("numReferenceFiles", 2, serverSource
);
76 HELPER
.assertGauge("hlogFileCount", 10, serverSource
);
77 HELPER
.assertGauge("hlogFileSize", 1024000, serverSource
);
78 HELPER
.assertGauge("storeFileCount", 300, serverSource
);
79 HELPER
.assertGauge("memstoreSize", 1025, serverSource
);
80 HELPER
.assertGauge("storeFileSize", 1900, serverSource
);
81 HELPER
.assertGauge("storeFileSizeGrowthRate", 50.0, serverSource
);
82 HELPER
.assertCounter("totalRequestCount", 899, serverSource
);
83 HELPER
.assertCounter("totalRowActionRequestCount",
84 HELPER
.getCounter("readRequestCount", serverSource
)
85 + HELPER
.getCounter("writeRequestCount", serverSource
),
87 HELPER
.assertCounter("readRequestCount", 997, serverSource
);
88 HELPER
.assertCounter("cpRequestCount", 998, serverSource
);
89 HELPER
.assertCounter("filteredReadRequestCount", 1997, serverSource
);
90 HELPER
.assertCounter("writeRequestCount", 707, serverSource
);
91 HELPER
.assertCounter("checkMutateFailedCount", 401, serverSource
);
92 HELPER
.assertCounter("checkMutatePassedCount", 405, serverSource
);
93 HELPER
.assertGauge("storeFileIndexSize", 406, serverSource
);
94 HELPER
.assertGauge("staticIndexSize", 407, serverSource
);
95 HELPER
.assertGauge("staticBloomSize", 408, serverSource
);
96 HELPER
.assertGauge("mutationsWithoutWALCount", 409, serverSource
);
97 HELPER
.assertGauge("mutationsWithoutWALSize", 410, serverSource
);
98 HELPER
.assertGauge("percentFilesLocal", 99, serverSource
);
99 HELPER
.assertGauge("percentFilesLocalSecondaryRegions", 99, serverSource
);
100 HELPER
.assertGauge("compactionQueueLength", 411, serverSource
);
101 HELPER
.assertGauge("flushQueueLength", 412, serverSource
);
102 HELPER
.assertGauge("blockCacheFreeSize", 413, serverSource
);
103 HELPER
.assertGauge("blockCacheCount", 414, serverSource
);
104 HELPER
.assertGauge("blockCacheSize", 415, serverSource
);
105 HELPER
.assertCounter("blockCacheHitCount", 416, serverSource
);
106 HELPER
.assertCounter("blockCacheMissCount", 417, serverSource
);
107 HELPER
.assertCounter("blockCacheEvictionCount", 418, serverSource
);
108 HELPER
.assertGauge("blockCacheCountHitPercent", 98, serverSource
);
109 HELPER
.assertGauge("blockCacheExpressHitPercent", 97, serverSource
);
110 HELPER
.assertCounter("blockCacheFailedInsertionCount", 36, serverSource
);
111 HELPER
.assertGauge("l1CacheHitCount", 200, serverSource
);
112 HELPER
.assertGauge("l1CacheMissCount", 100, serverSource
);
113 HELPER
.assertGauge("l1CacheHitRatio", 80, serverSource
);
114 HELPER
.assertGauge("l1CacheMissRatio", 20, serverSource
);
115 HELPER
.assertGauge("l2CacheHitCount", 800, serverSource
);
116 HELPER
.assertGauge("l2CacheMissCount", 200, serverSource
);
117 HELPER
.assertGauge("l2CacheHitRatio", 90, serverSource
);
118 HELPER
.assertGauge("l2CacheMissRatio", 10, serverSource
);
119 HELPER
.assertCounter("updatesBlockedTime", 419, serverSource
);
123 public void testConstuctor() {
124 assertNotNull("There should be a hadoop1/hadoop2 metrics source", rsm
.getMetricsSource() );
125 assertNotNull("The RegionServerMetricsWrapper should be accessable", rsm
.getRegionServerWrapper());
129 public void testSlowCount() {
130 for (int i
=0; i
< 12; i
++) {
131 rsm
.updateAppend(null, 12);
132 rsm
.updateAppend(null, 1002);
134 for (int i
=0; i
< 13; i
++) {
135 rsm
.updateDeleteBatch(null, 13);
136 rsm
.updateDeleteBatch(null, 1003);
138 for (int i
=0; i
< 14; i
++) {
139 rsm
.updateGet(null, 14);
140 rsm
.updateGet(null, 1004);
142 for (int i
=0; i
< 15; i
++) {
143 rsm
.updateIncrement(null, 15);
144 rsm
.updateIncrement(null, 1005);
146 for (int i
=0; i
< 16; i
++) {
147 rsm
.updatePutBatch(null, 16);
148 rsm
.updatePutBatch(null, 1006);
151 for (int i
=0; i
< 17; i
++) {
152 rsm
.updatePut(null, 17);
153 rsm
.updateDelete(null, 17);
154 rsm
.updateCheckAndDelete(17);
155 rsm
.updateCheckAndPut(17);
158 HELPER
.assertCounter("appendNumOps", 24, serverSource
);
159 HELPER
.assertCounter("deleteBatchNumOps", 26, serverSource
);
160 HELPER
.assertCounter("getNumOps", 28, serverSource
);
161 HELPER
.assertCounter("incrementNumOps", 30, serverSource
);
162 HELPER
.assertCounter("putBatchNumOps", 32, serverSource
);
163 HELPER
.assertCounter("putNumOps", 17, serverSource
);
164 HELPER
.assertCounter("deleteNumOps", 17, serverSource
);
165 HELPER
.assertCounter("checkAndDeleteNumOps", 17, serverSource
);
166 HELPER
.assertCounter("checkAndPutNumOps", 17, serverSource
);
169 HELPER
.assertCounter("slowAppendCount", 12, serverSource
);
170 HELPER
.assertCounter("slowDeleteCount", 13, serverSource
);
171 HELPER
.assertCounter("slowGetCount", 14, serverSource
);
172 HELPER
.assertCounter("slowIncrementCount", 15, serverSource
);
173 HELPER
.assertCounter("slowPutCount", 16, serverSource
);
176 String FLUSH_TIME
= "flushTime";
177 String FLUSH_TIME_DESC
= "Histogram for the time in millis for memstore flush";
178 String FLUSH_MEMSTORE_SIZE
= "flushMemstoreSize";
179 String FLUSH_MEMSTORE_SIZE_DESC
= "Histogram for number of bytes in the memstore for a flush";
180 String FLUSH_FILE_SIZE
= "flushFileSize";
181 String FLUSH_FILE_SIZE_DESC
= "Histogram for number of bytes in the resulting file for a flush";
182 String FLUSHED_OUTPUT_BYTES
= "flushedOutputBytes";
183 String FLUSHED_OUTPUT_BYTES_DESC
= "Total number of bytes written from flush";
184 String FLUSHED_MEMSTORE_BYTES
= "flushedMemstoreBytes";
185 String FLUSHED_MEMSTORE_BYTES_DESC
= "Total number of bytes of cells in memstore from flush";
188 public void testFlush() {
189 rsm
.updateFlush(null, 1, 2, 3);
190 HELPER
.assertCounter("flushTime_num_ops", 1, serverSource
);
191 HELPER
.assertCounter("flushMemstoreSize_num_ops", 1, serverSource
);
192 HELPER
.assertCounter("flushOutputSize_num_ops", 1, serverSource
);
193 HELPER
.assertCounter("flushedMemstoreBytes", 2, serverSource
);
194 HELPER
.assertCounter("flushedOutputBytes", 3, serverSource
);
196 rsm
.updateFlush(null, 10, 20, 30);
197 HELPER
.assertCounter("flushTimeNumOps", 2, serverSource
);
198 HELPER
.assertCounter("flushMemstoreSize_num_ops", 2, serverSource
);
199 HELPER
.assertCounter("flushOutputSize_num_ops", 2, serverSource
);
200 HELPER
.assertCounter("flushedMemstoreBytes", 22, serverSource
);
201 HELPER
.assertCounter("flushedOutputBytes", 33, serverSource
);
205 public void testCompaction() {
206 rsm
.updateCompaction(null, false, 1, 2, 3, 4, 5);
207 HELPER
.assertCounter("compactionTime_num_ops", 1, serverSource
);
208 HELPER
.assertCounter("compactionInputFileCount_num_ops", 1, serverSource
);
209 HELPER
.assertCounter("compactionInputSize_num_ops", 1, serverSource
);
210 HELPER
.assertCounter("compactionOutputFileCount_num_ops", 1, serverSource
);
211 HELPER
.assertCounter("compactedInputBytes", 4, serverSource
);
212 HELPER
.assertCounter("compactedoutputBytes", 5, serverSource
);
214 rsm
.updateCompaction(null, false, 10, 20, 30, 40, 50);
215 HELPER
.assertCounter("compactionTime_num_ops", 2, serverSource
);
216 HELPER
.assertCounter("compactionInputFileCount_num_ops", 2, serverSource
);
217 HELPER
.assertCounter("compactionInputSize_num_ops", 2, serverSource
);
218 HELPER
.assertCounter("compactionOutputFileCount_num_ops", 2, serverSource
);
219 HELPER
.assertCounter("compactedInputBytes", 44, serverSource
);
220 HELPER
.assertCounter("compactedoutputBytes", 55, serverSource
);
222 // do major compaction
223 rsm
.updateCompaction(null, true, 100, 200, 300, 400, 500);
225 HELPER
.assertCounter("compactionTime_num_ops", 3, serverSource
);
226 HELPER
.assertCounter("compactionInputFileCount_num_ops", 3, serverSource
);
227 HELPER
.assertCounter("compactionInputSize_num_ops", 3, serverSource
);
228 HELPER
.assertCounter("compactionOutputFileCount_num_ops", 3, serverSource
);
229 HELPER
.assertCounter("compactedInputBytes", 444, serverSource
);
230 HELPER
.assertCounter("compactedoutputBytes", 555, serverSource
);
232 HELPER
.assertCounter("majorCompactionTime_num_ops", 1, serverSource
);
233 HELPER
.assertCounter("majorCompactionInputFileCount_num_ops", 1, serverSource
);
234 HELPER
.assertCounter("majorCompactionInputSize_num_ops", 1, serverSource
);
235 HELPER
.assertCounter("majorCompactionOutputFileCount_num_ops", 1, serverSource
);
236 HELPER
.assertCounter("majorCompactedInputBytes", 400, serverSource
);
237 HELPER
.assertCounter("majorCompactedoutputBytes", 500, serverSource
);
241 public void testPauseMonitor() {
242 Configuration conf
= new Configuration();
243 conf
.setLong(JvmPauseMonitor
.INFO_THRESHOLD_KEY
, 1000L);
244 conf
.setLong(JvmPauseMonitor
.WARN_THRESHOLD_KEY
, 10000L);
245 JvmPauseMonitor monitor
= new JvmPauseMonitor(conf
, serverSource
);
246 monitor
.updateMetrics(1500, false);
247 HELPER
.assertCounter("pauseInfoThresholdExceeded", 1, serverSource
);
248 HELPER
.assertCounter("pauseWarnThresholdExceeded", 0, serverSource
);
249 HELPER
.assertCounter("pauseTimeWithoutGc_num_ops", 1, serverSource
);
250 HELPER
.assertCounter("pauseTimeWithGc_num_ops", 0, serverSource
);
251 monitor
.updateMetrics(15000, true);
252 HELPER
.assertCounter("pauseInfoThresholdExceeded", 1, serverSource
);
253 HELPER
.assertCounter("pauseWarnThresholdExceeded", 1, serverSource
);
254 HELPER
.assertCounter("pauseTimeWithoutGc_num_ops", 1, serverSource
);
255 HELPER
.assertCounter("pauseTimeWithGc_num_ops", 1, serverSource
);