Browse Source

Fix NPE in MlMemoryAutoscalingDecider (#116650) (#116669)

* Fix NPE in MlMemoryAutoscalingDecider

* Update docs/changelog/116650.yaml

* Update 116650.yaml

* Update docs/changelog/116650.yaml

* better fix
Jan Kuipers 11 months ago
parent
commit
7936230598

+ 5 - 0
docs/changelog/116650.yaml

@@ -0,0 +1,5 @@
+pr: 116650
+summary: Fix bug in ML autoscaling when some node info is unavailable
+area: Machine Learning
+type: bug
+issues: []

+ 5 - 1
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/autoscaling/MlMemoryAutoscalingCapacity.java

@@ -17,7 +17,11 @@ public record MlMemoryAutoscalingCapacity(ByteSizeValue nodeSize, ByteSizeValue
     }
 
     public static Builder from(AutoscalingCapacity autoscalingCapacity) {
-        return builder(autoscalingCapacity.node().memory(), autoscalingCapacity.total().memory());
+        if (autoscalingCapacity == null) {
+            return builder(null, null);
+        } else {
+            return builder(autoscalingCapacity.node().memory(), autoscalingCapacity.total().memory());
+        }
     }
 
     @Override

+ 1 - 1
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/autoscaling/MlMemoryAutoscalingDecider.java

@@ -809,7 +809,7 @@ class MlMemoryAutoscalingDecider {
         MlMemoryAutoscalingCapacity scaleDownResult,
         MlMemoryAutoscalingCapacity currentCapacity
     ) {
-        if (scaleDownResult == null || currentCapacity == null) {
+        if (scaleDownResult == null || currentCapacity == null || currentCapacity.isUndetermined()) {
             return null;
         }
         MlMemoryAutoscalingCapacity newCapacity = MlMemoryAutoscalingCapacity.builder(