-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Create concept of persistent ThreadContext headers that are unstashable #8291
Create concept of persistent ThreadContext headers that are unstashable #8291
Conversation
…nd get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
server/src/test/java/org/opensearch/common/util/concurrent/ThreadContextTests.java
Show resolved
Hide resolved
server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java
Show resolved
Hide resolved
server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.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.
This PR is building up features around stashing context, what about eliminating the need for plugins to access this API, what would that take?
This feature adds overhead in latency/bandwidth to every transport request without providing a better security implementation in the short term.
@peternied One assurance that plugins cannot read from the persistent headers is that if an object is stored there that is only known to the plugin and no other plugins (i.e. the Security User object), then other plugins cannot read it since their classloaders don't have access to the Security User object. I am also looking at a more JSM style approach, or similar, that would let only the IdentityPlugin utilize the ThreadContext and no other plugins. Or making it more targeted and forbidding accessing certain headers or areas of the ThreadContext.
I have not measured that, but I don't anticipate a hit to performance by storing the authenticated user as a persistent header (not currently implemented yet in the security plugin). I will try to gather data on that, but the impact should be marginal. |
Gradle Check (Jenkins) Run Completed with:
|
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 don't see any problems here. @peternied do you have strong objections to merging this?
server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
End of the day we've got the performance testing requirements pre-release and we can use that to detect issues, lets lean on those instead of trying to micro-optimize/analyze in this scenario. Lets merge this and keep iteration - thanks for the contribution @cwperks |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-8291-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 2f9728e8398e923cbbb93e36dd52c22e02612a8d
# Push it to GitHub
git push --set-upstream origin backport/backport-8291-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-2.x Then, create a pull request where the |
will need a manual backport, as usual |
Creating a manual backport now |
…le (opensearch-project#8291) * Add unstashable section of a threadcontext by adding ability to put and get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove new lines from top of CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Only one threadLocal Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Single putPersistent and getPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unnecessary line Signed-off-by: Craig Perkins <cwperx@amazon.com> * Chain putPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> (cherry picked from commit 2f9728e)
…le (#8291) (#8507) * Add unstashable section of a threadcontext by adding ability to put and get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove new lines from top of CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Only one threadLocal Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Single putPersistent and getPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unnecessary line Signed-off-by: Craig Perkins <cwperx@amazon.com> * Chain putPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> (cherry picked from commit 2f9728e)
…le (opensearch-project#8291) * Add unstashable section of a threadcontext by adding ability to put and get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove new lines from top of CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Only one threadLocal Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Single putPersistent and getPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unnecessary line Signed-off-by: Craig Perkins <cwperx@amazon.com> * Chain putPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
…le (opensearch-project#8291) * Add unstashable section of a threadcontext by adding ability to put and get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove new lines from top of CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Only one threadLocal Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Single putPersistent and getPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unnecessary line Signed-off-by: Craig Perkins <cwperx@amazon.com> * Chain putPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
…le (opensearch-project#8291) * Add unstashable section of a threadcontext by adding ability to put and get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove new lines from top of CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Only one threadLocal Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Single putPersistent and getPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unnecessary line Signed-off-by: Craig Perkins <cwperx@amazon.com> * Chain putPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Signed-off-by: sahil buddharaju <sahilbud@amazon.com>
…le (opensearch-project#8291) * Add unstashable section of a threadcontext by adding ability to put and get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove new lines from top of CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Only one threadLocal Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Single putPersistent and getPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unnecessary line Signed-off-by: Craig Perkins <cwperx@amazon.com> * Chain putPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
…le (opensearch-project#8291) * Add unstashable section of a threadcontext by adding ability to put and get durable headers and transient headers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove new lines from top of CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Only one threadLocal Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Single putPersistent and getPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unnecessary line Signed-off-by: Craig Perkins <cwperx@amazon.com> * Chain putPersistent Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Signed-off-by: Shivansh Arora <hishiv@amazon.com>
Description
This PR introduces the concept of "persistent" ThreadContext headers modeled after transient headers. These headers perform exactly the same as ThreadContext headers, but are not stashable and will always be available even inside a block where the ThreadContext has been stashed.
Some additional context on the ThreadContext:
The values in the ThreadContext are immutable after they have already been written to once. If a caller tries to overwrite an existing ThreadContext header than the caller will receive an IllegalArgumentException.
Related Issues
Resolves opensearch-project/security#2909
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.