Polish "Remove default value for OtlpMetricsProperties.url"
See gh-44493
This commit is contained in:
parent
75f72b6ee7
commit
4dabf16a06
|
@ -174,7 +174,6 @@ dependencies {
|
||||||
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")
|
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation("org.springframework.security:spring-security-test")
|
||||||
testImplementation("org.yaml:snakeyaml")
|
testImplementation("org.yaml:snakeyaml")
|
||||||
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.1.7")
|
|
||||||
|
|
||||||
testRuntimeOnly("jakarta.management.j2ee:jakarta.management.j2ee-api")
|
testRuntimeOnly("jakarta.management.j2ee:jakarta.management.j2ee-api")
|
||||||
testRuntimeOnly("jakarta.transaction:jakarta.transaction-api")
|
testRuntimeOnly("jakarta.transaction:jakarta.transaction-api")
|
||||||
|
|
|
@ -23,13 +23,14 @@ import io.micrometer.registry.otlp.AggregationTemporality;
|
||||||
import io.micrometer.registry.otlp.HistogramFlavor;
|
import io.micrometer.registry.otlp.HistogramFlavor;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.metrics.export.otlp.OtlpMetricsExportAutoConfiguration.PropertiesOtlpMetricsConnectionDetails;
|
||||||
import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryProperties;
|
import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryProperties;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link OtlpMetricsPropertiesConfigAdapter}.
|
* Tests for {@link OtlpMetricsPropertiesConfigAdapter}.
|
||||||
|
@ -57,19 +58,16 @@ class OtlpMetricsPropertiesConfigAdapterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenPropertiesUrlIsNotSetAdapterUrlReturnsDefault() {
|
void whenPropertiesUrlIsNotSetAdapterUrlReturnsDefault() {
|
||||||
|
assertThat(this.properties.getUrl()).isNull();
|
||||||
assertThat(createAdapter().url()).isEqualTo("http://localhost:4318/v1/metrics");
|
assertThat(createAdapter().url()).isEqualTo("http://localhost:4318/v1/metrics");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenPropertiesUrlIsNotSetAndOtelExporterOtlpEndpointIsSetAdapterUrlUsesIt() throws Exception {
|
void whenPropertiesUrlIsNotSetThanUseOtlpConfigUrlAsFallback() {
|
||||||
SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", "https://my-endpoint")
|
assertThat(this.properties.getUrl()).isNull();
|
||||||
.execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics"));
|
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
|
|
||||||
void whenPropertiesUrlIsNotSetAndOtelExporterOtlpMetricsEndpointIsSetAdapterUrlUsesIt() throws Exception {
|
|
||||||
SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://my-endpoint")
|
|
||||||
.execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue