001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import static org.junit.Assert.assertNotNull; 021 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.CompatibilityFactory; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.test.MetricsAssertHelper; 026import org.apache.hadoop.hbase.testclassification.RegionServerTests; 027import org.apache.hadoop.hbase.testclassification.SmallTests; 028import org.apache.hadoop.hbase.util.JvmPauseMonitor; 029import org.junit.Before; 030import org.junit.BeforeClass; 031import org.junit.ClassRule; 032import org.junit.Test; 033import org.junit.experimental.categories.Category; 034 035/** 036 * Unit test version of rs metrics tests. 037 */ 038@Category({RegionServerTests.class, SmallTests.class}) 039public class TestMetricsRegionServer { 040 041 @ClassRule 042 public static final HBaseClassTestRule CLASS_RULE = 043 HBaseClassTestRule.forClass(TestMetricsRegionServer.class); 044 045 public static MetricsAssertHelper HELPER = 046 CompatibilityFactory.getInstance(MetricsAssertHelper.class); 047 048 private MetricsRegionServerWrapperStub wrapper; 049 private MetricsRegionServer rsm; 050 private MetricsRegionServerSource serverSource; 051 052 @BeforeClass 053 public static void classSetUp() { 054 HELPER.init(); 055 } 056 057 @Before 058 public void setUp() { 059 wrapper = new MetricsRegionServerWrapperStub(); 060 rsm = new MetricsRegionServer(wrapper, new Configuration(false)); 061 serverSource = rsm.getMetricsSource(); 062 } 063 064 @Test 065 public void testWrapperSource() { 066 HELPER.assertTag("serverName", "test", serverSource); 067 HELPER.assertTag("clusterId", "tClusterId", serverSource); 068 HELPER.assertTag("zookeeperQuorum", "zk", serverSource); 069 HELPER.assertGauge("regionServerStartTime", 100, serverSource); 070 HELPER.assertGauge("regionCount", 101, serverSource); 071 HELPER.assertGauge("storeCount", 2, serverSource); 072 HELPER.assertGauge("maxStoreFileAge", 2, serverSource); 073 HELPER.assertGauge("minStoreFileAge", 2, serverSource); 074 HELPER.assertGauge("avgStoreFileAge", 2, serverSource); 075 HELPER.assertGauge("numReferenceFiles", 2, serverSource); 076 HELPER.assertGauge("hlogFileCount", 10, serverSource); 077 HELPER.assertGauge("hlogFileSize", 1024000, serverSource); 078 HELPER.assertGauge("storeFileCount", 300, serverSource); 079 HELPER.assertGauge("memstoreSize", 1025, serverSource); 080 HELPER.assertGauge("storeFileSize", 1900, serverSource); 081 HELPER.assertCounter("totalRequestCount", 899, serverSource); 082 HELPER.assertCounter("totalRowActionRequestCount", 083 HELPER.getCounter("readRequestCount", serverSource) 084 + HELPER.getCounter("writeRequestCount", serverSource), 085 serverSource); 086 HELPER.assertCounter("readRequestCount", 997, serverSource); 087 HELPER.assertCounter("filteredReadRequestCount", 1997, serverSource); 088 HELPER.assertCounter("writeRequestCount", 707, serverSource); 089 HELPER.assertCounter("checkMutateFailedCount", 401, serverSource); 090 HELPER.assertCounter("checkMutatePassedCount", 405, serverSource); 091 HELPER.assertGauge("storeFileIndexSize", 406, serverSource); 092 HELPER.assertGauge("staticIndexSize", 407, serverSource); 093 HELPER.assertGauge("staticBloomSize", 408, serverSource); 094 HELPER.assertGauge("mutationsWithoutWALCount", 409, serverSource); 095 HELPER.assertGauge("mutationsWithoutWALSize", 410, serverSource); 096 HELPER.assertGauge("percentFilesLocal", 99, serverSource); 097 HELPER.assertGauge("percentFilesLocalSecondaryRegions", 99, serverSource); 098 HELPER.assertGauge("compactionQueueLength", 411, serverSource); 099 HELPER.assertGauge("flushQueueLength", 412, serverSource); 100 HELPER.assertGauge("blockCacheFreeSize", 413, serverSource); 101 HELPER.assertGauge("blockCacheCount", 414, serverSource); 102 HELPER.assertGauge("blockCacheSize", 415, serverSource); 103 HELPER.assertCounter("blockCacheHitCount", 416, serverSource); 104 HELPER.assertCounter("blockCacheMissCount", 417, serverSource); 105 HELPER.assertCounter("blockCacheEvictionCount", 418, serverSource); 106 HELPER.assertGauge("blockCacheCountHitPercent", 98, serverSource); 107 HELPER.assertGauge("blockCacheExpressHitPercent", 97, serverSource); 108 HELPER.assertCounter("blockCacheFailedInsertionCount", 36, serverSource); 109 HELPER.assertGauge("l1CacheHitCount", 200, serverSource); 110 HELPER.assertGauge("l1CacheMissCount", 100, serverSource); 111 HELPER.assertGauge("l1CacheHitRatio", 80, serverSource); 112 HELPER.assertGauge("l1CacheMissRatio", 20, serverSource); 113 HELPER.assertGauge("l2CacheHitCount", 800, serverSource); 114 HELPER.assertGauge("l2CacheMissCount", 200, serverSource); 115 HELPER.assertGauge("l2CacheHitRatio", 90, serverSource); 116 HELPER.assertGauge("l2CacheMissRatio", 10, serverSource); 117 HELPER.assertCounter("updatesBlockedTime", 419, serverSource); 118 } 119 120 @Test 121 public void testConstuctor() { 122 assertNotNull("There should be a hadoop1/hadoop2 metrics source", rsm.getMetricsSource() ); 123 assertNotNull("The RegionServerMetricsWrapper should be accessable", rsm.getRegionServerWrapper()); 124 } 125 126 @Test 127 public void testSlowCount() { 128 for (int i=0; i < 12; i ++) { 129 rsm.updateAppend(null, 12); 130 rsm.updateAppend(null, 1002); 131 } 132 for (int i=0; i < 13; i ++) { 133 rsm.updateDeleteBatch(null, 13); 134 rsm.updateDeleteBatch(null, 1003); 135 } 136 for (int i=0; i < 14; i ++) { 137 rsm.updateGet(null, 14); 138 rsm.updateGet(null, 1004); 139 } 140 for (int i=0; i < 15; i ++) { 141 rsm.updateIncrement(null, 15); 142 rsm.updateIncrement(null, 1005); 143 } 144 for (int i=0; i < 16; i ++) { 145 rsm.updatePutBatch(null, 16); 146 rsm.updatePutBatch(null, 1006); 147 } 148 149 for (int i=0; i < 17; i ++) { 150 rsm.updatePut(null, 17); 151 rsm.updateDelete(null, 17); 152 rsm.updateCheckAndDelete(17); 153 rsm.updateCheckAndPut(17); 154 } 155 156 HELPER.assertCounter("appendNumOps", 24, serverSource); 157 HELPER.assertCounter("deleteBatchNumOps", 26, serverSource); 158 HELPER.assertCounter("getNumOps", 28, serverSource); 159 HELPER.assertCounter("incrementNumOps", 30, serverSource); 160 HELPER.assertCounter("putBatchNumOps", 32, serverSource); 161 HELPER.assertCounter("putNumOps", 17, serverSource); 162 HELPER.assertCounter("deleteNumOps", 17, serverSource); 163 HELPER.assertCounter("checkAndDeleteNumOps", 17, serverSource); 164 HELPER.assertCounter("checkAndPutNumOps", 17, serverSource); 165 166 167 HELPER.assertCounter("slowAppendCount", 12, serverSource); 168 HELPER.assertCounter("slowDeleteCount", 13, serverSource); 169 HELPER.assertCounter("slowGetCount", 14, serverSource); 170 HELPER.assertCounter("slowIncrementCount", 15, serverSource); 171 HELPER.assertCounter("slowPutCount", 16, serverSource); 172 } 173 174 String FLUSH_TIME = "flushTime"; 175 String FLUSH_TIME_DESC = "Histogram for the time in millis for memstore flush"; 176 String FLUSH_MEMSTORE_SIZE = "flushMemstoreSize"; 177 String FLUSH_MEMSTORE_SIZE_DESC = "Histogram for number of bytes in the memstore for a flush"; 178 String FLUSH_FILE_SIZE = "flushFileSize"; 179 String FLUSH_FILE_SIZE_DESC = "Histogram for number of bytes in the resulting file for a flush"; 180 String FLUSHED_OUTPUT_BYTES = "flushedOutputBytes"; 181 String FLUSHED_OUTPUT_BYTES_DESC = "Total number of bytes written from flush"; 182 String FLUSHED_MEMSTORE_BYTES = "flushedMemstoreBytes"; 183 String FLUSHED_MEMSTORE_BYTES_DESC = "Total number of bytes of cells in memstore from flush"; 184 185 @Test 186 public void testFlush() { 187 rsm.updateFlush(1, 2, 3); 188 HELPER.assertCounter("flushTime_num_ops", 1, serverSource); 189 HELPER.assertCounter("flushMemstoreSize_num_ops", 1, serverSource); 190 HELPER.assertCounter("flushOutputSize_num_ops", 1, serverSource); 191 HELPER.assertCounter("flushedMemstoreBytes", 2, serverSource); 192 HELPER.assertCounter("flushedOutputBytes", 3, serverSource); 193 194 rsm.updateFlush(10, 20, 30); 195 HELPER.assertCounter("flushTimeNumOps", 2, serverSource); 196 HELPER.assertCounter("flushMemstoreSize_num_ops", 2, serverSource); 197 HELPER.assertCounter("flushOutputSize_num_ops", 2, serverSource); 198 HELPER.assertCounter("flushedMemstoreBytes", 22, serverSource); 199 HELPER.assertCounter("flushedOutputBytes", 33, serverSource); 200 } 201 202 @Test 203 public void testCompaction() { 204 rsm.updateCompaction(false, 1, 2, 3, 4, 5); 205 HELPER.assertCounter("compactionTime_num_ops", 1, serverSource); 206 HELPER.assertCounter("compactionInputFileCount_num_ops", 1, serverSource); 207 HELPER.assertCounter("compactionInputSize_num_ops", 1, serverSource); 208 HELPER.assertCounter("compactionOutputFileCount_num_ops", 1, serverSource); 209 HELPER.assertCounter("compactedInputBytes", 4, serverSource); 210 HELPER.assertCounter("compactedoutputBytes", 5, serverSource); 211 212 rsm.updateCompaction(false, 10, 20, 30, 40, 50); 213 HELPER.assertCounter("compactionTime_num_ops", 2, serverSource); 214 HELPER.assertCounter("compactionInputFileCount_num_ops", 2, serverSource); 215 HELPER.assertCounter("compactionInputSize_num_ops", 2, serverSource); 216 HELPER.assertCounter("compactionOutputFileCount_num_ops", 2, serverSource); 217 HELPER.assertCounter("compactedInputBytes", 44, serverSource); 218 HELPER.assertCounter("compactedoutputBytes", 55, serverSource); 219 220 // do major compaction 221 rsm.updateCompaction(true, 100, 200, 300, 400, 500); 222 223 HELPER.assertCounter("compactionTime_num_ops", 3, serverSource); 224 HELPER.assertCounter("compactionInputFileCount_num_ops", 3, serverSource); 225 HELPER.assertCounter("compactionInputSize_num_ops", 3, serverSource); 226 HELPER.assertCounter("compactionOutputFileCount_num_ops", 3, serverSource); 227 HELPER.assertCounter("compactedInputBytes", 444, serverSource); 228 HELPER.assertCounter("compactedoutputBytes", 555, serverSource); 229 230 HELPER.assertCounter("majorCompactionTime_num_ops", 1, serverSource); 231 HELPER.assertCounter("majorCompactionInputFileCount_num_ops", 1, serverSource); 232 HELPER.assertCounter("majorCompactionInputSize_num_ops", 1, serverSource); 233 HELPER.assertCounter("majorCompactionOutputFileCount_num_ops", 1, serverSource); 234 HELPER.assertCounter("majorCompactedInputBytes", 400, serverSource); 235 HELPER.assertCounter("majorCompactedoutputBytes", 500, serverSource); 236 } 237 238 @Test 239 public void testPauseMonitor() { 240 Configuration conf = new Configuration(); 241 conf.setLong(JvmPauseMonitor.INFO_THRESHOLD_KEY, 1000L); 242 conf.setLong(JvmPauseMonitor.WARN_THRESHOLD_KEY, 10000L); 243 JvmPauseMonitor monitor = new JvmPauseMonitor(conf, serverSource); 244 monitor.updateMetrics(1500, false); 245 HELPER.assertCounter("pauseInfoThresholdExceeded", 1, serverSource); 246 HELPER.assertCounter("pauseWarnThresholdExceeded", 0, serverSource); 247 HELPER.assertCounter("pauseTimeWithoutGc_num_ops", 1, serverSource); 248 HELPER.assertCounter("pauseTimeWithGc_num_ops", 0, serverSource); 249 monitor.updateMetrics(15000, true); 250 HELPER.assertCounter("pauseInfoThresholdExceeded", 1, serverSource); 251 HELPER.assertCounter("pauseWarnThresholdExceeded", 1, serverSource); 252 HELPER.assertCounter("pauseTimeWithoutGc_num_ops", 1, serverSource); 253 HELPER.assertCounter("pauseTimeWithGc_num_ops", 1, serverSource); 254 } 255 256} 257