-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fix thread context propagation in TransportClusterUpdateSettingsAction #127799
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
Fix thread context propagation in TransportClusterUpdateSettingsAction #127799
Conversation
This fixes the settings API to properly return deprecation warning headers when updating deprecated settings, while properly associating them with the correct correlation id. Previously, the correlation id of the original context wasn't propagated to the cluster state update task. However, using `newRestorableContext(preserveResponseHeaders=true)` isn't enough to also - in case - propagate warning headers back to the task's thread context and hence can't be captured by the task executor in MasterService to return the response headers back to the caller. This PR adds a new variant of `newRestorableContext` that supports propagation of response headers if required. Fixes elastic#108628 (DeprecationHttpIT.testDeprecatedSettingsReturnWarnings)
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
ldematte
left a comment
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.
So, we had already newStoredContextPreservingResponseHeaders, but this PR exposes it via newRestorableContext (and that fixes the issue with deprecation warnings, but also with other response headers).
Nice :)
DaveCTurner
left a comment
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.
Hmm I'm confused is this not what org.elasticsearch.cluster.service.MasterService.ExecutionResult#captureResponseHeaders is supposed to do already? If there's a problem with propagating response headers back then it needs fixing in MasterService doesn't it?
|
@DaveCTurner this is necessary for An option I considered was to automatically create such a thread context supplier for TransportMasterNodeAction to make sure this is always the case. |
|
@DaveCTurner To explain further, if I don't restore the previously stored context (which includes the correlation id) as child context in However, if using Definitely agree, a more general fix would be better here. This is really extremely hard to get right :( |
Yep that's my confusion, the whole point of |
|
Oh wait I think I see, the Does this work? diff --git a/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java b/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java
index c46b3b7d6618..05fa03283d06 100644
--- a/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java
+++ b/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java
@@ -913,7 +913,7 @@ public class MasterService extends AbstractLifecycleComponent {
@Override
public Releasable captureResponseHeaders() {
- final var storedContext = threadContext.newStoredContext();
+ final var storedContext = threadContextSupplier.get();
return Releasables.wrap(() -> {
final var newResponseHeaders = threadContext.getResponseHeaders();
if (newResponseHeaders.isEmpty()) { |
I'll give it a try, |
|
🎉 you're a wizard @DaveCTurner 🧙 I wasn't aware the task already captures the context it was originally created in, that's what I had in mind as alternative above. If I don't have to manually restore that original context myself in |
…ngsAction" This reverts commit 0dc6df6.
…as originally created. MasterService used to execute tasks in a completely empty context rather than the original context which was captured when the task was created. Fixes elastic#108628 (DeprecationHttpIT.testDeprecatedSettingsReturnWarnings)
|
@DaveCTurner any concerns that this is having an undesirable / negative impact in some places when changed globally? |
|
IMO it makes more sense than what we do today everywhere I can think of: |
DaveCTurner
left a comment
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.
LGTM assuming CI is happy
|
@DaveCTurner currently looking into profiling yaml specs, these do fail with this change due to deprecation warnings bubbling up which got swallowed before: |
|
I thought we had fixed these towards 9, wondering if this was missed because the warnings never surfaced ... |
|
Yes, that's good, shows the change is working :). Makes sense to me to just mark those warnings as acceptable in the tests. |
…as originally created (elastic#127799) Previously MasterService executed tasks in a completely empty context rather than the original context which was captured when the task was created. This PR fixes MasterService to restore and use the original context. Fixes elastic#108628
Fix MasterService to execute tasks in the context in which the task was originally created.
MasterService used to execute tasks in a completely empty context rather than the original context which was captured when the task was created.
This fixes the settings API to properly return deprecation warning headers when updating deprecated settings, while properly associating them with the correct correlation id.Previously, the correlation id of the original context wasn't propagated to the cluster state update task.However, using
newRestorableContext(preserveResponseHeaders=true)isn't enough to also - in case - propagate warning headers back to the task's thread context and hence can't be captured by the task executor in MasterService to return the response headers back to the caller.This PR adds a new variant ofnewRestorableContextthat supports propagation of response headers if required.Fixes #108628 (DeprecationHttpIT.testDeprecatedSettingsReturnWarnings)