Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
HBASE-25964 Introducing hbase metrics to Hboss
Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
- Loading branch information
1 parent
b23665d
commit fe4c46d258209f984aef3368161682c3ae376322
Showing
5 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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()); | ||
} | ||
} |