Skip to content

Commit 6cd6f75

Browse files
committed
Add configuration support for ExponentialHistogram in OTLP Registry
Closes gh-41837
1 parent 807a38f commit 6cd6f75

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpProperties.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.util.concurrent.TimeUnit;
2121

2222
import io.micrometer.registry.otlp.AggregationTemporality;
23+
import io.micrometer.registry.otlp.HistogramFlavor;
2324

2425
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
2526
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -57,6 +58,22 @@ public class OtlpProperties extends StepRegistryProperties {
5758
*/
5859
private Map<String, String> headers;
5960

61+
/**
62+
* Histogram type to be preferred when histogram publishing is enabled.
63+
*/
64+
private HistogramFlavor histogramFlavor = HistogramFlavor.EXPLICIT_BUCKET_HISTOGRAM;
65+
66+
/**
67+
* Max scale to use for exponential histograms, if configured.
68+
*/
69+
private int maxScale = 20;
70+
71+
/**
72+
* Maximum number of buckets to be used for exponential histograms, if configured.
73+
* This has no effect on explicit bucket histograms.
74+
*/
75+
private int maxBucketCount = 160;
76+
6077
/**
6178
* Time unit for exported metrics.
6279
*/
@@ -97,6 +114,30 @@ public void setHeaders(Map<String, String> headers) {
97114
this.headers = headers;
98115
}
99116

117+
public HistogramFlavor getHistogramFlavor() {
118+
return this.histogramFlavor;
119+
}
120+
121+
public void setHistogramFlavor(HistogramFlavor histogramFlavor) {
122+
this.histogramFlavor = histogramFlavor;
123+
}
124+
125+
public int getMaxScale() {
126+
return this.maxScale;
127+
}
128+
129+
public void setMaxScale(int maxScale) {
130+
this.maxScale = maxScale;
131+
}
132+
133+
public int getMaxBucketCount() {
134+
return this.maxBucketCount;
135+
}
136+
137+
public void setMaxBucketCount(int maxBucketCount) {
138+
this.maxBucketCount = maxBucketCount;
139+
}
140+
100141
public TimeUnit getBaseTimeUnit() {
101142
return this.baseTimeUnit;
102143
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.TimeUnit;
2323

2424
import io.micrometer.registry.otlp.AggregationTemporality;
25+
import io.micrometer.registry.otlp.HistogramFlavor;
2526
import io.micrometer.registry.otlp.OtlpConfig;
2627

2728
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
@@ -98,6 +99,21 @@ public Map<String, String> headers() {
9899
return get(OtlpProperties::getHeaders, OtlpConfig.super::headers);
99100
}
100101

102+
@Override
103+
public HistogramFlavor histogramFlavor() {
104+
return get(OtlpProperties::getHistogramFlavor, OtlpConfig.super::histogramFlavor);
105+
}
106+
107+
@Override
108+
public int maxScale() {
109+
return get(OtlpProperties::getMaxScale, OtlpConfig.super::maxScale);
110+
}
111+
112+
@Override
113+
public int maxBucketCount() {
114+
return get(OtlpProperties::getMaxBucketCount, OtlpConfig.super::maxBucketCount);
115+
}
116+
101117
@Override
102118
public TimeUnit baseTimeUnit() {
103119
return get(OtlpProperties::getBaseTimeUnit, OtlpConfig.super::baseTimeUnit);

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.concurrent.TimeUnit;
2222

2323
import io.micrometer.registry.otlp.AggregationTemporality;
24+
import io.micrometer.registry.otlp.HistogramFlavor;
2425
import org.junit.jupiter.api.BeforeEach;
2526
import org.junit.jupiter.api.Test;
2627

@@ -85,6 +86,39 @@ void whenPropertiesHeadersIsSetAdapterHeadersReturnsIt() {
8586
assertThat(createAdapter().headers()).containsEntry("header", "value");
8687
}
8788

89+
@Test
90+
void whenPropertiesHistogramFlavorIsNotSetAdapterHistogramFlavorReturnsExplicitBucketHistogram() {
91+
assertThat(createAdapter().histogramFlavor()).isSameAs(HistogramFlavor.EXPLICIT_BUCKET_HISTOGRAM);
92+
}
93+
94+
@Test
95+
void whenPropertiesHistogramFlavorIsSetAdapterHistogramFlavorReturnsIt() {
96+
this.properties.setHistogramFlavor(HistogramFlavor.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM);
97+
assertThat(createAdapter().histogramFlavor()).isSameAs(HistogramFlavor.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM);
98+
}
99+
100+
@Test
101+
void whenPropertiesMaxScaleIsNotSetAdapterMaxScaleReturns20() {
102+
assertThat(createAdapter().maxScale()).isEqualTo(20);
103+
}
104+
105+
@Test
106+
void whenPropertiesMaxScaleIsSetAdapterMaxScaleReturnsIt() {
107+
this.properties.setMaxScale(5);
108+
assertThat(createAdapter().maxScale()).isEqualTo(5);
109+
}
110+
111+
@Test
112+
void whenPropertiesMaxBucketCountIsNotSetAdapterMaxBucketCountReturns160() {
113+
assertThat(createAdapter().maxBucketCount()).isEqualTo(160);
114+
}
115+
116+
@Test
117+
void whenPropertiesMaxBucketCountIsSetAdapterMaxBucketCountReturnsIt() {
118+
this.properties.setMaxBucketCount(6);
119+
assertThat(createAdapter().maxBucketCount()).isEqualTo(6);
120+
}
121+
88122
@Test
89123
void whenPropertiesBaseTimeUnitIsNotSetAdapterBaseTimeUnitReturnsMillis() {
90124
assertThat(createAdapter().baseTimeUnit()).isSameAs(TimeUnit.MILLISECONDS);

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,9 @@ void defaultValuesAreConsistent() {
3737
assertStepRegistryDefaultValues(properties, config);
3838
assertThat(properties.getUrl()).isEqualTo(config.url());
3939
assertThat(properties.getAggregationTemporality()).isSameAs(config.aggregationTemporality());
40+
assertThat(properties.getHistogramFlavor()).isSameAs(config.histogramFlavor());
41+
assertThat(properties.getMaxScale()).isEqualTo(config.maxScale());
42+
assertThat(properties.getMaxBucketCount()).isEqualTo(config.maxBucketCount());
4043
assertThat(properties.getBaseTimeUnit()).isSameAs(config.baseTimeUnit());
4144
}
4245

0 commit comments

Comments
 (0)