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

[Backport 2.x] Remove resource usages object from search response headers #16536

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix get index settings API doesn't show `number_of_routing_shards` setting when it was explicitly set ([#16294](https://github.com/opensearch-project/OpenSearch/pull/16294))
- Revert changes to upload remote state manifest using minimum codec version([#16403](https://github.com/opensearch-project/OpenSearch/pull/16403))
- Ensure index templates are not applied to system indices ([#16418](https://github.com/opensearch-project/OpenSearch/pull/16418))
- Remove resource usages object from search response headers ([#16532](https://github.com/opensearch-project/OpenSearch/pull/16532))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResou

@Override
public void onRequestEnd(SearchPhaseContext context, SearchRequestContext searchRequestContext) {
// Refresh the coordinator node level resource usages
taskResourceTrackingService.refreshResourceStats(context.getTask());
// Remove the shard level resource usages from thread context
taskResourceTrackingService.removeTaskResourceUsage();
}

@Override
public void onRequestFailure(SearchPhaseContext context, SearchRequestContext searchRequestContext) {
taskResourceTrackingService.removeTaskResourceUsage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ public void updateResponseHeader(final String key, final String value, final Fun
threadLocal.set(threadLocal.get().putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize, true));
}

/**
* Remove the {@code value} for the specified {@code key}.
*
* @param key the header name
*/
public void removeResponseHeader(final String key) {
threadLocal.get().responseHeaders.remove(key);
}

/**
* Saves the current thread context and wraps command in a Runnable that restores that context before running command. If
* <code>command</code> has already been passed through this method then it is returned unaltered rather than wrapped twice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ public void writeTaskResourceUsage(SearchShardTask task, String nodeId) {
}
}

/**
* Remove the current task level resource usages.
*/
public void removeTaskResourceUsage() {
threadPool.getThreadContext().removeResponseHeader(TASK_RESOURCE_USAGE);
}

/**
* Get the task resource usages from {@link ThreadContext}
*
Expand Down
Loading