diff --git a/server/src/main/java/org/opensearch/wlm/ResourceType.java b/server/src/main/java/org/opensearch/wlm/ResourceType.java index 856005f866bc7..b8e9ba8d02429 100644 --- a/server/src/main/java/org/opensearch/wlm/ResourceType.java +++ b/server/src/main/java/org/opensearch/wlm/ResourceType.java @@ -45,7 +45,12 @@ protected double getNormalisedThreshold(QueryGroup queryGroup) { private final QueryGroupUsageHelper queryGroupUsageHelper; private static List sortedValues = List.of(CPU, MEMORY); - ResourceType(String name, boolean statsEnabled, ResourceUsageCalculator resourceUsageCalculator, QueryGroupUsageHelper queryGroupUsageHelper) { + ResourceType( + String name, + boolean statsEnabled, + ResourceUsageCalculator resourceUsageCalculator, + QueryGroupUsageHelper queryGroupUsageHelper + ) { this.name = name; this.statsEnabled = statsEnabled; this.resourceUsageCalculator = resourceUsageCalculator; diff --git a/server/src/main/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategy.java b/server/src/main/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategy.java index ec59b1645dd62..c32272f1b8492 100644 --- a/server/src/main/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategy.java +++ b/server/src/main/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategy.java @@ -43,7 +43,9 @@ public HighestResourceConsumingTaskFirstSelectionStrategy(Supplier nanoTim * @return The comparator */ private Comparator sortingCondition(ResourceType resourceType) { - return Comparator.comparingDouble(task -> resourceType.getResourceUsageCalculator().calculateTaskResourceUsage(task, nanoTimeSupplier)); + return Comparator.comparingDouble( + task -> resourceType.getResourceUsageCalculator().calculateTaskResourceUsage(task, nanoTimeSupplier) + ); } /** diff --git a/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java b/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java index 5d7ee90ac562b..c7d9ff00929f9 100644 --- a/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java +++ b/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java @@ -52,7 +52,8 @@ public Map constructQueryGroupLevelUsa // Compute the QueryGroup resource usage final Map resourceUsage = new HashMap<>(); for (ResourceType resourceType : TRACKED_RESOURCES) { - double usage = resourceType.getResourceUsageCalculator().calculateResourceUsage(queryGroupEntry.getValue(), nanoTimeSupplier); + double usage = resourceType.getResourceUsageCalculator() + .calculateResourceUsage(queryGroupEntry.getValue(), nanoTimeSupplier); resourceUsage.put(resourceType, usage); } diff --git a/server/src/test/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategyTests.java b/server/src/test/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategyTests.java index 135613e2ef65a..1582a45897db3 100644 --- a/server/src/test/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategyTests.java +++ b/server/src/test/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategyTests.java @@ -45,10 +45,9 @@ public void testSelectTasksToCancelSelectsTasksMeetingThreshold_ifReduceByIsGrea assertFalse(selectedTasks.isEmpty()); boolean sortedInDescendingResourceUsage = IntStream.range(0, selectedTasks.size() - 1) .noneMatch( - index -> ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage(selectedTasks.get(index), null) < ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage( - selectedTasks.get(index + 1), - null - ) + index -> ResourceType.MEMORY.getResourceUsageCalculator() + .calculateTaskResourceUsage(selectedTasks.get(index), null) < ResourceType.MEMORY.getResourceUsageCalculator() + .calculateTaskResourceUsage(selectedTasks.get(index + 1), null) ); assertTrue(sortedInDescendingResourceUsage); assertTrue(tasksUsageMeetsThreshold(selectedTasks, reduceBy)); diff --git a/server/src/test/java/org/opensearch/wlm/tracker/ResourceUsageCalculatorTests.java b/server/src/test/java/org/opensearch/wlm/tracker/ResourceUsageCalculatorTests.java index 5235987e5d2ac..ebc9f366d369a 100644 --- a/server/src/test/java/org/opensearch/wlm/tracker/ResourceUsageCalculatorTests.java +++ b/server/src/test/java/org/opensearch/wlm/tracker/ResourceUsageCalculatorTests.java @@ -50,11 +50,16 @@ public void testQueryGroupMemoryUsage() { TestClock clock = new TestClock(); QueryGroupTask mockTask = createMockTaskWithResourceStats(QueryGroupTask.class, 100, 200, 0, 123); - double actualMemoryUsage = ResourceType.MEMORY.getResourceUsageCalculator().calculateResourceUsage(List.of(mockTask), clock::getTime); + double actualMemoryUsage = ResourceType.MEMORY.getResourceUsageCalculator() + .calculateResourceUsage(List.of(mockTask), clock::getTime); double expectedMemoryUsage = 200.0 / HEAP_SIZE_BYTES; assertEquals(expectedMemoryUsage, actualMemoryUsage, MIN_VALUE); - assertEquals(200.0 / HEAP_SIZE_BYTES, ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage(mockTask, clock::getTime), MIN_VALUE); + assertEquals( + 200.0 / HEAP_SIZE_BYTES, + ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage(mockTask, clock::getTime), + MIN_VALUE + ); } public static T createMockTaskWithResourceStats(