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

Add Task Id in thread context for Transport and Rest requests #1882

Conversation

tushar-kharbanda72
Copy link
Contributor

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

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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.

Tushar Kharbanda added 6 commits January 11, 2022 20:41
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]>
@opensearch-ci-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure b3bea74
Log 1853

Reports 1853

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

LGTM on 🍏

Comment on lines +454 to +480
/**
* 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;
}

Copy link
Collaborator

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

@dblock
Copy link
Member

dblock commented Mar 3, 2022

@tushar-kharbanda72 This is a good feature, want to finish it?

@tushar-kharbanda72
Copy link
Contributor Author

@dblock This one got included in this #2639

Closing this PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants