-
Notifications
You must be signed in to change notification settings - Fork 41k
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
Conversation
Signed-off-by: Johnny Lim <[email protected]>
This would also align with It should also be transparent to the user, as the |
@@ -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") |
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
See gh-44493 Signed-off-by: Johnny Lim <[email protected]>
Thanks @izeye ! |
Unlike Micrometer, Spring Boot's Micrometer integration doesn't support the
OTEL_EXPORTER_OTLP_ENDPOINT
andOTEL_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.