Merge pull request #44493 from izeye

* pr/44493:
  Polish "Remove default value for OtlpMetricsProperties.url"
  Remove default value for OtlpMetricsProperties.url

Closes gh-44493
This commit is contained in:
Moritz Halbritter 2025-03-06 09:40:12 +01:00
commit d5f8008276
3 changed files with 17 additions and 2 deletions

View File

@ -39,7 +39,7 @@ public class OtlpMetricsProperties extends StepRegistryProperties {
/**
* URI of the OTLP server.
*/
private String url = "http://localhost:4318/v1/metrics";
private String url;
/**
* Aggregation temporality of sums. It defines the way additive values are expressed.

View File

@ -29,6 +29,8 @@ import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetr
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}.
@ -54,6 +56,20 @@ class OtlpMetricsPropertiesConfigAdapterTests {
this.connectionDetails = new PropertiesOtlpMetricsConnectionDetails(this.properties);
}
@Test
void whenPropertiesUrlIsNotSetAdapterUrlReturnsDefault() {
assertThat(this.properties.getUrl()).isNull();
assertThat(createAdapter().url()).isEqualTo("http://localhost:4318/v1/metrics");
}
@Test
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
void whenPropertiesUrlIsSetAdapterUrlReturnsIt() {
this.properties.setUrl("http://another-url:4318/v1/metrics");

View File

@ -35,7 +35,6 @@ class OtlpMetricsPropertiesTests extends StepRegistryPropertiesTests {
OtlpMetricsProperties properties = new OtlpMetricsProperties();
OtlpConfig config = OtlpConfig.DEFAULT;
assertStepRegistryDefaultValues(properties, config);
assertThat(properties.getUrl()).isEqualTo(config.url());
assertThat(properties.getAggregationTemporality()).isSameAs(config.aggregationTemporality());
assertThat(properties.getHistogramFlavor()).isSameAs(config.histogramFlavor());
assertThat(properties.getMaxScale()).isEqualTo(config.maxScale());