Skip to content

Commit 75f72b6

Browse files
izeyemhalbritter
authored andcommitted
Remove default value for OtlpMetricsProperties.url
See gh-44493 Signed-off-by: Johnny Lim <[email protected]>
1 parent ccfc1ae commit 75f72b6

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ dependencies {
174174
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")
175175
testImplementation("org.springframework.security:spring-security-test")
176176
testImplementation("org.yaml:snakeyaml")
177+
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.1.7")
177178

178179
testRuntimeOnly("jakarta.management.j2ee:jakarta.management.j2ee-api")
179180
testRuntimeOnly("jakarta.transaction:jakarta.transaction-api")

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class OtlpMetricsProperties extends StepRegistryProperties {
3939
/**
4040
* URI of the OTLP server.
4141
*/
42-
private String url = "http://localhost:4318/v1/metrics";
42+
private String url;
4343

4444
/**
4545
* Aggregation temporality of sums. It defines the way additive values are expressed.

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

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.micrometer.registry.otlp.HistogramFlavor;
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
26+
import uk.org.webcompere.systemstubs.SystemStubs;
2627

2728
import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsExportAutoConfiguration.PropertiesOtlpMetricsConnectionDetails;
2829
import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryProperties;
@@ -54,6 +55,23 @@ void setUp() {
5455
this.connectionDetails = new PropertiesOtlpMetricsConnectionDetails(this.properties);
5556
}
5657

58+
@Test
59+
void whenPropertiesUrlIsNotSetAdapterUrlReturnsDefault() {
60+
assertThat(createAdapter().url()).isEqualTo("http://localhost:4318/v1/metrics");
61+
}
62+
63+
@Test
64+
void whenPropertiesUrlIsNotSetAndOtelExporterOtlpEndpointIsSetAdapterUrlUsesIt() throws Exception {
65+
SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", "https://my-endpoint")
66+
.execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics"));
67+
}
68+
69+
@Test
70+
void whenPropertiesUrlIsNotSetAndOtelExporterOtlpMetricsEndpointIsSetAdapterUrlUsesIt() throws Exception {
71+
SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://my-endpoint")
72+
.execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics"));
73+
}
74+
5775
@Test
5876
void whenPropertiesUrlIsSetAdapterUrlReturnsIt() {
5977
this.properties.setUrl("http://another-url:4318/v1/metrics");

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

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ void defaultValuesAreConsistent() {
3535
OtlpMetricsProperties properties = new OtlpMetricsProperties();
3636
OtlpConfig config = OtlpConfig.DEFAULT;
3737
assertStepRegistryDefaultValues(properties, config);
38-
assertThat(properties.getUrl()).isEqualTo(config.url());
3938
assertThat(properties.getAggregationTemporality()).isSameAs(config.aggregationTemporality());
4039
assertThat(properties.getHistogramFlavor()).isSameAs(config.histogramFlavor());
4140
assertThat(properties.getMaxScale()).isEqualTo(config.maxScale());

0 commit comments

Comments
 (0)