forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bharathwaj G <[email protected]>
- Loading branch information
1 parent
327b1dc
commit e920b1f
Showing
5 changed files
with
253 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
server/src/main/java/org/opensearch/tasks/ResourceUsageStatsTCPropagator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.tasks; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.opensearch.common.util.concurrent.ThreadContextStatePropagator; | ||
|
||
import static org.opensearch.tasks.TaskResourceTrackingService.TASK_ID; | ||
|
||
|
||
public class ResourceUsageStatsTCPropagator implements ThreadContextStatePropagator { | ||
public static final String NODE_RESOURCE_STATS = "PERF_STATS"; | ||
@Override | ||
public Map<String, Object> transients(Map<String, Object> source) { | ||
final Map<String, Object> transients = new HashMap<>(); | ||
for(Map.Entry<String, Object> entry : source.entrySet()) { | ||
if(entry.getKey().startsWith(NODE_RESOURCE_STATS)) { | ||
// key starts with prefix | ||
transients.put(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
return transients; | ||
} | ||
|
||
@Override | ||
public Map<String, String> headers(Map<String, Object> source) { | ||
final Map<String, String> headers = new HashMap<>(); | ||
for(Map.Entry<String, Object> entry : source.entrySet()) { | ||
if(entry.getKey().startsWith(NODE_RESOURCE_STATS)) { | ||
// key starts with prefix | ||
headers.put(entry.getKey(), entry.getValue().toString()); | ||
} | ||
} | ||
return headers; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
server/src/main/java/org/opensearch/transport/ResourceUsageStatsReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.transport; | ||
|
||
public class ResourceUsageStatsReference { | ||
private String resourceUsageStats; | ||
|
||
public ResourceUsageStatsReference(String stats) { | ||
this.resourceUsageStats = stats; | ||
} | ||
|
||
public String getResourceUsageStats() { | ||
return resourceUsageStats; | ||
} | ||
|
||
public void setResourceUsageStats(String stats) { | ||
this.resourceUsageStats = new String(stats); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.resourceUsageStats; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.