Skip to content

Commit 5948b71

Browse files
authored
Fix NPE in AdaptiveAllocationsScalarService for null nodes (serverless) (#124318)
1 parent 9e7a90f commit 5948b71

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/adaptiveallocations/AdaptiveAllocationsScalerService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.cluster.ClusterChangedEvent;
1616
import org.elasticsearch.cluster.ClusterState;
1717
import org.elasticsearch.cluster.ClusterStateListener;
18+
import org.elasticsearch.cluster.node.DiscoveryNode;
1819
import org.elasticsearch.cluster.service.ClusterService;
1920
import org.elasticsearch.common.Strings;
2021
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
@@ -383,7 +384,8 @@ private void processDeploymentStats(GetDeploymentStatsAction.Response statsRespo
383384
key -> new HashMap<>()
384385
);
385386
for (AssignmentStats.NodeStats nodeStats : assignmentStats.getNodeStats()) {
386-
String nodeId = nodeStats.getNode().getId();
387+
DiscoveryNode node = nodeStats.getNode();
388+
String nodeId = node == null ? null : node.getId();
387389
Stats lastStats = deploymentStats.get(nodeId);
388390
Stats nextStats = new Stats(
389391
nodeStats.getInferenceCount().orElse(0L),

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/adaptiveallocations/AdaptiveAllocationsScalerServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private GetDeploymentStatsAction.Response getDeploymentStatsResponse(int numAllo
130130
Instant.now(),
131131
List.of(
132132
AssignmentStats.NodeStats.forStartedState(
133-
DiscoveryNodeUtils.create("node_1"),
133+
randomBoolean() ? DiscoveryNodeUtils.create("node_1") : null,
134134
inferenceCount,
135135
latency,
136136
latency,

0 commit comments

Comments
 (0)