diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java index df78a5ac1f5..75dc300ba44 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java @@ -42,10 +42,6 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram { } public MutableHistogram(String name, String description) { - this(name, description, Integer.MAX_VALUE << 2); - } - - protected MutableHistogram(String name, String description, long maxExpected) { this.name = StringUtils.capitalize(name); this.desc = StringUtils.uncapitalize(description); this.histogram = new HistogramImpl(); diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java index 4b73087ed5a..273154f9ff2 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java @@ -36,11 +36,7 @@ public abstract class MutableRangeHistogram extends MutableHistogram implements } public MutableRangeHistogram(String name, String description) { - this(name, description, Integer.MAX_VALUE << 2); - } - - public MutableRangeHistogram(String name, String description, long expectedMax) { - super(name, description, expectedMax); + super(name, description); } /** diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java index 2f1dc6f2154..b02efb76f9d 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java @@ -26,6 +26,7 @@ import org.apache.yetus.audience.InterfaceAudience; */ @InterfaceAudience.Private public class MutableSizeHistogram extends MutableRangeHistogram { + private final static String RANGE_TYPE = "SizeRangeCount"; private final static long[] RANGES = {10,100,1000,10000,100000,1000000,10000000,100000000}; @@ -34,11 +35,7 @@ public class MutableSizeHistogram extends MutableRangeHistogram { } public MutableSizeHistogram(String name, String description) { - this(name, description, RANGES[RANGES.length-2]); - } - - public MutableSizeHistogram(String name, String description, long expectedMax) { - super(name, description, expectedMax); + super(name, description); } @Override diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java index e002781d992..7c6dfbbd577 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java @@ -35,11 +35,7 @@ public class MutableTimeHistogram extends MutableRangeHistogram { } public MutableTimeHistogram(String name, String description) { - this(name, description, RANGES[RANGES.length - 2]); - } - - public MutableTimeHistogram(String name, String description, long expectedMax) { - super(name, description, expectedMax); + super(name, description); } @Override diff --git a/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/HistogramImpl.java b/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/HistogramImpl.java index 7b79fba50f1..fd6a2b348e2 100644 --- a/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/HistogramImpl.java +++ b/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/HistogramImpl.java @@ -36,7 +36,7 @@ public class HistogramImpl implements Histogram { private final CounterImpl counter; public HistogramImpl() { - this(Integer.MAX_VALUE << 2); + this((long) Integer.MAX_VALUE << 2); } public HistogramImpl(long maxExpected) { diff --git a/hbase-metrics/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestHistogramImpl.java b/hbase-metrics/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestHistogramImpl.java index 2e53869650f..9be3fcee20f 100644 --- a/hbase-metrics/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestHistogramImpl.java +++ b/hbase-metrics/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestHistogramImpl.java @@ -63,19 +63,19 @@ public class TestHistogramImpl { Snapshot snapshot = histogram.snapshot(); assertEquals(100, snapshot.getCount()); - assertEquals(50, snapshot.getMedian()); + assertEquals(49, snapshot.getMedian()); assertEquals(49, snapshot.getMean()); assertEquals(0, snapshot.getMin()); assertEquals(99, snapshot.getMax()); - assertEquals(25, snapshot.get25thPercentile()); - assertEquals(75, snapshot.get75thPercentile()); - assertEquals(90, snapshot.get90thPercentile()); - assertEquals(95, snapshot.get95thPercentile()); - assertEquals(98, snapshot.get98thPercentile()); - assertEquals(99, snapshot.get99thPercentile()); - assertEquals(99, snapshot.get999thPercentile()); + assertEquals(24, snapshot.get25thPercentile()); + assertEquals(74, snapshot.get75thPercentile()); + assertEquals(89, snapshot.get90thPercentile()); + assertEquals(94, snapshot.get95thPercentile()); + assertEquals(97, snapshot.get98thPercentile()); + assertEquals(98, snapshot.get99thPercentile()); + assertEquals(98, snapshot.get999thPercentile()); - assertEquals(51, snapshot.getCountAtOrBelow(50)); + assertEquals(100, snapshot.getCountAtOrBelow(50)); // check that histogram is reset. assertEquals(100, histogram.getCount()); // count does not reset @@ -98,5 +98,23 @@ public class TestHistogramImpl { assertEquals(198, snapshot.get98thPercentile()); assertEquals(199, snapshot.get99thPercentile()); assertEquals(199, snapshot.get999thPercentile()); + + IntStream.range(500, 1000).forEach(histogram::update); + + snapshot = histogram.snapshot(); + + assertEquals(500, snapshot.getCount()); + assertEquals(749, snapshot.getMedian()); + assertEquals(749, snapshot.getMean()); + assertEquals(500, snapshot.getMin()); + assertEquals(999, snapshot.getMax()); + assertEquals(624, snapshot.get25thPercentile()); + assertEquals(874, snapshot.get75thPercentile()); + assertEquals(949, snapshot.get90thPercentile()); + assertEquals(974, snapshot.get95thPercentile()); + assertEquals(989, snapshot.get98thPercentile()); + assertEquals(994, snapshot.get99thPercentile()); + assertEquals(998, snapshot.get999thPercentile()); + } }