-
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
Add Task Id in thread context for Transport and Rest requests #1882
Add Task Id in thread context for Transport and Rest requests #1882
Conversation
Signed-off-by: Tushar Kharbanda <[email protected]>
Signed-off-by: Tushar Kharbanda <[email protected]>
Signed-off-by: Tushar Kharbanda <[email protected]>
Signed-off-by: Tushar Kharbanda <[email protected]>
Signed-off-by: Tushar Kharbanda <[email protected]>
Signed-off-by: Tushar Kharbanda <[email protected]>
Can one of the admins verify this patch? |
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 on 🍏
/** | ||
* Adds Task Id in the ThreadContext. | ||
* | ||
* Stashes the existing ThreadContext and preserves all the existing ThreadContext's data in the new ThreadContext | ||
* as well. | ||
* | ||
* @param task for which Task Id needs to be added in ThreadContext. | ||
* | ||
* @return StoredContext reference to restore the ThreadContext from which we created a new one. | ||
* Caller can call context.restore() to get the existing ThreadContext back. | ||
*/ | ||
public ThreadContext.StoredContext addTaskIdInThreadContext(@Nullable Task task) { | ||
if (task == null) { | ||
return () -> {}; | ||
} | ||
|
||
ThreadContext threadContext = threadPool.getThreadContext(); | ||
|
||
if (threadContext.getTransient(TASK_ID) != null) { | ||
logger.warn("Task Id already present in the thread context. Overwriting"); | ||
} | ||
|
||
ThreadContext.StoredContext storedContext = threadContext.newStoredContext(true, Collections.singletonList(TASK_ID)); | ||
threadContext.putTransient(TASK_ID, task.getId()); | ||
return storedContext; | ||
} | ||
|
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.
Lets think about placing this logic outside of the purview of the TaskManager
@tushar-kharbanda72 This is a good feature, want to finish it? |
Description
This change is to include Task Id in thread context for all the Rest or Transport requests. This change is required majorly to implement task resource tracking which relies on the fact that Task Id will be available in Thread Context.
Issues Resolved
#1179
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.