Skip to content
Permalink
Browse files
HBASE-25964 Introducing hbase metrics to Hboss
Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
  • Loading branch information
BukrosSzabolcs committed Jun 2, 2021
1 parent b23665d commit fe4c46d258209f984aef3368161682c3ae376322
Showing 5 changed files with 233 additions and 1 deletion.
@@ -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>
@@ -49,6 +49,8 @@
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 void initialize(URI name, Configuration conf) throws IOException {

fs = FileSystem.get(name, internalConf);
sync = TreeLockManager.get(fs);
metrics = MetricsOSSSourceImpl.getInstance();
}

@InterfaceAudience.Private
@@ -445,8 +449,20 @@ public boolean setReplication(Path src, short replication)
}

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);
}
}

@@ -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";

}
@@ -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;
}
}
@@ -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());
}
}

0 comments on commit fe4c46d

Please sign in to comment.