Skip to content

Commit

Permalink
add total cancellations
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <[email protected]>
  • Loading branch information
kaushalmahi12 committed Aug 26, 2024
1 parent 7fada74 commit ce813f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/src/main/java/org/opensearch/wlm/stats/QueryGroupState.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class QueryGroupState {
*/
private final AtomicLong failures = new AtomicLong();

/**
* This will track total number of cancellations in the query group due to all resource type breaches
*/
private final AtomicLong totalCancellations = new AtomicLong();

/**
* This is used to store the resource type state both for CPU and MEMORY
*/
Expand Down Expand Up @@ -68,6 +73,10 @@ public long getFailures() {
return failures.get();
}

public long getTotalCancellations() {
return totalCancellations.get();
}

/**
* getter for query group resource state
* @return the query group resource state
Expand Down Expand Up @@ -97,6 +106,13 @@ public void incrementFailures() {
failures.incrementAndGet();
}

/**
* this is a call back to increment total cancellations for a query group
*/
public void incrementTotalCancellations() {
totalCancellations.incrementAndGet();
}

/**
* This class holds the resource level stats for the query group
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public void testRandomQueryGroupsStateUpdates() {
} else {
updaterThreads.add(new Thread(() -> queryGroupState.getResourceState().get(ResourceType.MEMORY).incrementCancellations()));
}

if (i%5 == 3 || i%5 == 4) {
updaterThreads.add(new Thread(() -> queryGroupState.incrementTotalCancellations()));
}
}

// trigger the updates
Expand All @@ -49,6 +53,7 @@ public void testRandomQueryGroupsStateUpdates() {
assertEquals(5, queryGroupState.getCompletions());
assertEquals(5, queryGroupState.getRejections());
assertEquals(5, queryGroupState.getFailures());
assertEquals(10, queryGroupState.getTotalCancellations());
assertEquals(5, queryGroupState.getResourceState().get(ResourceType.CPU).getCancellations());
assertEquals(5, queryGroupState.getResourceState().get(ResourceType.MEMORY).getCancellations());
}
Expand Down

0 comments on commit ce813f1

Please sign in to comment.