Skip to content

Commit

Permalink
remove untagged tasks from WLM tracking
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <[email protected]>
  • Loading branch information
kaushalmahi12 committed Jan 17, 2025
1 parent 36d43ef commit 0c37980
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/src/main/java/org/opensearch/wlm/QueryGroupTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class QueryGroupTask extends CancellableTask {
public static final Supplier<String> DEFAULT_QUERY_GROUP_ID_SUPPLIER = () -> "DEFAULT_QUERY_GROUP";
private final LongSupplier nanoTimeSupplier;
private String queryGroupId;
private boolean isEligibleForTracking = false;

public QueryGroupTask(long id, String type, String action, String description, TaskId parentTaskId, Map<String, String> headers) {
this(id, type, action, description, parentTaskId, headers, NO_TIMEOUT, System::nanoTime);
Expand Down Expand Up @@ -81,6 +82,7 @@ public final String getQueryGroupId() {
* @param threadContext current threadContext
*/
public final void setQueryGroupId(final ThreadContext threadContext) {
isEligibleForTracking = true;
if (threadContext != null && threadContext.getHeader(QUERY_GROUP_ID_HEADER) != null) {
this.queryGroupId = threadContext.getHeader(QUERY_GROUP_ID_HEADER);
} else {
Expand All @@ -92,6 +94,10 @@ public long getElapsedTime() {
return nanoTimeSupplier.getAsLong() - getStartTimeNanos();
}

public boolean isEligibleForTracking() {
return isEligibleForTracking;
}

@Override
public boolean shouldCancelChildrenOnCancellation() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private Map<String, List<QueryGroupTask>> getTasksGroupedByQueryGroup() {
.stream()
.filter(QueryGroupTask.class::isInstance)
.map(QueryGroupTask.class::cast)
.filter(QueryGroupTask::isEligibleForTracking)
.collect(Collectors.groupingBy(QueryGroupTask::getQueryGroupId, Collectors.mapping(task -> task, Collectors.toList())));
}
}

0 comments on commit 0c37980

Please sign in to comment.