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 org.apache.hadoop.conf.Configuration;
021import org.apache.hadoop.hbase.CompatibilityFactory;
022import org.apache.hadoop.hbase.test.MetricsAssertHelper;
023import org.apache.hadoop.hbase.testclassification.RegionServerTests;
024import org.apache.hadoop.hbase.testclassification.SmallTests;
025import org.junit.jupiter.api.Tag;
026import org.junit.jupiter.api.Test;
027
028@Tag(RegionServerTests.TAG)
029@Tag(SmallTests.TAG)
030public class TestMetricsRegion {
031
032  public MetricsAssertHelper HELPER = CompatibilityFactory.getInstance(MetricsAssertHelper.class);
033
034  @Test
035  public void testRegionWrapperMetrics() {
036    MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub(), new Configuration());
037    MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource();
038
039    HELPER.assertGauge(
040      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 101,
041      agg);
042    HELPER.assertGauge(
043      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount",
044      102, agg);
045    HELPER.assertGauge(
046      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_maxStoreFileAge",
047      2, agg);
048    HELPER.assertGauge(
049      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_minStoreFileAge",
050      2, agg);
051    HELPER.assertGauge(
052      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_avgStoreFileAge",
053      2, agg);
054    HELPER.assertGauge(
055      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_numReferenceFiles",
056      2, agg);
057    HELPER.assertGauge(
058      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 103,
059      agg);
060    HELPER.assertGauge(
061      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreHeapSize",
062      104, agg);
063    HELPER.assertGauge(
064      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreOffHeapSize",
065      105, agg);
066    HELPER.assertCounter(
067      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_cpRequestCount",
068      108, agg);
069    HELPER
070      .assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_"
071        + "filteredReadRequestCount", 107, agg);
072    HELPER.assertCounter(
073      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", 0,
074      agg);
075    mr.close();
076
077    // test region with replica id > 0
078    mr = new MetricsRegion(new MetricsRegionWrapperStub(1), new Configuration());
079    agg = mr.getSource().getAggregateSource();
080    HELPER.assertGauge(
081      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_storeCount",
082      101, agg);
083    HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
084      + "_metric_storeFileCount", 102, agg);
085    HELPER.assertGauge(
086      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_memstoreSize",
087      103, agg);
088    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
089      + "_metric_cpRequestCount", 108, agg);
090    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
091      + "_metric_filteredReadRequestCount", 107, agg);
092    HELPER.assertCounter(
093      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_replicaid", 1,
094      agg);
095    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
096      + "_metric_compactionsQueuedCount", 4, agg);
097    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
098      + "_metric_flushesQueuedCount", 6, agg);
099    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
100      + "_metric_maxCompactionQueueSize", 4, agg);
101    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
102      + "_metric_maxFlushQueueSize", 6, agg);
103    mr.close();
104  }
105}