|
16 | 16 | package io.micrometer.registry.otlp;
|
17 | 17 |
|
18 | 18 | import io.micrometer.common.lang.Nullable;
|
| 19 | +import io.micrometer.common.util.StringUtils; |
19 | 20 | import io.micrometer.common.util.internal.logging.InternalLogger;
|
20 | 21 | import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
|
21 | 22 | import io.micrometer.core.instrument.*;
|
|
50 | 51 | import java.util.concurrent.ScheduledExecutorService;
|
51 | 52 | import java.util.concurrent.ThreadFactory;
|
52 | 53 | import java.util.concurrent.TimeUnit;
|
| 54 | +import java.util.function.Supplier; |
53 | 55 | import java.util.function.ToDoubleFunction;
|
54 | 56 | import java.util.function.ToLongFunction;
|
55 | 57 |
|
@@ -503,22 +505,35 @@ static double[] getSloWithPositiveInf(DistributionStatisticConfig distributionSt
|
503 | 505 | return sloWithPositiveInf;
|
504 | 506 | }
|
505 | 507 |
|
506 |
| - private static HistogramFlavor histogramFlavorPerMeter(OtlpConfig config, Meter.Id id) { |
507 |
| - for (Map.Entry<String, HistogramFlavor> entry : config.histogramFlavorPerMeter().entrySet()) { |
508 |
| - if (id.getName().startsWith(entry.getKey())) { |
509 |
| - return entry.getValue(); |
510 |
| - } |
| 508 | + // VisibleForTesting |
| 509 | + static HistogramFlavor histogramFlavorPerMeter(OtlpConfig config, Meter.Id id) { |
| 510 | + return lookup(config.histogramFlavorPerMeter(), id, config.histogramFlavor()); |
| 511 | + } |
| 512 | + |
| 513 | + // VisibleForTesting |
| 514 | + static Integer maxBucketsPerMeter(OtlpConfig config, Meter.Id id) { |
| 515 | + return lookup(config.maxBucketsPerMeter(), id, config.maxBucketCount()); |
| 516 | + } |
| 517 | + |
| 518 | + private static <T> T lookup(Map<String, T> values, Meter.Id id, T defaultValue) { |
| 519 | + if (values.isEmpty()) { |
| 520 | + return defaultValue; |
511 | 521 | }
|
512 |
| - return config.histogramFlavor(); |
| 522 | + return doLookup(values, id, () -> defaultValue); |
513 | 523 | }
|
514 | 524 |
|
515 |
| - private static Integer maxBucketsPerMeter(OtlpConfig config, Meter.Id id) { |
516 |
| - for (Map.Entry<String, Integer> entry : config.maxBucketsPerMeter().entrySet()) { |
517 |
| - if (id.getName().startsWith(entry.getKey())) { |
518 |
| - return entry.getValue(); |
| 525 | + private static <T> T doLookup(Map<String, T> values, Meter.Id id, Supplier<T> defaultValue) { |
| 526 | + String name = id.getName(); |
| 527 | + while (StringUtils.isNotEmpty(name)) { |
| 528 | + T result = values.get(name); |
| 529 | + if (result != null) { |
| 530 | + return result; |
519 | 531 | }
|
| 532 | + int lastDot = name.lastIndexOf('.'); |
| 533 | + name = (lastDot != -1) ? name.substring(0, lastDot) : ""; |
520 | 534 | }
|
521 |
| - return config.maxBucketCount(); |
| 535 | + |
| 536 | + return defaultValue.get(); |
522 | 537 | }
|
523 | 538 |
|
524 | 539 | /**
|
|
0 commit comments