Skip to content
Merged
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 @@ -42,10 +42,6 @@ public MutableHistogram(MetricsInfo info) {
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public MutableRangeHistogram(MetricsInfo info) {
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
@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};

Expand All @@ -34,11 +35,7 @@ public MutableSizeHistogram(MetricsInfo info) {
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public MutableTimeHistogram(MetricsInfo info) {
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this is the change that required the test changes

}

public HistogramImpl(long maxExpected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ public void testSnapshot() {
Snapshot snapshot = histogram.snapshot();

assertEquals(100, snapshot.getCount());
assertEquals(50, snapshot.getMedian());
assertEquals(49, snapshot.getMedian());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you help me understanding why this became 49?

Copy link
Contributor Author

@virajjasani virajjasani Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMin()=0, getMax()=99. Hence, ideally getMedian() should be 49.
All these values are changed after fixing: https://github.com/apache/hbase/pull/787/files#diff-ac08d4adf915ba5ccb72db551e2fef34R39 (which was incorrect before because without long conversion, the value is numeric overload and results -4)

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
Expand All @@ -98,5 +98,23 @@ public void testSnapshot() {
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());

}
}