-
Notifications
You must be signed in to change notification settings - Fork 923
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
Conversation
Motivation: Modifications: - Add `ContextStorage` and its default implementation `ContextStorageThreadLocal`. - Add `ContextStorageProvier` so that a user customizes the `ContextStorage` using Java SPI Result:
I need to add Javadoc, but I wanted to get some feedback especially for naming before I finish. PTAL |
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.
Basically looks good, thanks!
core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientRequestContext.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/ContextStorage.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/ContextStorageThreadLocal.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/ContextStorageThreadLocal.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/RequestContextUtil.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/RequestContextUtil.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/RequestContextUtil.java
Outdated
Show resolved
Hide resolved
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.
@anuraaga already commented everything important, so not much to add. 😅
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
1897d23
to
b9c59b6
Compare
core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java
Outdated
Show resolved
Hide resolved
ServiceLoader.load(ContextStorageProvider.class)); | ||
final String contextStorageFqcn = Flags.contextStorage(); | ||
if (!providers.isEmpty()) { | ||
if (providers.size() > 1) { |
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.
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
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.
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. 😉
core/src/main/java/com/linecorp/armeria/common/ContextStorage.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/ContextStorage.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/RequestContextUtil.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/ThreadLocalContextStorage.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ 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 Continue to review full report at Codecov.
|
core/src/main/java/com/linecorp/armeria/common/RequestContextStorage.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/ThreadLocalRequestContextStorage.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/RequestContextUtil.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/RequestContextUtil.java
Show resolved
Hide resolved
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.
Thanks a lot! @minwoox 👍
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.
Thanks, looks great
core/src/main/java/com/linecorp/armeria/common/ThreadLocalRequestContextStorage.java
Outdated
Show resolved
Hide resolved
} catch (Throwable t) { | ||
throw new IllegalStateException("Failed to create context storage. provider: " + provider, t); | ||
} | ||
logger.info("{} is used to create the request context storage: {}", |
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 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.
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 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()
).
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.
But I guess showing the created storage context is too verbose. Fixed. Thank you!
Thanks for reviewing! |
…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
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:
RequestContextStorage
.RequestContextStorageProvier
so that a user customizes theContextStorage
using Java SPIResult:
RequestContext
.RequestContext
#2514