Polish "Remove default value for OtlpMetricsProperties.url"

See gh-44493
This commit is contained in:
Moritz Halbritter 2025-03-06 09:36:07 +01:00
parent 75f72b6ee7
commit 4dabf16a06
2 changed files with 8 additions and 11 deletions

View File

@ -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")

View File

@ -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