From e0768e081488da5ee6ee2efd2facd14d1565bb21 Mon Sep 17 00:00:00 2001 From: eclark Date: Wed, 25 Sep 2013 21:41:05 +0000 Subject: [PATCH] HBASE-9650 Per region metrics are not showing up for system tables. git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1526309 13f79535-47bb-0310-9956-ffa450edef68 --- .../regionserver/MetricsRegionWrapper.java | 6 +++++ .../regionserver/MetricsRegionSourceImpl.java | 20 +++++++------- .../thrift/MetricsThriftServerSourceImpl.java | 23 ++++++++-------- .../TestMetricsRegionSourceImpl.java | 19 +++++++++----- .../regionserver/MetricsRegionSourceImpl.java | 20 +++++++------- .../thrift/MetricsThriftServerSourceImpl.java | 26 +++++++++---------- .../TestMetricsRegionSourceImpl.java | 19 +++++++++----- .../MetricsRegionWrapperImpl.java | 17 +++++++++--- .../MetricsRegionWrapperStub.java | 5 ++++ .../hbase/regionserver/TestMetricsRegion.java | 6 ++--- .../regionserver/TestRegionServerMetrics.java | 16 ++++++++---- 11 files changed, 107 insertions(+), 70 deletions(-) diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java index 2c533ea871d..e1929c4f138 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java @@ -31,6 +31,12 @@ public interface MetricsRegionWrapper { */ String getTableName(); + /** + * Get the name of the namespace this table is in. + * @return String version of the namespace. Can't be empty. + */ + String getNamespace(); + /** * Get the name of the region. * diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java index 385c6456c14..93024b4b474 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java @@ -24,7 +24,7 @@ import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.impl.JmxCacheBuster; import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry; import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong; -import org.apache.hadoop.metrics2.lib.MetricMutableStat; +import org.apache.hadoop.metrics2.lib.MetricMutableHistogram; public class MetricsRegionSourceImpl implements MetricsRegionSource { @@ -46,8 +46,8 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { private MetricMutableCounterLong regionIncrement; private MetricMutableCounterLong regionAppend; - private MetricMutableStat regionGet; - private MetricMutableStat regionScanNext; + private MetricMutableHistogram regionGet; + private MetricMutableHistogram regionScanNext; public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper, MetricsRegionAggregateSourceImpl aggregate) { @@ -56,14 +56,14 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { agg.register(this); LOG.debug("Creating new MetricsRegionSourceImpl for table " + - regionWrapper.getTableName() + - " " + - regionWrapper.getRegionName()); + regionWrapper.getTableName() + " " + regionWrapper.getRegionName()); registry = agg.getMetricsRegistry(); - regionNamePrefix = "table." + regionWrapper.getTableName() + "." - + "region." + regionWrapper.getRegionName() + "."; + regionNamePrefix = "namespace_" + regionWrapper.getNamespace() + + "_table_" + regionWrapper.getTableName() + + "_region_" + regionWrapper.getRegionName() + + "_metric_"; String suffix = "Count"; @@ -81,10 +81,10 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { regionAppend = registry.getLongCounter(regionAppendKey, 0l); regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY; - regionGet = registry.newStat(regionGetKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); + regionGet = registry.newHistogram(regionGetKey); regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY; - regionScanNext = registry.newStat(regionScanNextKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); + regionScanNext = registry.newHistogram(regionScanNextKey); } @Override diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java index 248eee47629..112a6a3cb9c 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.thrift; import org.apache.hadoop.hbase.metrics.BaseSourceImpl; import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MetricMutableHistogram; import org.apache.hadoop.metrics2.lib.MetricMutableStat; /** @@ -31,12 +32,12 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements MetricsThriftServerSource { - private MetricMutableStat batchGetStat; - private MetricMutableStat batchMutateStat; - private MetricMutableStat queueTimeStat; + private MetricMutableHistogram batchGetStat; + private MetricMutableHistogram batchMutateStat; + private MetricMutableHistogram queueTimeStat; - private MetricMutableStat thriftCallStat; - private MetricMutableStat thriftSlowCallStat; + private MetricMutableHistogram thriftCallStat; + private MetricMutableHistogram thriftSlowCallStat; private MetricMutableGaugeLong callQueueLenGauge; @@ -51,11 +52,11 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements @Override public void init() { super.init(); - batchGetStat = getMetricsRegistry().newStat(BATCH_GET_KEY, "", "Keys", "Ops"); - batchMutateStat = getMetricsRegistry().newStat(BATCH_MUTATE_KEY, "", "Keys", "Ops"); - queueTimeStat = getMetricsRegistry().newStat(TIME_IN_QUEUE_KEY); - thriftCallStat = getMetricsRegistry().newStat(THRIFT_CALL_KEY); - thriftSlowCallStat = getMetricsRegistry().newStat(SLOW_THRIFT_CALL_KEY); + batchGetStat = getMetricsRegistry().newHistogram(BATCH_GET_KEY); + batchMutateStat = getMetricsRegistry().newHistogram(BATCH_MUTATE_KEY); + queueTimeStat = getMetricsRegistry().newHistogram(TIME_IN_QUEUE_KEY); + thriftCallStat = getMetricsRegistry().newHistogram(THRIFT_CALL_KEY); + thriftSlowCallStat = getMetricsRegistry().newHistogram(SLOW_THRIFT_CALL_KEY); callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0); } @@ -81,7 +82,7 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements @Override public void incMethodTime(String name, long time) { - MetricMutableStat s = getMetricsRegistry().newStat(name); + MetricMutableHistogram s = getMetricsRegistry().getHistogram(name); s.add(time); } diff --git a/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java b/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java index 89c0762e6d9..76319da3c52 100644 --- a/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java +++ b/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java @@ -60,7 +60,12 @@ public class TestMetricsRegionSourceImpl { @Override public String getTableName() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; + } + + @Override + public String getNamespace() { + return null; } @Override @@ -70,32 +75,32 @@ public class TestMetricsRegionSourceImpl { @Override public long getNumStores() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getNumStoreFiles() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getMemstoreSize() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getStoreFileSize() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getReadRequestCount() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getWriteRequestCount() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } } } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java index 05eadfce4f7..1e548bcccae 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java @@ -26,7 +26,7 @@ import org.apache.hadoop.metrics2.impl.JmxCacheBuster; import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry; import org.apache.hadoop.metrics2.lib.Interns; import org.apache.hadoop.metrics2.lib.MutableCounterLong; -import org.apache.hadoop.metrics2.lib.MutableStat; +import org.apache.hadoop.metrics2.lib.MutableHistogram; @InterfaceAudience.Private public class MetricsRegionSourceImpl implements MetricsRegionSource { @@ -52,8 +52,8 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { private MutableCounterLong regionIncrement; private MutableCounterLong regionAppend; - private MutableStat regionGet; - private MutableStat regionScanNext; + private MutableHistogram regionGet; + private MutableHistogram regionScanNext; public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper, MetricsRegionAggregateSourceImpl aggregate) { @@ -62,14 +62,14 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { agg.register(this); LOG.debug("Creating new MetricsRegionSourceImpl for table " + - regionWrapper.getTableName() + - " " + - regionWrapper.getRegionName()); + regionWrapper.getTableName() + " " + regionWrapper.getRegionName()); registry = agg.getMetricsRegistry(); - regionNamePrefix = "table." + regionWrapper.getTableName() + "." - + "region." + regionWrapper.getRegionName() + "."; + regionNamePrefix = "namespace_" + regionWrapper.getNamespace() + + "_table_" + regionWrapper.getTableName() + + "_region_" + regionWrapper.getRegionName() + + "_metric_"; String suffix = "Count"; @@ -86,10 +86,10 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { regionAppend = registry.getLongCounter(regionAppendKey, 0l); regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY; - regionGet = registry.newStat(regionGetKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); + regionGet = registry.newHistogram(regionGetKey); regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY; - regionScanNext = registry.newStat(regionScanNextKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); + regionScanNext = registry.newHistogram(regionScanNextKey); } @Override diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java index 0c625606ff2..0f8780e4321 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java @@ -21,7 +21,7 @@ package org.apache.hadoop.hbase.thrift; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.hbase.metrics.BaseSourceImpl; import org.apache.hadoop.metrics2.lib.MutableGaugeLong; -import org.apache.hadoop.metrics2.lib.MutableStat; +import org.apache.hadoop.metrics2.lib.MutableHistogram; /** * Hadoop 2 version of MetricsThriftServerSource{@link org.apache.hadoop.hbase.thrift.MetricsThriftServerSource} @@ -32,12 +32,12 @@ import org.apache.hadoop.metrics2.lib.MutableStat; public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements MetricsThriftServerSource { - private MutableStat batchGetStat; - private MutableStat batchMutateStat; - private MutableStat queueTimeStat; + private MutableHistogram batchGetStat; + private MutableHistogram batchMutateStat; + private MutableHistogram queueTimeStat; - private MutableStat thriftCallStat; - private MutableStat thriftSlowCallStat; + private MutableHistogram thriftCallStat; + private MutableHistogram thriftSlowCallStat; private MutableGaugeLong callQueueLenGauge; @@ -51,13 +51,11 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements @Override public void init() { super.init(); - batchGetStat = getMetricsRegistry().newStat(BATCH_GET_KEY, "", "Keys", "Ops"); - batchMutateStat = getMetricsRegistry().newStat(BATCH_MUTATE_KEY, "", "Keys", "Ops"); - queueTimeStat = getMetricsRegistry().newRate(TIME_IN_QUEUE_KEY); - - thriftCallStat = getMetricsRegistry().newRate(THRIFT_CALL_KEY); - thriftSlowCallStat = getMetricsRegistry().newRate(SLOW_THRIFT_CALL_KEY); - + batchGetStat = getMetricsRegistry().newHistogram(BATCH_GET_KEY); + batchMutateStat = getMetricsRegistry().newHistogram(BATCH_MUTATE_KEY); + queueTimeStat = getMetricsRegistry().newHistogram(TIME_IN_QUEUE_KEY); + thriftCallStat = getMetricsRegistry().newHistogram(THRIFT_CALL_KEY); + thriftSlowCallStat = getMetricsRegistry().newHistogram(SLOW_THRIFT_CALL_KEY); callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0); } @@ -84,7 +82,7 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements @Override public void incMethodTime(String name, long time) { - MutableStat s = getMetricsRegistry().newRate(name); + MutableHistogram s = getMetricsRegistry().getHistogram(name); s.add(time); } diff --git a/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java index 89c0762e6d9..76319da3c52 100644 --- a/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java +++ b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java @@ -60,7 +60,12 @@ public class TestMetricsRegionSourceImpl { @Override public String getTableName() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; + } + + @Override + public String getNamespace() { + return null; } @Override @@ -70,32 +75,32 @@ public class TestMetricsRegionSourceImpl { @Override public long getNumStores() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getNumStoreFiles() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getMemstoreSize() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getStoreFileSize() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getReadRequestCount() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } @Override public long getWriteRequestCount() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java index 146ed3adc15..78eb8fa5dfa 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java @@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit; public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable { public static final int PERIOD = 45; + public static final String UNKNOWN = "unknown"; private final HRegion region; private ScheduledExecutorService executor; @@ -55,16 +56,26 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable public String getTableName() { HTableDescriptor tableDesc = this.region.getTableDesc(); if (tableDesc == null) { - return ""; + return UNKNOWN; } - return tableDesc.getTableName().getNameAsString(); + return tableDesc.getTableName().getQualifierAsString(); } + @Override + public String getNamespace() { + HTableDescriptor tableDesc = this.region.getTableDesc(); + if (tableDesc == null) { + return UNKNOWN; + } + return tableDesc.getTableName().getNamespaceAsString(); + } + + @Override public String getRegionName() { HRegionInfo regionInfo = this.region.getRegionInfo(); if (regionInfo == null) { - return ""; + return UNKNOWN; } return regionInfo.getEncodedName(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java index eebec6a8c49..c6385022e6c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java @@ -25,6 +25,11 @@ public class MetricsRegionWrapperStub implements MetricsRegionWrapper { return "MetricsRegionWrapperStub"; } + @Override + public String getNamespace() { + return "TestNS"; + } + @Override public String getRegionName() { return "DEADBEEF001"; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java index 03b0b58661f..714518dd3a2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java @@ -35,9 +35,9 @@ public class TestMetricsRegion { MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub()); MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource(); - HELPER.assertGauge("table.MetricsRegionWrapperStub.region.DEADBEEF001.storeCount", 101, agg); - HELPER.assertGauge("table.MetricsRegionWrapperStub.region.DEADBEEF001.storeFileCount", 102, agg); - HELPER.assertGauge("table.MetricsRegionWrapperStub.region.DEADBEEF001.memstoreSize", 103, agg); + HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 101, agg); + HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 102, agg); + HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 103, agg); mr.close(); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java index 33a951aa000..db6a4afedd5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java @@ -141,9 +141,12 @@ public class TestRegionServerMetrics { .getMetrics() .getSource() .getAggregateSource(); - String prefix = "table."+tableNameString + ".region." + i.getEncodedName(); - metricsHelper.assertCounter(prefix + ".getNumOps", 10, agg); - metricsHelper.assertCounter(prefix + ".mutateCount", 30, agg); + String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+ + "_table_"+tableNameString + + "_region_" + i.getEncodedName()+ + "_metric"; + metricsHelper.assertCounter(prefix + "_getNumOps", 10, agg); + metricsHelper.assertCounter(prefix + "_mutateCount", 30, agg); } @@ -347,8 +350,11 @@ public class TestRegionServerMetrics { .getMetrics() .getSource() .getAggregateSource(); - String prefix = "table."+tableNameString + ".region." + i.getEncodedName(); - metricsHelper.assertCounter(prefix + ".scanNextNumOps", 30, agg); + String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+ + "_table_"+tableNameString + + "_region_" + i.getEncodedName()+ + "_metric"; + metricsHelper.assertCounter(prefix + "_scanNextNumOps", 30, agg); } } }