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

Provide a way to customize context propagation using its own storage #2610

Merged
merged 13 commits into from
Mar 25, 2020

Conversation

minwoox
Copy link
Member

@minwoox minwoox commented Mar 19, 2020

Motivation:
Related #2375 (comment)
It will be good if we provide a way to customize the context storage so that a user can do the scope management by him/herself.

Modifications:

  • Add RequestContextStorage.
  • Add RequestContextStorageProvier so that a user customizes the ContextStorage using Java SPI

Result:

Motivation:

Modifications:
- Add `ContextStorage` and its default implementation `ContextStorageThreadLocal`.
- Add `ContextStorageProvier` so that a user customizes the `ContextStorage` using Java SPI

Result:
@minwoox minwoox added this to the 0.99.0 milestone Mar 19, 2020
@minwoox minwoox requested review from trustin, anuraaga and ikhoon March 19, 2020 02:39
@minwoox
Copy link
Member Author

minwoox commented Mar 19, 2020

I need to add Javadoc, but I wanted to get some feedback especially for naming before I finish. PTAL

Copy link
Collaborator

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Basically looks good, thanks!

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

@anuraaga already commented everything important, so not much to add. 😅

@minwoox minwoox force-pushed the add_context_storage branch from 1897d23 to b9c59b6 Compare March 19, 2020 07:59
@minwoox minwoox marked this pull request as ready for review March 19, 2020 08:02
@minwoox
Copy link
Member Author

minwoox commented Mar 19, 2020

@anuraaga and @trustin, I updated. PTAL. 🙇
Will update the commit message later.

ServiceLoader.load(ContextStorageProvider.class));
final String contextStorageFqcn = Flags.contextStorage();
if (!providers.isEmpty()) {
if (providers.size() > 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I was thinking instead of loading directly from the flag, we'd use the flag to disambiguate among the different providers in this case. I guess we can do both though

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I guess I totally misunderstood. 🤣
So you meant when multiple providers exist (e.g com.x.AProvider, io.x.BProvider...), if the flag is io.x.BProvider, then we should choose the BProvider class. Right?

If so, I want to get rid of the current way and follow it because, I think, there would be a case who wants to use two different JARs that have their own RequestContextStorage.
So I think we should choose one of them instead of throwing an exception. 😉

@codecov
Copy link

codecov bot commented Mar 19, 2020

Codecov Report

Merging #2610 into master will decrease coverage by 0.06%.
The diff coverage is 59.03%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2610      +/-   ##
============================================
- Coverage     73.35%   73.29%   -0.07%     
- Complexity    11047    11060      +13     
============================================
  Files           971      972       +1     
  Lines         42518    42588      +70     
  Branches       5294     5309      +15     
============================================
+ Hits          31191    31216      +25     
- Misses         8617     8658      +41     
- Partials       2710     2714       +4     
Impacted Files Coverage Δ Complexity Δ
...rp/armeria/internal/common/RequestContextUtil.java 46.66% <30.43%> (-53.34%) 12.00 <7.00> (+4.00) ⬇️
...meria/common/ThreadLocalRequestContextStorage.java 87.50% <87.50%> (ø) 4.00 <4.00> (?)
.../linecorp/armeria/client/ClientFactoryBuilder.java 65.85% <100.00%> (+0.42%) 42.00 <1.00> (+1.00)
.../linecorp/armeria/client/ClientRequestContext.java 70.00% <100.00%> (ø) 22.00 <9.00> (+1.00)
...c/main/java/com/linecorp/armeria/common/Flags.java 61.77% <100.00%> (+0.44%) 61.00 <1.00> (+1.00)
...va/com/linecorp/armeria/common/RequestContext.java 62.96% <100.00%> (-1.33%) 19.00 <3.00> (-1.00)
...linecorp/armeria/common/RequestContextStorage.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
...ava/com/linecorp/armeria/server/ServerBuilder.java 79.61% <100.00%> (+0.11%) 105.00 <0.00> (ø)
...linecorp/armeria/server/ServiceRequestContext.java 73.07% <100.00%> (ø) 22.00 <7.00> (+1.00)
.../java/com/linecorp/armeria/client/HttpSession.java 41.17% <0.00%> (-5.50%) 5.00% <0.00%> (ø%)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e0cdb1...ccf427a. Read the comment docs.

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks a lot! @minwoox 👍

Copy link
Collaborator

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Thanks, looks great

} catch (Throwable t) {
throw new IllegalStateException("Failed to create context storage. provider: " + provider, t);
}
logger.info("{} is used to create the request context storage: {}",
Copy link
Member

Choose a reason for hiding this comment

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

I actually meant not logging when:

  • using the default provider (because it may be noisy.)
  • specified via the flag (because it's logged there already.)

i.e. we can log in the else {} block above.

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 thought it might be useful to show the information of the created request context storage after it's fully created. (i.e. no exception when calling newStorage()).

Copy link
Member Author

Choose a reason for hiding this comment

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

But I guess showing the created storage context is too verbose. Fixed. Thank you!

@trustin trustin merged commit b297e73 into line:master Mar 25, 2020
@minwoox minwoox deleted the add_context_storage branch March 25, 2020 01:08
@minwoox
Copy link
Member Author

minwoox commented Mar 25, 2020

Thanks for reviewing!

fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
…e#2610)

Motivation:
Related line#2375 (comment)
It will be good if we provide a way to customize the context storage so that a user can do the scope management by him/herself.

Modifications:
- Add `RequestContextStorage`.
- Add `RequestContextStorageProvier` so that a user customizes the `ContextStorage` using Java SPI

Result:
- You can, now, create your own storage to store `RequestContext`.
- Close line#2514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding hooks back to RequestContext
4 participants