From 4dabf16a06e29ebad2296b3a691f36bf3c144054 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 6 Mar 2025 09:36:07 +0100 Subject: [PATCH] Polish "Remove default value for OtlpMetricsProperties.url" See gh-44493 --- .../build.gradle | 1 - ...tlpMetricsPropertiesConfigAdapterTests.java | 18 ++++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index d4d86281937..0b30ced72d3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -174,7 +174,6 @@ dependencies { testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient") testImplementation("org.springframework.security:spring-security-test") testImplementation("org.yaml:snakeyaml") - testImplementation("uk.org.webcompere:system-stubs-jupiter:2.1.7") testRuntimeOnly("jakarta.management.j2ee:jakarta.management.j2ee-api") testRuntimeOnly("jakarta.transaction:jakarta.transaction-api") diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java index 8a157249cee..93ef9fa3f5f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java @@ -23,13 +23,14 @@ import io.micrometer.registry.otlp.AggregationTemporality; import io.micrometer.registry.otlp.HistogramFlavor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import uk.org.webcompere.systemstubs.SystemStubs; import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsExportAutoConfiguration.PropertiesOtlpMetricsConnectionDetails; import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryProperties; import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.spy; /** * Tests for {@link OtlpMetricsPropertiesConfigAdapter}. @@ -57,19 +58,16 @@ class OtlpMetricsPropertiesConfigAdapterTests { @Test void whenPropertiesUrlIsNotSetAdapterUrlReturnsDefault() { + assertThat(this.properties.getUrl()).isNull(); assertThat(createAdapter().url()).isEqualTo("http://localhost:4318/v1/metrics"); } @Test - void whenPropertiesUrlIsNotSetAndOtelExporterOtlpEndpointIsSetAdapterUrlUsesIt() throws Exception { - SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", "https://my-endpoint") - .execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics")); - } - - @Test - void whenPropertiesUrlIsNotSetAndOtelExporterOtlpMetricsEndpointIsSetAdapterUrlUsesIt() throws Exception { - SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://my-endpoint") - .execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics")); + void whenPropertiesUrlIsNotSetThanUseOtlpConfigUrlAsFallback() { + assertThat(this.properties.getUrl()).isNull(); + OtlpMetricsPropertiesConfigAdapter adapter = spy(createAdapter()); + given(adapter.get("management.otlp.metrics.export.url")).willReturn("https://my-endpoint/v1/metrics"); + assertThat(adapter.url()).isEqualTo("https://my-endpoint/v1/metrics"); } @Test