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
.assertFalse
;
21 import static org
.junit
.Assert
.assertTrue
;
23 import java
.io
.IOException
;
25 import org
.apache
.hadoop
.conf
.Configuration
;
26 import org
.apache
.hadoop
.hbase
.CompatibilityFactory
;
27 import org
.apache
.hadoop
.hbase
.CompatibilitySingletonFactory
;
28 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
29 import org
.apache
.hadoop
.hbase
.TableName
;
30 import org
.apache
.hadoop
.hbase
.test
.MetricsAssertHelper
;
31 import org
.apache
.hadoop
.hbase
.testclassification
.RegionServerTests
;
32 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
33 import org
.junit
.ClassRule
;
34 import org
.junit
.Test
;
35 import org
.junit
.experimental
.categories
.Category
;
37 @Category({RegionServerTests
.class, SmallTests
.class})
38 public class TestMetricsTableLatencies
{
41 public static final HBaseClassTestRule CLASS_RULE
=
42 HBaseClassTestRule
.forClass(TestMetricsTableLatencies
.class);
44 public static MetricsAssertHelper HELPER
=
45 CompatibilityFactory
.getInstance(MetricsAssertHelper
.class);
48 public void testTableWrapperAggregateMetrics() throws IOException
{
49 TableName tn1
= TableName
.valueOf("table1");
50 TableName tn2
= TableName
.valueOf("table2");
51 MetricsTableLatencies latencies
= CompatibilitySingletonFactory
.getInstance(
52 MetricsTableLatencies
.class);
53 assertTrue("'latencies' is actually " + latencies
.getClass(),
54 latencies
instanceof MetricsTableLatenciesImpl
);
55 MetricsTableLatenciesImpl latenciesImpl
= (MetricsTableLatenciesImpl
) latencies
;
56 RegionServerTableMetrics tableMetrics
= new RegionServerTableMetrics(false);
58 // Metrics to each table should be disjoint
59 // N.B. each call to assertGauge removes all previously acquired metrics so we have to
60 // make the metrics call and then immediately verify it. Trying to do multiple metrics
61 // updates followed by multiple verifications will fail on the 2nd verification (as the
62 // first verification cleaned the data structures in MetricsAssertHelperImpl).
63 tableMetrics
.updateGet(tn1
, 500L);
64 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
65 tn1
, MetricsTableLatencies
.GET_TIME
+ "_" + "999th_percentile"), 500L, latenciesImpl
);
66 tableMetrics
.updatePut(tn1
, 50L);
67 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
68 tn1
, MetricsTableLatencies
.PUT_TIME
+ "_" + "99th_percentile"), 50L, latenciesImpl
);
70 tableMetrics
.updateGet(tn2
, 300L);
71 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
72 tn2
, MetricsTableLatencies
.GET_TIME
+ "_" + "999th_percentile"), 300L, latenciesImpl
);
73 tableMetrics
.updatePut(tn2
, 75L);
74 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
75 tn2
, MetricsTableLatencies
.PUT_TIME
+ "_" + "99th_percentile"), 75L, latenciesImpl
);
79 public void testTableQueryMeterSwitch() {
80 TableName tn1
= TableName
.valueOf("table1");
81 MetricsTableLatencies latencies
= CompatibilitySingletonFactory
.getInstance(
82 MetricsTableLatencies
.class);
83 assertTrue("'latencies' is actually " + latencies
.getClass(),
84 latencies
instanceof MetricsTableLatenciesImpl
);
85 MetricsTableLatenciesImpl latenciesImpl
= (MetricsTableLatenciesImpl
) latencies
;
87 Configuration conf
= new Configuration();
88 boolean enableTableQueryMeter
= conf
.getBoolean(
89 MetricsRegionServer
.RS_ENABLE_TABLE_QUERY_METER_METRICS_KEY
,
90 MetricsRegionServer
.RS_ENABLE_TABLE_QUERY_METER_METRICS_KEY_DEFAULT
);
92 assertFalse(enableTableQueryMeter
);
93 RegionServerTableMetrics tableMetrics
= new RegionServerTableMetrics(enableTableQueryMeter
);
94 tableMetrics
.updateTableReadQueryMeter(tn1
, 500L);
95 assertFalse(HELPER
.checkGaugeExists(MetricsTableLatenciesImpl
.qualifyMetricsName(
96 tn1
, MetricsTableQueryMeterImpl
.TABLE_READ_QUERY_PER_SECOND
+ "_" + "count"),
98 tableMetrics
.updateTableWriteQueryMeter(tn1
, 500L);
99 assertFalse(HELPER
.checkGaugeExists(MetricsTableLatenciesImpl
.qualifyMetricsName(
100 tn1
, MetricsTableQueryMeterImpl
.TABLE_WRITE_QUERY_PER_SECOND
+ "_" + "count"),
104 conf
.setBoolean(MetricsRegionServer
.RS_ENABLE_TABLE_QUERY_METER_METRICS_KEY
, true);
105 enableTableQueryMeter
= conf
.getBoolean(
106 MetricsRegionServer
.RS_ENABLE_TABLE_QUERY_METER_METRICS_KEY
,
107 MetricsRegionServer
.RS_ENABLE_TABLE_QUERY_METER_METRICS_KEY_DEFAULT
);
108 assertTrue(enableTableQueryMeter
);
109 tableMetrics
= new RegionServerTableMetrics(true);
110 tableMetrics
.updateTableReadQueryMeter(tn1
, 500L);
111 assertTrue(HELPER
.checkGaugeExists(MetricsTableLatenciesImpl
.qualifyMetricsName(
112 tn1
, MetricsTableQueryMeterImpl
.TABLE_READ_QUERY_PER_SECOND
+ "_" + "count"),
114 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
115 tn1
, MetricsTableQueryMeterImpl
.TABLE_READ_QUERY_PER_SECOND
+ "_" + "count"),
116 500L, latenciesImpl
);
117 tableMetrics
.updateTableWriteQueryMeter(tn1
, 500L);
118 assertTrue(HELPER
.checkGaugeExists(MetricsTableLatenciesImpl
.qualifyMetricsName(
119 tn1
, MetricsTableQueryMeterImpl
.TABLE_WRITE_QUERY_PER_SECOND
+ "_" + "count"),
121 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
122 tn1
, MetricsTableQueryMeterImpl
.TABLE_WRITE_QUERY_PER_SECOND
+ "_" + "count"),
123 500L, latenciesImpl
);