Skip to content

Commit 80ca32f

Browse files
authored
remove resource usages object from headers (opensearch-project#16532)
Signed-off-by: Chenyang Ji <cyji@amazon.com>
1 parent 4b284c5 commit 80ca32f

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2626
- 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))
2727
- Revert changes to upload remote state manifest using minimum codec version([#16403](https://github.com/opensearch-project/OpenSearch/pull/16403))
2828
- Ensure index templates are not applied to system indices ([#16418](https://github.com/opensearch-project/OpenSearch/pull/16418))
29+
- Remove resource usages object from search response headers ([#16532](https://github.com/opensearch-project/OpenSearch/pull/16532))
2930

3031
### Security
3132

server/src/main/java/org/opensearch/action/search/SearchTaskRequestOperationsListener.java

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResou
2525

2626
@Override
2727
public void onRequestEnd(SearchPhaseContext context, SearchRequestContext searchRequestContext) {
28+
// Refresh the coordinator node level resource usages
2829
taskResourceTrackingService.refreshResourceStats(context.getTask());
30+
// Remove the shard level resource usages from thread context
31+
taskResourceTrackingService.removeTaskResourceUsage();
32+
}
33+
34+
@Override
35+
public void onRequestFailure(SearchPhaseContext context, SearchRequestContext searchRequestContext) {
36+
taskResourceTrackingService.removeTaskResourceUsage();
2937
}
3038
}

server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java

+9
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,15 @@ public void updateResponseHeader(final String key, final String value, final Fun
547547
threadLocal.set(threadLocal.get().putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize, true));
548548
}
549549

550+
/**
551+
* Remove the {@code value} for the specified {@code key}.
552+
*
553+
* @param key the header name
554+
*/
555+
public void removeResponseHeader(final String key) {
556+
threadLocal.get().responseHeaders.remove(key);
557+
}
558+
550559
/**
551560
* Saves the current thread context and wraps command in a Runnable that restores that context before running command. If
552561
* <code>command</code> has already been passed through this method then it is returned unaltered rather than wrapped twice.

server/src/main/java/org/opensearch/tasks/TaskResourceTrackingService.java

+7
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ public void writeTaskResourceUsage(SearchShardTask task, String nodeId) {
328328
}
329329
}
330330

331+
/**
332+
* Remove the current task level resource usages.
333+
*/
334+
public void removeTaskResourceUsage() {
335+
threadPool.getThreadContext().removeResponseHeader(TASK_RESOURCE_USAGE);
336+
}
337+
331338
/**
332339
* Get the task resource usages from {@link ThreadContext}
333340
*

0 commit comments

Comments
 (0)