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

Context propagation: use new APIs from latest snapshots #3256

Merged
merged 3 commits into from Nov 2, 2022

Conversation

simonbasle
Copy link
Member

  • Depend on post-RC1 snapshots of context-propagation
  • Use ContextSnapshot.setAllThreadLocalsFrom
  • Remove registry and intermediary classes, use Supplier

With the introduction of removal methods in ContextRegistry, it becomes
more practical to use the ContextRegistry.getInstance global instance.
Following that, two of the three intermediate classes are no longer
needed and can be replaced with lambdas: ContextCaptureFunction and
ContextRestoreHandleConsumer.

Instead of calling the ContextPropagation methods with a subscriber
(which necessitates some mocking in tests), we now take a Supplier
of Context. A CoreSubscriber::currentContext method reference can
do the trick in production code.
@simonbasle simonbasle requested a review from a team as a code owner October 27, 2022 13:36
@simonbasle simonbasle added this to the 3.5.0 milestone Oct 27, 2022
@simonbasle simonbasle added the type/enhancement A general enhancement label Oct 27, 2022
@simonbasle simonbasle self-assigned this Oct 27, 2022
@simonbasle simonbasle added area/context This issue is related to the Context area/observability labels Oct 27, 2022
}

static <T, R> BiConsumer<T, SynchronousSink<R>> contextRestoreForHandle(BiConsumer<T, SynchronousSink<R>> handler, CoreSubscriber<? super R> actual) {
if (!ContextPropagation.isContextPropagationAvailable() || actual.currentContext().isEmpty()) {
static <T, R> BiConsumer<T, SynchronousSink<R>> contextRestoreForHandle(BiConsumer<T, SynchronousSink<R>> handler, Supplier<Context> contextSupplier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just a small comment that the supplier can be overhead for the mono case since one extra object is allocated per subscriber * per operator. I guess that the goal was to avoid context retrieval if there is no need, but not sure what brings more impact.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is fine since the Supplier in the hot path is CoreSubscriber::currentContext (ie. a method reference).

@simonbasle simonbasle changed the title Context propagation: use new APIs in latest snapshots Context propagation: use new APIs from latest snapshots Nov 2, 2022
@simonbasle simonbasle merged commit a62e031 into main Nov 2, 2022
@simonbasle simonbasle deleted the latestContextPropagationApis branch November 2, 2022 13:45
@chemicL
Copy link
Member

chemicL commented Nov 3, 2022

Late LGTM 👍

@simonbasle
Copy link
Member Author

this also fixes #3244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/context This issue is related to the Context area/observability type/enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants