MeterBuilder { public static Optional<Histogram> buildHistogram(MeterId meterId, boolean supportsAggregablePercentiles, DistributionStatisticConfig distributionStatisticConfig, boolean useNanoTime) { if (!distributionStatisticConfig.isPublishingHistogram()) { return Optional.empty(); } final NavigableSet<Double> buckets = distributionStatisticConfig.getHistogramBuckets(supportsAggregablePercentiles); final List<Double> steps = buckets.stream().sorted(Double::compare) .map(t -> useNanoTime ? TimeUtils.nanosToUnit(t, TimeUnit.MILLISECONDS) : t).collect(Collectors.toList()); final Histogram.Builder histogramBuilder = MeterFactory.histogram( meterId.copyTo(meterId.getName() + "_histogram", MeterId.MeterType.HISTOGRAM)).steps(steps); final Double minimumExpectedValueAsDouble = distributionStatisticConfig.getMinimumExpectedValueAsDouble(); if (minimumExpectedValueAsDouble != null) { histogramBuilder.minValue(useNanoTime ? TimeUtils.nanosToUnit(minimumExpectedValueAsDouble, TimeUnit.MILLISECONDS) : minimumExpectedValueAsDouble); } return Optional.of(histogramBuilder.build()); }  static Counter buildCounter(MeterId meterId, SkywalkingConfig config); static Counter.Mode getCounterMode(MeterId meterId, SkywalkingConfig config); static Optional<Histogram> buildHistogram(MeterId meterId, boolean supportsAggregablePercentiles,
                                                     DistributionStatisticConfig distributionStatisticConfig,
                                                     boolean useNanoTime); static MeterId convertId(Meter.Id id, String name);  }
@Test public void testBuildHistogram() { final MeterId meterId = new MeterId("test", MeterId.MeterType.COUNTER, Arrays.asList(new MeterId.Tag("k1", "v1"))); final DistributionStatisticConfig statisticConfig = DistributionStatisticConfig.builder() .serviceLevelObjectives(Duration.ofMillis(1).toNanos(), Duration.ofMillis(5).toNanos(), Duration.ofMillis(10).toNanos()) .minimumExpectedValue(0d).build(); final Optional<Histogram> histogramOptional = MeterBuilder.buildHistogram(meterId, true, statisticConfig, true); final Histogram histogram = histogramOptional.orElse(null); Assert.assertNotNull(histogram); Assert.assertNull(MeterBuilder.buildHistogram(meterId, true, DistributionStatisticConfig.DEFAULT, true).orElse(null)); }