@Test
  public void testLastBucketWithSizeHistogram() {
    // create and init histogram minValue and maxValue
    MetricsCollectorImpl collector = new MetricsCollectorImpl();
    MutableSizeHistogram histogram = new MutableSizeHistogram(SIZE_HISTOGRAM_NAME, "");
    long[] ranges = histogram.getRanges();
    int len = ranges.length;
    histogram.add(0L);
    histogram.add(ranges[len - 1]);
    histogram.snapshot(collector.addRecord(RECORD_NAME), true);
    collector.clear();

    // fill up values and snapshot
    histogram.add(ranges[len - 2] * 2);
    histogram.add(ranges[len - 1] * 2);
    histogram.snapshot(collector.addRecord(RECORD_NAME), true);
    List<? extends MetricsRecord> records = collector.getRecords();
    assertEquals(1, records.size());
    MetricsRecord record = records.iterator().next();
    assertEquals(RECORD_NAME, record.name());

    // get size range metrics
    String histogramMetricPrefix = SIZE_HISTOGRAM_NAME + "_" + histogram.getRangeType();
    List<AbstractMetric> metrics = new ArrayList<>();
    for (AbstractMetric metric : record.metrics()) {
      if (metric.name().startsWith(histogramMetricPrefix)) {
        metrics.add(metric);
      }
    }
    assertEquals(2, metrics.size());

    // check range [10000000,100000000]
    String metricName = histogramMetricPrefix + "_" + ranges[len - 2] + "-" + ranges[len - 1];
    assertEquals(metricName, metrics.get(0).name());
    assertEquals(1, metrics.get(0).value().longValue());

    // check range [100000000, inf]
    metricName = histogramMetricPrefix + "_" + ranges[len - 1] + "-inf";
    assertEquals(metricName, metrics.get(1).name(), metricName);
    assertEquals(1, metrics.get(1).value().longValue());
  }
calculate the distribution for last bucket, see HBASE-24615 for detail.
hbase-hadoop-compat/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableRangeHistogram.java