View Javadoc

1   /**
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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  package org.apache.hadoop.hbase.regionserver;
19  
20  import org.apache.hadoop.conf.Configuration;
21  import org.apache.hadoop.hbase.*;
22  import org.apache.hadoop.hbase.client.*;
23  import org.apache.hadoop.hbase.test.MetricsAssertHelper;
24  import org.apache.hadoop.hbase.testclassification.MediumTests;
25  import org.apache.hadoop.hbase.util.Bytes;
26  import org.apache.hadoop.hbase.util.Threads;
27  import org.apache.log4j.Level;
28  import org.apache.log4j.Logger;
29  import org.junit.AfterClass;
30  import org.junit.BeforeClass;
31  import org.junit.Ignore;
32  import org.junit.Test;
33  import org.junit.experimental.categories.Category;
34  
35  import static org.junit.Assert.*;
36  
37  import java.io.IOException;
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  
42  @Category(MediumTests.class)
43  public class TestRegionServerMetrics {
44    private static MetricsAssertHelper metricsHelper;
45  
46    static {
47      Logger.getLogger("org.apache.hadoop.hbase").setLevel(Level.DEBUG);
48    }
49  
50    private static MiniHBaseCluster cluster;
51    private static HRegionServer rs;
52    private static Configuration conf;
53    private static HBaseTestingUtility TEST_UTIL;
54    private static MetricsRegionServer metricsRegionServer;
55    private static MetricsRegionServerSource serverSource;
56    private static final int NUM_SCAN_NEXT = 30;
57    private static int numScanNext = 0;
58  
59    @BeforeClass
60    public static void startCluster() throws Exception {
61      metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class);
62      TEST_UTIL = new HBaseTestingUtility();
63      conf = TEST_UTIL.getConfiguration();
64      conf.getLong("hbase.splitlog.max.resubmit", 0);
65      // Make the failure test faster
66      conf.setInt("zookeeper.recovery.retry", 0);
67      conf.setInt(HConstants.REGIONSERVER_INFO_PORT, -1);
68  
69      TEST_UTIL.startMiniCluster(1, 1);
70      cluster = TEST_UTIL.getHBaseCluster();
71  
72      cluster.waitForActiveAndReadyMaster();
73  
74      while (cluster.getLiveRegionServerThreads().size() < 1) {
75        Threads.sleep(100);
76      }
77  
78      rs = cluster.getRegionServer(0);
79      metricsRegionServer = rs.getRegionServerMetrics();
80      serverSource = metricsRegionServer.getMetricsSource();
81    }
82  
83    @AfterClass
84    public static void after() throws Exception {
85      if (TEST_UTIL != null) {
86        TEST_UTIL.shutdownMiniCluster();
87      }
88    }
89  
90    @Test(timeout = 300000)
91    public void testRegionCount() throws Exception {
92      String regionMetricsKey = "regionCount";
93      long regions = metricsHelper.getGaugeLong(regionMetricsKey, serverSource);
94      // Creating a table should add one region
95      TEST_UTIL.createTable(TableName.valueOf("table"), Bytes.toBytes("cf"));
96      metricsHelper.assertGaugeGt(regionMetricsKey, regions, serverSource);
97    }
98  
99    @Test
100   public void testLocalFiles() throws Exception {
101     metricsHelper.assertGauge("percentFilesLocal", 0, serverSource);
102     metricsHelper.assertGauge("percentFilesLocalSecondaryRegions", 0, serverSource);
103   }
104 
105   @Test
106   public void testRequestCount() throws Exception {
107     String tableNameString = "testRequestCount";
108     TableName tName = TableName.valueOf(tableNameString);
109     byte[] cfName = Bytes.toBytes("d");
110     byte[] row = Bytes.toBytes("rk");
111     byte[] qualifier = Bytes.toBytes("qual");
112     byte[] initValue = Bytes.toBytes("Value");
113 
114     TEST_UTIL.createTable(tName, cfName);
115 
116     Connection connection = TEST_UTIL.getConnection();
117     connection.getTable(tName).close(); //wait for the table to come up.
118 
119     // Do a first put to be sure that the connection is established, meta is there and so on.
120     Table table = connection.getTable(tName);
121     Put p = new Put(row);
122     p.add(cfName, qualifier, initValue);
123     table.put(p);
124 
125     metricsRegionServer.getRegionServerWrapper().forceRecompute();
126     long requests = metricsHelper.getCounter("totalRequestCount", serverSource);
127     long rowActionRequests = metricsHelper.getCounter("totalRowActionRequestCount", serverSource);
128     long readRequests = metricsHelper.getCounter("readRequestCount", serverSource);
129     long writeRequests = metricsHelper.getCounter("writeRequestCount", serverSource);
130 
131     for (int i=0; i< 30; i++) {
132       table.put(p);
133     }
134 
135     metricsRegionServer.getRegionServerWrapper().forceRecompute();
136     metricsHelper.assertCounter("totalRequestCount", requests + 30, serverSource);
137     metricsHelper.assertCounter("totalRowActionRequestCount", rowActionRequests + 30, serverSource);
138     metricsHelper.assertCounter("readRequestCount", readRequests, serverSource);
139     metricsHelper.assertCounter("writeRequestCount", writeRequests + 30, serverSource);
140 
141     Get g = new Get(row);
142     for (int i=0; i< 10; i++) {
143       table.get(g);
144     }
145 
146     metricsRegionServer.getRegionServerWrapper().forceRecompute();
147     metricsHelper.assertCounter("totalRequestCount", requests + 40, serverSource);
148     metricsHelper.assertCounter("totalRowActionRequestCount", rowActionRequests + 40, serverSource);
149     metricsHelper.assertCounter("readRequestCount", readRequests + 10, serverSource);
150     metricsHelper.assertCounter("writeRequestCount", writeRequests + 30, serverSource);
151 
152     try (RegionLocator locator = connection.getRegionLocator(tName)) {
153       for ( HRegionLocation location: locator.getAllRegionLocations()) {
154         HRegionInfo i = location.getRegionInfo();
155         MetricsRegionAggregateSource agg = rs.getRegion(i.getRegionName())
156             .getMetrics()
157             .getSource()
158             .getAggregateSource();
159         String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
160             "_table_"+tableNameString +
161             "_region_" + i.getEncodedName()+
162             "_metric";
163         metricsHelper.assertCounter(prefix + "_getCount", 10, agg);
164         metricsHelper.assertCounter(prefix + "_putCount", 31, agg);
165       }
166     }
167     List<Get> gets = new ArrayList<Get>();
168     for (int i=0; i< 10; i++) {
169       gets.add(new Get(row));
170     }
171     table.get(gets);
172 
173     // By default, master doesn't host meta now.
174     // Adding some meta related requests
175     requests += 1;
176     rowActionRequests += 1;
177     readRequests ++;
178 
179     metricsRegionServer.getRegionServerWrapper().forceRecompute();
180     metricsHelper.assertCounter("totalRequestCount", requests + 41, serverSource);
181     metricsHelper.assertCounter("totalRowActionRequestCount", rowActionRequests + 50, serverSource);
182     metricsHelper.assertCounter("readRequestCount", readRequests + 20, serverSource);
183     metricsHelper.assertCounter("writeRequestCount", writeRequests + 30, serverSource);
184 
185     List<Put> puts = new ArrayList<>();
186     for (int i=0; i< 30; i++) {
187       // put multiple lines for latter scan
188       Put put = new Put(Bytes.toBytes("" + i + "row")).addColumn(cfName, qualifier, initValue);
189       puts.add(put);
190     }
191     table.put(puts);
192 
193     metricsRegionServer.getRegionServerWrapper().forceRecompute();
194     metricsHelper.assertCounter("totalRequestCount", requests + 42, serverSource);
195     metricsHelper.assertCounter("totalRowActionRequestCount", rowActionRequests + 80, serverSource);
196     metricsHelper.assertCounter("readRequestCount", readRequests + 20, serverSource);
197     metricsHelper.assertCounter("writeRequestCount", writeRequests + 60, serverSource);
198 
199     doScan(table, 10, false);
200     metricsRegionServer.getRegionServerWrapper().forceRecompute();
201     metricsHelper.assertCounter("totalRequestCount", requests + 52, serverSource);
202     metricsHelper.assertCounter("totalRowActionRequestCount", rowActionRequests + 90, serverSource);
203     metricsHelper.assertCounter("readRequestCount", readRequests + 30, serverSource);
204     metricsHelper.assertCounter("writeRequestCount", writeRequests + 60, serverSource);
205 
206     doScan(table, 10, true);
207     metricsRegionServer.getRegionServerWrapper().forceRecompute();
208     metricsHelper.assertCounter("totalRequestCount", requests + 53, serverSource);
209     metricsHelper.assertCounter("totalRowActionRequestCount", rowActionRequests + 100, serverSource);
210     metricsHelper.assertCounter("readRequestCount", readRequests + 40, serverSource);
211     metricsHelper.assertCounter("writeRequestCount", writeRequests + 60, serverSource);
212 
213     table.close();
214   }
215 
216   public void doScan(Table table, int n, boolean caching) throws IOException {
217     Scan scan = new Scan();
218     if (caching) {
219       scan.setCaching(n);
220     } else {
221       scan.setCaching(1);
222     }
223     ResultScanner scanner = table.getScanner(scan);
224     for (int i = 0; i < n; i++) {
225       scanner.next();
226     }
227   }
228 
229   @Test
230   public void testGet() throws Exception {
231     String tableNameString = "testGet";
232     TableName tName = TableName.valueOf(tableNameString);
233     byte[] cfName = Bytes.toBytes("d");
234     byte[] row = Bytes.toBytes("rk");
235     byte[] qualifier = Bytes.toBytes("qual");
236     byte[] initValue = Bytes.toBytes("Value");
237 
238     TEST_UTIL.createTable(tName, cfName);
239 
240     Connection connection = TEST_UTIL.getConnection();
241     connection.getTable(tName).close(); //wait for the table to come up.
242 
243     // Do a first put to be sure that the connection is established, meta is there and so on.
244     Table table = connection.getTable(tName);
245     Put p = new Put(row);
246     p.addColumn(cfName, qualifier, initValue);
247     table.put(p);
248 
249     Get g = new Get(row);
250     for (int i=0; i< 10; i++) {
251       table.get(g);
252     }
253 
254     metricsRegionServer.getRegionServerWrapper().forceRecompute();
255 
256     try (RegionLocator locator = connection.getRegionLocator(tName)) {
257       for ( HRegionLocation location: locator.getAllRegionLocations()) {
258         HRegionInfo i = location.getRegionInfo();
259         MetricsRegionAggregateSource agg = rs.getRegion(i.getRegionName())
260           .getMetrics()
261           .getSource()
262           .getAggregateSource();
263         String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
264           "_table_"+tableNameString +
265           "_region_" + i.getEncodedName()+
266           "_metric";
267         metricsHelper.assertCounter(prefix + "_getCount", 10, agg);
268         metricsHelper.assertCounter(prefix + "_getCount", 10, agg);
269       }
270       metricsHelper.assertCounterGt("Get_num_ops", 10, serverSource);
271     }
272     table.close();
273   }
274 
275   @Test
276   public void testMutationsWithoutWal() throws Exception {
277     TableName tableName = TableName.valueOf("testMutationsWithoutWal");
278     byte[] cf = Bytes.toBytes("d");
279     byte[] row = Bytes.toBytes("rk");
280     byte[] qualifier = Bytes.toBytes("qual");
281     byte[] val = Bytes.toBytes("Value");
282 
283     metricsRegionServer.getRegionServerWrapper().forceRecompute();
284 
285     TEST_UTIL.createTable(tableName, cf);
286 
287     Table t = new HTable(conf, tableName);
288 
289     Put p = new Put(row);
290     p.add(cf, qualifier, val);
291     p.setDurability(Durability.SKIP_WAL);
292 
293     t.put(p);
294 
295     metricsRegionServer.getRegionServerWrapper().forceRecompute();
296     metricsHelper.assertGauge("mutationsWithoutWALCount", 1, serverSource);
297     long minLength = row.length + cf.length + qualifier.length + val.length;
298     metricsHelper.assertGaugeGt("mutationsWithoutWALSize", minLength, serverSource);
299 
300     t.close();
301   }
302 
303   @Test
304   public void testStoreCount() throws Exception {
305     TableName tableName = TableName.valueOf("testStoreCount");
306     byte[] cf = Bytes.toBytes("d");
307     byte[] row = Bytes.toBytes("rk");
308     byte[] qualifier = Bytes.toBytes("qual");
309     byte[] val = Bytes.toBytes("Value");
310 
311     metricsRegionServer.getRegionServerWrapper().forceRecompute();
312     long stores = metricsHelper.getGaugeLong("storeCount", serverSource);
313     long storeFiles = metricsHelper.getGaugeLong("storeFileCount", serverSource);
314 
315     TEST_UTIL.createTable(tableName, cf);
316 
317     //Force a hfile.
318     Table t = new HTable(conf, tableName);
319     Put p = new Put(row);
320     p.add(cf, qualifier, val);
321     t.put(p);
322     TEST_UTIL.getHBaseAdmin().flush(tableName);
323 
324     metricsRegionServer.getRegionServerWrapper().forceRecompute();
325     metricsHelper.assertGauge("storeCount", stores +1, serverSource);
326     metricsHelper.assertGauge("storeFileCount", storeFiles + 1, serverSource);
327 
328     t.close();
329   }
330 
331   @Test
332   public void testStoreFileAge() throws Exception {
333     TableName tableName = TableName.valueOf("testStoreFileAge");
334     byte[] cf = Bytes.toBytes("d");
335     byte[] row = Bytes.toBytes("rk");
336     byte[] qualifier = Bytes.toBytes("qual");
337     byte[] val = Bytes.toBytes("Value");
338 
339     //Force a hfile.
340     Table t = TEST_UTIL.createTable(tableName, cf);
341     Put p = new Put(row);
342     p.addColumn(cf, qualifier, val);
343     t.put(p);
344     TEST_UTIL.getHBaseAdmin().flush(tableName);
345 
346     metricsRegionServer.getRegionServerWrapper().forceRecompute();
347     assertTrue(metricsHelper.getGaugeLong("maxStoreFileAge", serverSource) > 0);
348     assertTrue(metricsHelper.getGaugeLong("minStoreFileAge", serverSource) > 0);
349     assertTrue(metricsHelper.getGaugeLong("avgStoreFileAge", serverSource) > 0);
350 
351     t.close();
352   }
353 
354   @Test
355   public void testCheckAndPutCount() throws Exception {
356     String tableNameString = "testCheckAndPutCount";
357     TableName tableName = TableName.valueOf(tableNameString);
358     byte[] cf = Bytes.toBytes("d");
359     byte[] row = Bytes.toBytes("rk");
360     byte[] qualifier = Bytes.toBytes("qual");
361     byte[] valOne = Bytes.toBytes("Value");
362     byte[] valTwo = Bytes.toBytes("ValueTwo");
363     byte[] valThree = Bytes.toBytes("ValueThree");
364 
365     TEST_UTIL.createTable(tableName, cf);
366     Table t = new HTable(conf, tableName);
367     Put p = new Put(row);
368     p.add(cf, qualifier, valOne);
369     t.put(p);
370 
371     Put pTwo = new Put(row);
372     pTwo.add(cf, qualifier, valTwo);
373     t.checkAndPut(row, cf, qualifier, valOne, pTwo);
374 
375     Put pThree = new Put(row);
376     pThree.add(cf, qualifier, valThree);
377     t.checkAndPut(row, cf, qualifier, valOne, pThree);
378 
379     metricsRegionServer.getRegionServerWrapper().forceRecompute();
380     metricsHelper.assertCounter("checkMutateFailedCount", 1, serverSource);
381     metricsHelper.assertCounter("checkMutatePassedCount", 1, serverSource);
382 
383     t.close();
384   }
385 
386   @Test
387   public void testIncrement() throws Exception {
388     String tableNameString = "testIncrement";
389     TableName tableName = TableName.valueOf(tableNameString);
390     byte[] cf = Bytes.toBytes("d");
391     byte[] row = Bytes.toBytes("rk");
392     byte[] qualifier = Bytes.toBytes("qual");
393     byte[] val = Bytes.toBytes(0l);
394 
395 
396     TEST_UTIL.createTable(tableName, cf);
397     Table t = new HTable(conf, tableName);
398 
399     Put p = new Put(row);
400     p.add(cf, qualifier, val);
401     t.put(p);
402 
403     for(int count = 0; count< 13; count++) {
404       Increment inc = new Increment(row);
405       inc.addColumn(cf, qualifier, 100);
406       t.increment(inc);
407     }
408 
409     metricsRegionServer.getRegionServerWrapper().forceRecompute();
410     metricsHelper.assertCounter("incrementNumOps", 13, serverSource);
411 
412     t.close();
413   }
414 
415   @Test
416   public void testAppend() throws Exception {
417     String tableNameString = "testAppend";
418     TableName tableName = TableName.valueOf(tableNameString);
419     byte[] cf = Bytes.toBytes("d");
420     byte[] row = Bytes.toBytes("rk");
421     byte[] qualifier = Bytes.toBytes("qual");
422     byte[] val = Bytes.toBytes("One");
423 
424 
425     TEST_UTIL.createTable(tableName, cf);
426     Table t = new HTable(conf, tableName);
427 
428     Put p = new Put(row);
429     p.add(cf, qualifier, val);
430     t.put(p);
431 
432     for(int count = 0; count< 73; count++) {
433       Append append = new Append(row);
434       append.add(cf, qualifier, Bytes.toBytes(",Test"));
435       t.append(append);
436     }
437 
438     metricsRegionServer.getRegionServerWrapper().forceRecompute();
439     metricsHelper.assertCounter("appendNumOps", 73, serverSource);
440 
441     t.close();
442   }
443 
444   @Test
445   public void testScanSize() throws IOException {
446     String tableNameString = "testScanSize";
447     TableName tableName = TableName.valueOf(tableNameString);
448     byte[] cf = Bytes.toBytes("d");
449     byte[] qualifier = Bytes.toBytes("qual");
450     byte[] val = Bytes.toBytes("One");
451 
452     List<Put> puts = new ArrayList<>();
453     for (int insertCount =0; insertCount < 100; insertCount++) {
454       Put p = new Put(Bytes.toBytes("" + insertCount + "row"));
455       p.add(cf, qualifier, val);
456       puts.add(p);
457     }
458     try (HTable t = TEST_UTIL.createTable(tableName, cf)) {
459       t.put(puts);
460 
461       Scan s = new Scan();
462       s.setBatch(1);
463       s.setCaching(1);
464       ResultScanner resultScanners = t.getScanner(s);
465 
466       for (int nextCount = 0; nextCount < NUM_SCAN_NEXT; nextCount++) {
467         Result result = resultScanners.next();
468         assertNotNull(result);
469         assertEquals(1, result.size());
470       }
471     }
472     numScanNext += NUM_SCAN_NEXT;
473     try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
474       for ( HRegionLocation location: locator.getAllRegionLocations()) {
475         HRegionInfo i = location.getRegionInfo();
476         MetricsRegionAggregateSource agg = rs.getRegion(i.getRegionName())
477             .getMetrics()
478             .getSource()
479             .getAggregateSource();
480         String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
481             "_table_"+tableNameString +
482             "_region_" + i.getEncodedName()+
483             "_metric";
484         metricsHelper.assertCounter(prefix + "_scanCount", NUM_SCAN_NEXT, agg);
485       }
486       metricsHelper.assertCounterGt("ScanSize_num_ops", numScanNext, serverSource);
487     }
488     try (Admin admin = TEST_UTIL.getHBaseAdmin()) {
489       admin.disableTable(tableName);
490       admin.deleteTable(tableName);
491     }
492   }
493 
494   @Test
495   public void testScanTime() throws IOException {
496     String tableNameString = "testScanTime";
497     TableName tableName = TableName.valueOf(tableNameString);
498     byte[] cf = Bytes.toBytes("d");
499     byte[] qualifier = Bytes.toBytes("qual");
500     byte[] val = Bytes.toBytes("One");
501 
502     List<Put> puts = new ArrayList<>();
503     for (int insertCount =0; insertCount < 100; insertCount++) {
504       Put p = new Put(Bytes.toBytes("" + insertCount + "row"));
505       p.addColumn(cf, qualifier, val);
506       puts.add(p);
507     }
508     try (Table t = TEST_UTIL.createTable(tableName, cf)) {
509       t.put(puts);
510 
511       Scan s = new Scan();
512       s.setBatch(1);
513       s.setCaching(1);
514       ResultScanner resultScanners = t.getScanner(s);
515 
516       for (int nextCount = 0; nextCount < NUM_SCAN_NEXT; nextCount++) {
517         Result result = resultScanners.next();
518         assertNotNull(result);
519         assertEquals(1, result.size());
520       }
521     }
522     numScanNext += NUM_SCAN_NEXT;
523     try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
524       for ( HRegionLocation location: locator.getAllRegionLocations()) {
525         HRegionInfo i = location.getRegionInfo();
526         MetricsRegionAggregateSource agg = rs.getRegion(i.getRegionName())
527           .getMetrics()
528           .getSource()
529           .getAggregateSource();
530         String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
531           "_table_"+tableNameString +
532           "_region_" + i.getEncodedName()+
533           "_metric";
534         metricsHelper.assertCounter(prefix + "_scanCount", NUM_SCAN_NEXT, agg);
535       }
536       metricsHelper.assertCounterGt("ScanTime_num_ops", numScanNext, serverSource);
537     }
538     try (Admin admin = TEST_UTIL.getHBaseAdmin()) {
539       admin.disableTable(tableName);
540       admin.deleteTable(tableName);
541     }
542   }
543 
544   @Test
545   public void testScanSizeForSmallScan() throws IOException {
546     String tableNameString = "testScanSizeSmall";
547     TableName tableName = TableName.valueOf(tableNameString);
548     byte[] cf = Bytes.toBytes("d");
549     byte[] qualifier = Bytes.toBytes("qual");
550     byte[] val = Bytes.toBytes("One");
551 
552     List<Put> puts = new ArrayList<>();
553     for (int insertCount =0; insertCount < 100; insertCount++) {
554       Put p = new Put(Bytes.toBytes("" + insertCount + "row"));
555       p.add(cf, qualifier, val);
556       puts.add(p);
557     }
558     try (HTable t = TEST_UTIL.createTable(tableName, cf)) {
559       t.put(puts);
560 
561       Scan s = new Scan();
562       s.setSmall(true);
563       s.setCaching(1);
564       ResultScanner resultScanners = t.getScanner(s);
565 
566       for (int nextCount = 0; nextCount < NUM_SCAN_NEXT; nextCount++) {
567         Result result = resultScanners.next();
568         assertNotNull(result);
569         assertEquals(1, result.size());
570       }
571     }
572     numScanNext += NUM_SCAN_NEXT;
573     try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
574       int cnt = 0;
575       for (HRegionLocation location: locator.getAllRegionLocations()) {
576         cnt++;
577         HRegionInfo i = location.getRegionInfo();
578         MetricsRegionAggregateSource agg = rs.getRegion(i.getRegionName())
579             .getMetrics()
580             .getSource()
581             .getAggregateSource();
582         String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
583             "_table_"+tableNameString +
584             "_region_" + i.getEncodedName()+
585             "_metric";
586         metricsHelper.assertCounter(prefix + "_scanCount", NUM_SCAN_NEXT, agg);
587       }
588       metricsHelper.assertCounterGt("ScanSize_num_ops", numScanNext, serverSource);
589     }
590     try (Admin admin = TEST_UTIL.getHBaseAdmin()) {
591       admin.disableTable(tableName);
592       admin.deleteTable(tableName);
593     }
594   }
595  
596   @Test
597   @Ignore
598   public void testRangeCountMetrics() throws Exception {
599     String tableNameString = "testRangeCountMetrics";
600     final long[] timeranges =
601         { 1, 3, 10, 30, 100, 300, 1000, 3000, 10000, 30000, 60000, 120000, 300000, 600000 };
602     final String timeRangeType = "TimeRangeCount";
603     final String timeRangeMetricName = "Mutate";
604     boolean timeRangeCountUpdated = false;
605 
606     TableName tName = TableName.valueOf(tableNameString);
607     byte[] cfName = Bytes.toBytes("d");
608     byte[] row = Bytes.toBytes("rk");
609     byte[] qualifier = Bytes.toBytes("qual");
610     byte[] initValue = Bytes.toBytes("Value");
611 
612     TEST_UTIL.createTable(tName, cfName);
613 
614     Connection connection = TEST_UTIL.getConnection();
615     connection.getTable(tName).close(); // wait for the table to come up.
616 
617     // Do a first put to be sure that the connection is established, meta is there and so on.
618     Table table = connection.getTable(tName);
619     Put p = new Put(row);
620     p.addColumn(cfName, qualifier, initValue);
621     table.put(p);
622 
623     // do some puts and gets
624     for (int i = 0; i < 10; i++) {
625       table.put(p);
626     }
627 
628     Get g = new Get(row);
629     for (int i = 0; i < 10; i++) {
630       table.get(g);
631     }
632 
633     metricsRegionServer.getRegionServerWrapper().forceRecompute();
634 
635     // Check some time range counters were updated
636     long prior = 0;
637 
638     String dynamicMetricName;
639     for (int i = 0; i < timeranges.length; i++) {
640       dynamicMetricName =
641           timeRangeMetricName + "_" + timeRangeType + "_" + prior + "-" + timeranges[i];
642       if (metricsHelper.checkCounterExists(dynamicMetricName, serverSource)) {
643         long count = metricsHelper.getGaugeLong(dynamicMetricName, serverSource);
644         if (count > 0) {
645           timeRangeCountUpdated = true;
646           break;
647         }
648       }
649       prior = timeranges[i];
650     }
651     dynamicMetricName =
652         timeRangeMetricName + "_" + timeRangeType + "_" + timeranges[timeranges.length - 1] + "-inf";
653     if (metricsHelper.checkCounterExists(dynamicMetricName, serverSource)) {
654       long count = metricsHelper.getCounter(dynamicMetricName, serverSource);
655       if (count > 0) {
656         timeRangeCountUpdated = true;
657       }
658     }
659     assertEquals(true, timeRangeCountUpdated);
660 
661     table.close();
662   }
663 
664   @Test
665   public void testAverageRegionSize() throws Exception {
666     TableName tableName = TableName.valueOf("testAverageRegionSize");
667     byte[] cf = Bytes.toBytes("d");
668     byte[] row = Bytes.toBytes("rk");
669     byte[] qualifier = Bytes.toBytes("qual");
670     byte[] val = Bytes.toBytes("Value");
671 
672     //Force a hfile.
673     Table t = TEST_UTIL.createTable(tableName, cf);
674     Put p = new Put(row);
675     p.addColumn(cf, qualifier, val);
676     t.put(p);
677     TEST_UTIL.getHBaseAdmin().flush(tableName);
678 
679     metricsRegionServer.getRegionServerWrapper().forceRecompute();
680     assertTrue(metricsHelper.getGaugeDouble("averageRegionSize", serverSource) > 0.0);
681 
682     t.close();
683   }
684 }