hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wchevre...@apache.org
Subject [hbase-filesystem] branch master updated: HBASE-25964 Introducing hbase metrics to Hboss
Date Wed, 02 Jun 2021 15:36:17 GMT
This is an automated email from the ASF dual-hosted git repository.

wchevreuil pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase-filesystem.git


The following commit(s) were added to refs/heads/master by this push:
     new fe4c46d   HBASE-25964 Introducing hbase metrics to Hboss
fe4c46d is described below

commit fe4c46d258209f984aef3368161682c3ae376322
Author: BukrosSzabolcs <szabolcs@cloudera.com>
AuthorDate: Wed Jun 2 17:36:09 2021 +0200

     HBASE-25964 Introducing hbase metrics to Hboss
    
    Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
---
 hbase-oss/pom.xml                                  |  12 +++
 .../hbase/oss/HBaseObjectStoreSemantics.java       |  18 +++-
 .../hadoop/hbase/oss/metrics/MetricsOSSSource.java |  78 ++++++++++++++++
 .../hbase/oss/metrics/MetricsOSSSourceImpl.java    | 103 +++++++++++++++++++++
 .../hbase/oss/metrics/TestMetricsOSSSource.java    |  23 +++++
 5 files changed, 233 insertions(+), 1 deletion(-)

diff --git a/hbase-oss/pom.xml b/hbase-oss/pom.xml
index e0196db..7713b5e 100644
--- a/hbase-oss/pom.xml
+++ b/hbase-oss/pom.xml
@@ -250,6 +250,18 @@
       <version>${hbase.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.hbase</groupId>
+      <artifactId>hbase-hadoop-compat</artifactId>
+      <version>${hbase.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hbase</groupId>
+      <artifactId>hbase-hadoop2-compat</artifactId>
+      <version>${hbase.version}</version>
+      <scope>provided</scope>
+    </dependency>
 
     <!-- Test dependencies -->
     <dependency>
diff --git a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java
b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java
index d1fcc1c..7669181 100644
--- a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java
+++ b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java
@@ -49,6 +49,8 @@ import org.apache.hadoop.fs.permission.AclStatus;
 import org.apache.hadoop.fs.permission.FsAction;
 import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
+import org.apache.hadoop.hbase.oss.metrics.MetricsOSSSource;
+import org.apache.hadoop.hbase.oss.metrics.MetricsOSSSourceImpl;
 import org.apache.hadoop.hbase.oss.sync.AutoLock;
 import org.apache.hadoop.hbase.oss.sync.AutoLock.LockedFSDataOutputStream;
 import org.apache.hadoop.hbase.oss.sync.AutoLock.LockedRemoteIterator;
@@ -96,6 +98,7 @@ public class HBaseObjectStoreSemantics extends FilterFileSystem {
         LoggerFactory.getLogger(HBaseObjectStoreSemantics.class);
 
   private TreeLockManager sync;
+  private MetricsOSSSource metrics;
 
   public void initialize(URI name, Configuration conf) throws IOException {
     setConf(conf);
@@ -116,6 +119,7 @@ public class HBaseObjectStoreSemantics extends FilterFileSystem {
 
     fs = FileSystem.get(name, internalConf);
     sync = TreeLockManager.get(fs);
+    metrics = MetricsOSSSourceImpl.getInstance();
   }
 
   @InterfaceAudience.Private
@@ -445,8 +449,20 @@ public class HBaseObjectStoreSemantics extends FilterFileSystem {
   }
 
   public boolean rename(Path src, Path dst) throws IOException {
+    long startTime = System.currentTimeMillis();
+    long lockAcquiredTime = startTime;
+    long doneTime = startTime;
     try (AutoLock l = sync.lockRename(src, dst)) {
-      return fs.rename(src, dst);
+      lockAcquiredTime = System.currentTimeMillis();
+      metrics.updateAcquireRenameLockHisto(lockAcquiredTime- startTime);
+      boolean result = fs.rename(src, dst);
+      doneTime = System.currentTimeMillis();
+      metrics.updateRenameFsOperationHisto(doneTime - lockAcquiredTime);
+      return result;
+    }
+    finally {
+      long releasedLocksTime = System.currentTimeMillis();
+      metrics.updateReleaseRenameLockHisto(releasedLocksTime - doneTime);
     }
   }
 
diff --git a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/metrics/MetricsOSSSource.java
b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/metrics/MetricsOSSSource.java
new file mode 100644
index 0000000..9b94e95
--- /dev/null
+++ b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/metrics/MetricsOSSSource.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.oss.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseSource;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Interface for classes that expose metrics about the Object Store.
+ */
+@InterfaceAudience.Private
+public interface MetricsOSSSource extends BaseSource {
+
+  /**
+   * The name of the metrics
+   */
+  String METRICS_NAME = "FileSystem";
+
+  /**
+   * The name of the metrics context that metrics will be under.
+   */
+  String METRICS_CONTEXT = "objectstore";
+
+  /**
+   * Description
+   */
+  String METRICS_DESCRIPTION = "Metrics about Object Store";
+
+  /**
+   * The name of the metrics context that metrics will be under in jmx
+   */
+  String METRICS_JMX_CONTEXT = "ObjectStore,sub=" + METRICS_NAME;
+
+  /**
+   * Update the Rename AcquireLock Histogram
+   *
+   * @param t time it took
+   */
+  public void updateAcquireRenameLockHisto(long t);
+
+  /**
+   * Update the Rename ReleaseLock Histogram
+   *
+   * @param t time it took
+   */
+  public void updateReleaseRenameLockHisto(long t);
+
+  /**
+   * Update the Rename FsOperation Histogram
+   *
+   * @param t time it took
+   */
+  public void updateRenameFsOperationHisto(long t);
+
+  String ACQUIRE_RENAME_LOCK = "acquireRenameLock";
+  String ACQUIRE_RENAME_LOCK_DESC = "Time in ms required to acquire lock for Rename";
+  String RELEASE_RENAME_LOCK = "releaseRenameLock";
+  String RELEASE_RENAME_LOCK_DESC = "Time in ms required to release lock for Rename";
+  String RENAME_FS_OPERATION = "renameFsOperation";
+  String RENAME_FS_OPERATION_DESC = "Time in ms required to finish Rename file operation";
+
+}
diff --git a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/metrics/MetricsOSSSourceImpl.java
b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/metrics/MetricsOSSSourceImpl.java
new file mode 100644
index 0000000..64088c1
--- /dev/null
+++ b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/metrics/MetricsOSSSourceImpl.java
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.oss.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
+import org.apache.hadoop.metrics2.MetricHistogram;
+import org.apache.hadoop.metrics2.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Hadoop2 implementation of MetricsOSSSource.
+ *
+ * Implements BaseSource through BaseSourceImpl, following the pattern
+ */
+@InterfaceAudience.Private
+public class MetricsOSSSourceImpl
+    extends BaseSourceImpl implements MetricsOSSSource {
+
+  private static MetricsOSSSourceImpl instance = null;
+
+  private final MetricHistogram acquireRenameLockHisto;
+  private final MetricHistogram releaseRenameLockHisto;
+  private final MetricHistogram renameFsOperationHisto;
+
+
+  private MetricsOSSSourceImpl() {
+    this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
+  }
+
+  private MetricsOSSSourceImpl(String metricsName,
+                                       String metricsDescription,
+                                       String metricsContext,
+                                       String metricsJmxContext) {
+    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+
+    acquireRenameLockHisto = getMetricsRegistry().newTimeHistogram(ACQUIRE_RENAME_LOCK, ACQUIRE_RENAME_LOCK_DESC);
+    releaseRenameLockHisto = getMetricsRegistry().newTimeHistogram(RELEASE_RENAME_LOCK, RELEASE_RENAME_LOCK_DESC);
+    renameFsOperationHisto = getMetricsRegistry().newTimeHistogram(RENAME_FS_OPERATION, RENAME_FS_OPERATION_DESC);
+
+  }
+
+  @Override
+  public void updateAcquireRenameLockHisto(long t) {
+    acquireRenameLockHisto.add(t);
+  }
+
+  @Override
+  public void updateReleaseRenameLockHisto(long t) {
+    releaseRenameLockHisto.add(t);
+  }
+
+  @Override
+  public void updateRenameFsOperationHisto(long t) {
+    renameFsOperationHisto.add(t);
+  }
+
+
+  /**
+   * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking
all
+   * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
+   * getMetrics to push the metrics into the collector.
+   *
+   * @param metricsCollector Collector to accept metrics
+   * @param all              push all or only changed?
+   */
+  @Override
+  public void getMetrics(MetricsCollector metricsCollector, boolean all) {
+    MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
+
+    metricsRegistry.snapshot(mrb, all);
+
+    // source is registered in supers constructor, sometimes called before the whole initialization.
+    if (metricsAdapter != null) {
+      // snapshot MetricRegistry as well
+      metricsAdapter.snapshotAllMetrics(registry, mrb);
+    }
+  }
+
+
+  public static synchronized MetricsOSSSourceImpl getInstance(){
+    if(instance == null){
+      instance = new MetricsOSSSourceImpl();
+    }
+    return instance;
+  }
+}
diff --git a/hbase-oss/src/test/java/org/apache/hadoop/hbase/oss/metrics/TestMetricsOSSSource.java
b/hbase-oss/src/test/java/org/apache/hadoop/hbase/oss/metrics/TestMetricsOSSSource.java
new file mode 100644
index 0000000..81fde0b
--- /dev/null
+++ b/hbase-oss/src/test/java/org/apache/hadoop/hbase/oss/metrics/TestMetricsOSSSource.java
@@ -0,0 +1,23 @@
+package org.apache.hadoop.hbase.oss.metrics;
+
+import org.apache.hadoop.metrics2.lib.MutableHistogram;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestMetricsOSSSource {
+
+  @Test
+  public void testUpdateValues(){
+    MetricsOSSSourceImpl metrics = MetricsOSSSourceImpl.getInstance();
+    metrics.updateAcquireRenameLockHisto(1l);
+    metrics.updateRenameFsOperationHisto(2l);
+    metrics.updateReleaseRenameLockHisto(3l);
+
+    Assert.assertEquals(1l, ((MutableHistogram) metrics.getMetricsRegistry()
+        .getHistogram(MetricsOSSSource.ACQUIRE_RENAME_LOCK)).getMax());
+    Assert.assertEquals(2l, ((MutableHistogram) metrics.getMetricsRegistry()
+        .getHistogram(MetricsOSSSource.RENAME_FS_OPERATION)).getMax());
+    Assert.assertEquals(3l, ((MutableHistogram) metrics.getMetricsRegistry()
+        .getHistogram(MetricsOSSSource.RELEASE_RENAME_LOCK)).getMax());
+  }
+}

Mime
View raw message