Skip to content

Commit 4c5d123

Browse files
committed
Change lookup logic without making it customizable
1 parent e36f6e9 commit 4c5d123

File tree

3 files changed

+26
-342
lines changed

3 files changed

+26
-342
lines changed

Diff for: implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java

+17-21
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,16 @@ default HistogramFlavor histogramFlavor() {
230230

231231
/**
232232
* Configures the histogram flavor mapping to use on a per-meter level. This can
233-
* override the {@link #histogramFlavor()} configuration for matching Meters. By
234-
* default, {@link OtlpMeterRegistry} (through
235-
* {@link io.micrometer.registry.otlp.OtlpMeterRegistry.HistogramFlavorPerMeterLookup})
236-
* uses the result of this method to look up the {@link HistogramFlavor} by
237-
* {@link Meter.Id} (prefix match on the Meter's name by default). This means that
238-
* this method provides the data while
239-
* {@link io.micrometer.registry.otlp.OtlpMeterRegistry.HistogramFlavorPerMeterLookup}
240-
* provides the logic for the lookup, and you can override them independently.
241-
* @return mapping of meter name to histogram flavor
233+
* override the {@link #histogramFlavor()} configuration for matching Meters.
234+
* {@link OtlpMeterRegistry} uses the result of this method to look up the
235+
* {@link HistogramFlavor} by {@link Meter.Id}. The longest dot-separated match wins.
236+
* For example, if the returned Map has keys {@literal http} and
237+
* {@literal http.server}, an ID with a name {@literal http.server.requests} would
238+
* match with the entry having key {@literal http.server}, whereas an ID with name
239+
* {@literal http.client.requests} would match with the entry having the key
240+
* {@literal http}.
241+
* @return mapping of meter name (or prefix) to histogram flavor
242242
* @since 1.15.0
243-
* @see io.micrometer.registry.otlp.OtlpMeterRegistry.HistogramFlavorPerMeterLookup
244243
* @see #histogramFlavor()
245244
*/
246245
default Map<String, HistogramFlavor> histogramFlavorPerMeter() {
@@ -275,19 +274,16 @@ default int maxBucketCount() {
275274

276275
/**
277276
* Configures the max bucket count mapping to use on a per-meter level. This can
278-
* override the {@link #maxBucketCount()} configuration for matching Meters. By
279-
* default, {@link OtlpMeterRegistry} (through
280-
* {@link io.micrometer.registry.otlp.OtlpMeterRegistry.MaxBucketsPerMeterLookup})
281-
* uses the result of this method to look up the max bucket count by {@link Meter.Id}
282-
* (prefix match on the Meter's name by default). This means that this method provides
283-
* the data while
284-
* {@link io.micrometer.registry.otlp.OtlpMeterRegistry.MaxBucketsPerMeterLookup}
285-
* provides the logic for the lookup, and you can override them independently. This
286-
* has no effect on a meter if it does not have an exponential bucket histogram
287-
* configured.
277+
* override the {@link #maxBucketCount()} configuration for matching Meters.
278+
* {@link OtlpMeterRegistry} uses the result of this method to look up the max bucket
279+
* count by {@link Meter.Id}. The longest dot-separated match wins. For example, if
280+
* the returned Map has keys {@literal http} and {@literal http.server}, an ID with a
281+
* name {@literal http.server.requests} would match with the entry having key
282+
* {@literal http.server}, whereas an ID with name {@literal http.client.requests}
283+
* would match with the entry having the key {@literal http}. This has no effect on a
284+
* meter if it does not have an exponential bucket histogram configured.
288285
* @return mapping of meter name to max bucket count
289286
* @since 1.15.0
290-
* @see io.micrometer.registry.otlp.OtlpMeterRegistry.MaxBucketsPerMeterLookup
291287
* @see #maxBucketCount()
292288
*/
293289
default Map<String, Integer> maxBucketsPerMeter() {

Diff for: implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java

+9-54
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,17 @@ public OtlpMeterRegistry(OtlpConfig config, Clock clock) {
116116
* @since 1.14.0
117117
*/
118118
public OtlpMeterRegistry(OtlpConfig config, Clock clock, ThreadFactory threadFactory) {
119-
this(config, clock, threadFactory, new OtlpHttpMetricsSender(new HttpUrlConnectionSender()),
120-
HistogramFlavorPerMeterLookup.DEFAULT, MaxBucketsPerMeterLookup.DEFAULT);
119+
this(config, clock, threadFactory, new OtlpHttpMetricsSender(new HttpUrlConnectionSender()));
121120
}
122121

123122
private OtlpMeterRegistry(OtlpConfig config, Clock clock, ThreadFactory threadFactory,
124-
OtlpMetricsSender metricsSender, HistogramFlavorPerMeterLookup histogramFlavorPerMeterLookup,
125-
MaxBucketsPerMeterLookup maxBucketsPerMeterLookup) {
123+
OtlpMetricsSender metricsSender) {
126124
super(config, clock);
127125
this.config = config;
128126
this.baseTimeUnit = config.baseTimeUnit();
129127
this.metricsSender = metricsSender;
130-
this.histogramFlavorPerMeterLookup = histogramFlavorPerMeterLookup;
131-
this.maxBucketsPerMeterLookup = maxBucketsPerMeterLookup;
128+
this.histogramFlavorPerMeterLookup = HistogramFlavorPerMeterLookup.DEFAULT;
129+
this.maxBucketsPerMeterLookup = MaxBucketsPerMeterLookup.DEFAULT;
132130
this.resource = Resource.newBuilder().addAllAttributes(getResourceAttributes()).build();
133131
this.aggregationTemporality = config.aggregationTemporality();
134132
config().namingConvention(NamingConvention.dot);
@@ -510,11 +508,10 @@ static double[] getSloWithPositiveInf(DistributionStatisticConfig distributionSt
510508

511509
/**
512510
* Overridable lookup mechanism for {@link HistogramFlavor}.
513-
*
514-
* @since 1.15.0
515511
*/
512+
// VisibleForTesting
516513
@FunctionalInterface
517-
public interface HistogramFlavorPerMeterLookup {
514+
interface HistogramFlavorPerMeterLookup {
518515

519516
/**
520517
* Default implementation.
@@ -542,11 +539,10 @@ public interface HistogramFlavorPerMeterLookup {
542539
/**
543540
* Overridable lookup mechanism for max bucket count. This has no effect on a meter if
544541
* it does not have an exponential bucket histogram configured.
545-
*
546-
* @since 1.15.0
547542
*/
543+
// VisibleForTesting
548544
@FunctionalInterface
549-
public interface MaxBucketsPerMeterLookup {
545+
interface MaxBucketsPerMeterLookup {
550546

551547
/**
552548
* Default implementation.
@@ -610,15 +606,9 @@ public static class Builder {
610606

611607
private OtlpMetricsSender metricsSender;
612608

613-
private HistogramFlavorPerMeterLookup histogramFlavorPerMeterLookup;
614-
615-
private MaxBucketsPerMeterLookup maxBucketsPerMeterLookup;
616-
617609
private Builder(OtlpConfig otlpConfig) {
618610
this.otlpConfig = otlpConfig;
619611
this.metricsSender = new OtlpHttpMetricsSender(new HttpUrlConnectionSender());
620-
this.histogramFlavorPerMeterLookup = HistogramFlavorPerMeterLookup.DEFAULT;
621-
this.maxBucketsPerMeterLookup = MaxBucketsPerMeterLookup.DEFAULT;
622612
}
623613

624614
/** Override the default clock. */
@@ -644,43 +634,8 @@ public Builder metricsSender(OtlpMetricsSender metricsSender) {
644634
return this;
645635
}
646636

647-
/**
648-
* Override the default matching behavior to use with
649-
* {@link OtlpConfig#histogramFlavorPerMeter()}. The default behavior is longest
650-
* dot-separated match wins. For example, if
651-
* {@link OtlpConfig#histogramFlavorPerMeter()} has keys {@literal http} and
652-
* {@literal http.server}, an ID with a name {@literal http.server.requests} would
653-
* match with the entry having key {@literal http.server}, whereas an ID with name
654-
* {@literal http.client.requests} would match with the entry having the key
655-
* {@literal http}.
656-
*
657-
* @see OtlpConfig#histogramFlavorPerMeter()
658-
*/
659-
public Builder histogramFlavorPerMeterLookup(HistogramFlavorPerMeterLookup histogramFlavorPerMeterLookup) {
660-
this.histogramFlavorPerMeterLookup = histogramFlavorPerMeterLookup;
661-
return this;
662-
}
663-
664-
/**
665-
* Override the default matching behavior to use with
666-
* {@link OtlpConfig#maxBucketsPerMeter()}. The default behavior is longest
667-
* dot-separated match wins. For example, if
668-
* {@link OtlpConfig#maxBucketsPerMeter()} has keys {@literal http} and
669-
* {@literal http.server}, an ID with a name {@literal http.server.requests} would
670-
* match with the entry having key {@literal http.server}, whereas an ID with name
671-
* {@literal http.client.requests} would match with the entry having the key
672-
* {@literal http}.
673-
*
674-
* @see OtlpConfig#maxBucketsPerMeter()
675-
*/
676-
public Builder maxBucketsPerMeterLookup(MaxBucketsPerMeterLookup maxBucketsPerMeterLookup) {
677-
this.maxBucketsPerMeterLookup = maxBucketsPerMeterLookup;
678-
return this;
679-
}
680-
681637
public OtlpMeterRegistry build() {
682-
return new OtlpMeterRegistry(otlpConfig, clock, threadFactory, metricsSender, histogramFlavorPerMeterLookup,
683-
maxBucketsPerMeterLookup);
638+
return new OtlpMeterRegistry(otlpConfig, clock, threadFactory, metricsSender);
684639
}
685640

686641
}

0 commit comments

Comments
 (0)