Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-28335 Expose CacheStats ageAtEviction histogram in jmx #5942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,5 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
"Count of scanners which were expired due to scanner lease timeout";
String CURRENT_REGION_CACHE_RATIO = "currentRegionCacheRatio";
String CURRENT_REGION_CACHE_RATIO_DESC = "The percentage of caching completed for this region.";
String AGE_AT_EVICTION = "AgeAtEviction";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.apache.hadoop.hbase.metrics.Interns;
import org.apache.hadoop.hbase.metrics.impl.FastLongHistogram;
import org.apache.hadoop.metrics2.MetricHistogram;
import org.apache.hadoop.metrics2.MetricsCollector;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
Expand Down Expand Up @@ -512,7 +513,7 @@ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
}

private MetricsRecordBuilder addGaugesToMetricsRecordBuilder(MetricsRecordBuilder mrb) {
return mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
.addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
.addGauge(Interns.info(WALFILE_COUNT, WALFILE_COUNT_DESC), rsWrap.getNumWALFiles())
.addGauge(Interns.info(WALFILE_SIZE, WALFILE_SIZE_DESC), rsWrap.getWALFileSize())
Expand Down Expand Up @@ -641,6 +642,39 @@ private MetricsRecordBuilder addGaugesToMetricsRecordBuilder(MetricsRecordBuilde
.addGauge(Interns.info(BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT,
BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT_DESC), rsWrap.getByteBuffAllocatorUsedBufferCount())
.addGauge(Interns.info(ACTIVE_SCANNERS, ACTIVE_SCANNERS_DESC), rsWrap.getActiveScanners());
addFastLongHistStats(mrb, rsWrap.getAgeAtEviction(), AGE_AT_EVICTION);
return mrb;
}

private void addFastLongHistStats(MetricsRecordBuilder mrb, FastLongHistogram flHistogram,
String metricsKey) {
mrb.addGauge(Interns.info(metricsKey + MetricHistogram.MIN_METRIC_NAME, ""),
flHistogram.getMin());
mrb.addGauge(Interns.info(metricsKey + MetricHistogram.MAX_METRIC_NAME, ""),
flHistogram.getMax());
mrb.addGauge(Interns.info(metricsKey + MetricHistogram.MEAN_METRIC_NAME, ""),
flHistogram.getMean());
long[] quantiles = flHistogram.getQuantiles();

mrb.addGauge(Interns.info(metricsKey + MetricHistogram.TWENTY_FIFTH_PERCENTILE_METRIC_NAME, ""),
quantiles[0]);
mrb.addGauge(Interns.info(metricsKey + MetricHistogram.MEDIAN_METRIC_NAME, ""), quantiles[1]);
mrb.addGauge(
Interns.info(metricsKey + MetricHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME, ""),
quantiles[2]);
mrb.addGauge(Interns.info(metricsKey + MetricHistogram.NINETIETH_PERCENTILE_METRIC_NAME, ""),
quantiles[3]);
mrb.addGauge(Interns.info(metricsKey + MetricHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME, ""),
quantiles[4]);
mrb.addGauge(
Interns.info(metricsKey + MetricHistogram.NINETY_EIGHTH_PERCENTILE_METRIC_NAME, ""),
quantiles[5]);
mrb.addGauge(
Interns.info(metricsKey + MetricHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME, ""),
quantiles[6]);
mrb.addGauge(Interns
.info(metricsKey + MetricHistogram.NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC_NAME, ""),
quantiles[7]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.regionserver;

import java.util.List;
import org.apache.hadoop.hbase.metrics.impl.FastLongHistogram;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand Down Expand Up @@ -643,4 +644,6 @@ public interface MetricsRegionServerWrapper {
long getByteBuffAllocatorUsedBufferCount();

int getActiveScanners();

FastLongHistogram getAgeAtEviction();
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,8 @@ public AgeSnapshot getAgeAtEvictionSnapshot() {
private static long sum(long[] counts) {
return Arrays.stream(counts).sum();
}

public FastLongHistogram getAgeAtEviction() {
return this.ageAtEviction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.hadoop.hbase.io.hfile.BlockCache;
import org.apache.hadoop.hbase.io.hfile.CacheStats;
import org.apache.hadoop.hbase.io.hfile.CombinedBlockCache;
import org.apache.hadoop.hbase.metrics.impl.FastLongHistogram;
import org.apache.hadoop.hbase.mob.MobFileCache;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
Expand Down Expand Up @@ -730,6 +731,11 @@ public int getActiveScanners() {
return regionServer.getRpcServices().getScannersCount();
}

@Override
public FastLongHistogram getAgeAtEviction() {
return cacheStats.getAgeAtEviction();
}

private static final class RegionMetricAggregate {
private long numStores = 0;
private long numStoreFiles = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Collections;
import java.util.List;
import org.apache.hadoop.hbase.metrics.impl.FastLongHistogram;

public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrapper {

Expand Down Expand Up @@ -162,6 +163,15 @@ public int getActiveScanners() {
return 0;
}

@Override
public FastLongHistogram getAgeAtEviction() {
FastLongHistogram histogram = new FastLongHistogram();
histogram.add(100, 1);
histogram.add(500, 1);
histogram.add(400, 1);
return histogram;
}

@Override
public long getReadRequestsCount() {
return 997;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.regionserver;

import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.AGE_AT_EVICTION;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -26,11 +27,13 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CompatibilityFactory;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.metrics.impl.FastLongHistogram;
import org.apache.hadoop.hbase.regionserver.metrics.MetricsTableRequests;
import org.apache.hadoop.hbase.test.MetricsAssertHelper;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.JvmPauseMonitor;
import org.apache.hadoop.metrics2.MetricHistogram;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand Down Expand Up @@ -139,6 +142,29 @@ public void testWrapperSource() {
HELPER.assertGauge("l2CacheHitRatio", 90, serverSource);
HELPER.assertGauge("l2CacheMissRatio", 10, serverSource);
HELPER.assertCounter("updatesBlockedTime", 419, serverSource);
// start asserting ageAtEviction Histogram stats
FastLongHistogram ageAtEviction = wrapper.getAgeAtEviction();
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.MIN_METRIC_NAME, 100, serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.MAX_METRIC_NAME, 500, serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.MEAN_METRIC_NAME, (500 + 400 + 100) / 3,
serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.TWENTY_FIFTH_PERCENTILE_METRIC_NAME,
ageAtEviction.getQuantiles()[0], serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.MEDIAN_METRIC_NAME,
ageAtEviction.getQuantiles()[1], serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME,
ageAtEviction.getQuantiles()[2], serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.NINETIETH_PERCENTILE_METRIC_NAME,
ageAtEviction.getQuantiles()[3], serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME,
ageAtEviction.getQuantiles()[4], serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.NINETY_EIGHTH_PERCENTILE_METRIC_NAME,
ageAtEviction.getQuantiles()[5], serverSource);
HELPER.assertGauge(AGE_AT_EVICTION + MetricHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME,
ageAtEviction.getQuantiles()[6], serverSource);
HELPER.assertGauge(
AGE_AT_EVICTION + MetricHistogram.NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC_NAME,
ageAtEviction.getQuantiles()[7], serverSource);
}

@Test
Expand Down