|
8 | 8 | import java.util.Arrays;
|
9 | 9 | import java.util.Collections;
|
10 | 10 | import java.util.List;
|
| 11 | +import java.util.Locale; |
| 12 | +import java.util.logging.Level; |
| 13 | +import java.util.logging.Logger; |
11 | 14 |
|
12 | 15 | /**
|
13 | 16 | * Utilities for interacting with explicit bucket histograms.
|
|
16 | 19 | * at any time.
|
17 | 20 | */
|
18 | 21 | public final class ExplicitBucketHistogramUtils {
|
19 |
| - private ExplicitBucketHistogramUtils() {} |
20 | 22 |
|
21 |
| - public static final List<Double> DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES = |
| 23 | + private static final Logger logger = |
| 24 | + Logger.getLogger(ExplicitBucketHistogramUtils.class.getName()); |
| 25 | + private static final String LEGACY_BUCKETS_ENABLED = "otel.java.histogram.legacy.buckets.enabled"; |
| 26 | + private static final List<Double> DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES = |
22 | 27 | Collections.unmodifiableList(
|
23 | 28 | Arrays.asList(0d, 5d, 10d, 25d, 50d, 75d, 100d, 250d, 500d, 1_000d));
|
| 29 | + private static final List<Double> LEGACY_HISTOGRAM_BUCKET_BOUNDARIES = |
| 30 | + Collections.unmodifiableList( |
| 31 | + Arrays.asList( |
| 32 | + 5d, 10d, 25d, 50d, 75d, 100d, 250d, 500d, 750d, 1_000d, 2_500d, 5_000d, 7_500d, |
| 33 | + 10_000d)); |
| 34 | + |
| 35 | + private static final List<Double> defaultBucketBoundaries; |
| 36 | + |
| 37 | + static { |
| 38 | + // TODO: remove support for configuring legacy bucket boundaries after 1.24.0 |
| 39 | + boolean legacyBucketsEnabled = |
| 40 | + Boolean.parseBoolean(System.getProperty(LEGACY_BUCKETS_ENABLED)) |
| 41 | + || Boolean.parseBoolean( |
| 42 | + System.getenv(LEGACY_BUCKETS_ENABLED.toUpperCase(Locale.ROOT).replace(".", "_"))); |
| 43 | + if (legacyBucketsEnabled) { |
| 44 | + logger.log( |
| 45 | + Level.WARNING, |
| 46 | + "Legacy explicit bucket histogram buckets have been enabled. Support will be removed " |
| 47 | + + "after version 1.24.0. If you depend on the legacy bucket boundaries, please " |
| 48 | + + "use the View API as described in " |
| 49 | + + "https://opentelemetry.io/docs/instrumentation/java/manual/#views."); |
| 50 | + defaultBucketBoundaries = LEGACY_HISTOGRAM_BUCKET_BOUNDARIES; |
| 51 | + } else { |
| 52 | + defaultBucketBoundaries = DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + private ExplicitBucketHistogramUtils() {} |
| 57 | + |
| 58 | + /** Returns the default explicit bucket histogram bucket boundaries. */ |
| 59 | + public static List<Double> getDefaultBucketBoundaries() { |
| 60 | + return defaultBucketBoundaries; |
| 61 | + } |
24 | 62 |
|
25 | 63 | /** Converts bucket boundary "convenient" configuration into the "more efficient" array. */
|
26 | 64 | public static double[] createBoundaryArray(List<Double> boundaries) {
|
|
0 commit comments