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

Introduce ObservationThreadLocalTestExecutionListener in the TestContext framework #30651

Conversation

marcingrzejszczak
Copy link
Contributor

@marcingrzejszczak marcingrzejszczak commented Jun 12, 2023

Without this change we have no way to pass the ObservationRegistry that is registered in the given test's ApplicationContext as the one that should be used by the ObservationThreadLocalAccessor.

With this change we introduce a TestExecutionListener that will set an ObservationRegistry registered in the test's ApplicationContext for each test class and after each test class will restore the previously stored ObservationRegistry instance.

without this change we have no option to pass the ObservationRegistry that is registered in the given TestContext's ApplicationContext as the one that should be used by the ObservationThreadLocalAccessor.

with this change we create a TestExecutionListener that will set an ObservationRegistry registered in the TestContext's ApplicationContext for each test class and after each test class will restore the previously stored ObservationRegistry instance
@marcingrzejszczak
Copy link
Contributor Author

cc @rstoyanchev after upgrading the context propagation library I needed to update one class

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 12, 2023
Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

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

I'm only commenting on the change in spring-webmvc. I have not reviewed the spring-test changes.

@sbrannen sbrannen changed the title Added ObservationThreadLocalTestListener Introduce ObservationThreadLocalTestExecutionListener in the TestContext framework Jun 13, 2023
@sbrannen sbrannen added in: test Issues in the test module type: enhancement A general enhancement labels Jun 13, 2023
Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

I've made an initial review and requested several changes.

I've also raised a few points that need to be decided on.

spring-test/spring-test.gradle Show resolved Hide resolved
* This implementation is not thread-safe.
*
* @author Marcin Grzejszczak
* @since 6.0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @since 6.0
* @since 6.1

I imagine this would be added in 6.1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've made the whole train of changes in Micrometer Core (1.10.8), Context Propagation (1.0.3), Micrometer Tracing (1.0.7) and Reactor all in patch versions to fix bugs related to context propagation with reactor. We need this to be working in a patch release IMO. Without this change context propagation will not work properly. I would say that adding this component is a bug fix not an enhancement.

@sbrannen sbrannen marked this pull request as draft June 13, 2023 09:35
@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 13, 2023
@sbrannen sbrannen added this to the 6.1.x milestone Jun 13, 2023
marcingrzejszczak and others added 8 commits June 13, 2023 11:47
…ervation/ObservationThreadLocalTestListener.java

Co-authored-by: Sam Brannen <sam@sambrannen.com>
…ervation/ObservationThreadLocalTestListener.java

Co-authored-by: Sam Brannen <sam@sambrannen.com>
…ervation/ObservationThreadLocalTestListener.java

Co-authored-by: Sam Brannen <sam@sambrannen.com>
…ervation/package-info.java

Co-authored-by: Sam Brannen <sam@sambrannen.com>
…ervation/ObservationThreadLocalTestListenerTests.java

Co-authored-by: Sam Brannen <sam@sambrannen.com>
- dependencies ordered alphabetically
- renamed the test execution listener to contain "execution" and "micrometer" in the name
- production code lines are smaller (up to 100 chars)
- test execution attribute is a private static final field
- added javadocs in the test execution listener
@marcingrzejszczak
Copy link
Contributor Author

marcingrzejszczak commented Jun 13, 2023

@sbrannen sbrannen added status: superseded An issue that has been superseded by another and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 13, 2023
@sbrannen sbrannen removed this from the 6.1.x milestone Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants