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