From d1a8e7308fa5707fb8c25df62aeb0359effcf0b1 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Tue, 9 Nov 2021 12:59:52 +0100 Subject: [PATCH] Autoscaling use adjusted total memory The current capacity in use in autoscaling would use the full container memory and not the adjusted total memory. ES sometimes responds with `current_capacity` as `required_capacity` and the `current_capacity` therefore need to use the adjusted capacity instead (since the orchestration should add the memory reservation on top). Relates #78750 --- .../capacity/memory/AutoscalingMemoryInfoService.java | 2 +- .../capacity/memory/AutoscalingMemoryInfoServiceTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoService.java index 3e872d3525a08..13e52b96180c5 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoService.java @@ -181,7 +181,7 @@ private void retainAliveNodes(Set currentNodes) { private void addNodeStats(ImmutableOpenMap.Builder builder, NodeStats nodeStats) { // we might add nodes that already died here, but those will be removed on next cluster state update anyway and is only a small // waste. - builder.put(nodeStats.getNode().getEphemeralId(), nodeStats.getOs().getMem().getTotal().getBytes()); + builder.put(nodeStats.getNode().getEphemeralId(), nodeStats.getOs().getMem().getAdjustedTotal().getBytes()); } public AutoscalingMemoryInfo snapshot() { diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoServiceTests.java index 1c005095854bd..2e8089c2f1986 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/memory/AutoscalingMemoryInfoServiceTests.java @@ -331,7 +331,7 @@ public void assertMatchesResponse(Set nodes, NodesStatsResponse r n -> { assertThat( service.snapshot().get(n), - equalTo(response.getNodesMap().get(n.getId()).getOs().getMem().getTotal().getBytes()) + equalTo(response.getNodesMap().get(n.getId()).getOs().getMem().getAdjustedTotal().getBytes()) ); } ); @@ -347,7 +347,7 @@ private static NodeStats statsForNode(DiscoveryNode node, long memory) { OsStats osStats = new OsStats( randomNonNegativeLong(), new OsStats.Cpu(randomShort(), null), - new OsStats.Mem(memory, memory, randomLongBetween(0, memory)), + new OsStats.Mem(memory, randomLongBetween(0, memory), randomLongBetween(0, memory)), new OsStats.Swap(randomNonNegativeLong(), randomNonNegativeLong()), null );