Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default value for OtlpMetricsProperties.url #44493

Closed
wants to merge 1 commit into from

Conversation

izeye
Copy link
Contributor

@izeye izeye commented Feb 28, 2025

Unlike Micrometer, Spring Boot's Micrometer integration doesn't support the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_METRICS_ENDPOINT environment variables due to its default value.

This PR removes the default value for the OtlpMetricsProperties.url property to try to align with Micrometer.

@mhalbritter
Copy link
Contributor

mhalbritter commented Mar 5, 2025

This would also align with OtlpLoggingProperties and OtlpTracingProperties, which have no default for their endpoint property.

It should also be transparent to the user, as the OtlpMetricsPropertiesConfigAdapter calls io.micrometer.registry.otlp.OtlpConfig#url when the property is null and this returns http://localhost:4318/v1/metrics as a default.

@@ -175,6 +175,7 @@ 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library has been added for mocking environment variables. But on the GitHub page it says:

From JDK16 onwards, there are deeper restrictions on the ability to use reflection. [...] Consequently, this library now uses bytebuddy to enable the interception of calls for reading environment variables. This might interact with your chosen version of Mockito or other libraries.

I wanted to know the team's opinion if we want to have that library for tests or if we want to ditch the tests (whenPropertiesUrlIsNotSetAndOtelExporterOtlpEndpointIsSetAdapterUrlUsesIt and whenPropertiesUrlIsNotSetAndOtelExporterOtlpMetricsEndpointIsSetAdapterUrlUsesIt).

Copy link
Contributor

@nosan nosan Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like these tests verify the Micrometer OtlpConfig implementation rather than the OtlpMetricsPropertiesConfigAdapter.

I believe OtlpMetricsPropertiesConfigAdapter tests can be a little updated to ensure that
adapter delegates to OtlpConfig.url() when the URL is not set.

@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());
	when(adapter.get("management.otlp.metrics.export.url")).thenReturn("https://my-endpoint/v1/metrics");
	assertThat(adapter.url()).isEqualTo("https://my-endpoint/v1/metrics");
}

In that case, uk.org.webcompere:system-stubs-jupiter:2.1.7 is unnecessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in favor of trying to mock environment variables so +1 for @nosan's suggestion.

More generally, where we need to test environment variables, we try to allow the Map to be injected for testing purposes. If third-party code doesn't allow that then I'd prefer that we accept that it can't be tested rather than relying on reflection to hack into System.getenv.

@mhalbritter mhalbritter added the for: team-attention An issue we'd like other members of the team to review label Mar 5, 2025
@wilkinsona wilkinsona added type: enhancement A general enhancement for: merge-with-amendments Needs some changes when we merge and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Mar 5, 2025
@wilkinsona wilkinsona added this to the 3.5.x milestone Mar 5, 2025
@mhalbritter mhalbritter self-assigned this Mar 6, 2025
mhalbritter pushed a commit that referenced this pull request Mar 6, 2025
@mhalbritter
Copy link
Contributor

Thanks @izeye !

@mhalbritter mhalbritter removed the for: merge-with-amendments Needs some changes when we merge label Mar 6, 2025
@mhalbritter mhalbritter modified the milestones: 3.5.x, 3.5.0-M3 Mar 6, 2025
@izeye izeye deleted the url-default-value branch March 6, 2025 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants