Skip to content

Commit a312404

Browse files
authored
Fix scale up for model allocations (elastic#115189) (elastic#115225)
1 parent 5cc18bc commit a312404

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/autoscaling/MlAutoscalingContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public boolean isEmpty() {
177177
return anomalyDetectionTasks.isEmpty()
178178
&& snapshotUpgradeTasks.isEmpty()
179179
&& dataframeAnalyticsTasks.isEmpty()
180-
&& modelAssignments.values().stream().allMatch(assignment -> assignment.totalTargetAllocations() == 0);
180+
&& modelAssignments.values().stream().allMatch(assignment -> assignment.getTaskParams().getNumberOfAllocations() == 0);
181181
}
182182

183183
public List<String> findPartiallyAllocatedModels() {

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/autoscaling/MlAutoscalingDeciderServiceTests.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static org.elasticsearch.xpack.ml.utils.NativeMemoryCalculator.STATIC_JVM_UPPER_THRESHOLD;
5555
import static org.hamcrest.Matchers.containsString;
5656
import static org.hamcrest.Matchers.equalTo;
57+
import static org.hamcrest.Matchers.greaterThan;
5758
import static org.hamcrest.Matchers.is;
5859
import static org.hamcrest.Matchers.nullValue;
5960
import static org.mockito.ArgumentMatchers.any;
@@ -331,6 +332,53 @@ public void testScale_GivenModelWithZeroAllocations() {
331332
assertThat(result.requiredCapacity().node().memory().getBytes(), equalTo(0L));
332333
}
333334

335+
public void testScale_GivenTrainedModelAllocationAndNoMlNode() {
336+
MlAutoscalingDeciderService service = buildService();
337+
service.onMaster();
338+
339+
ClusterState clusterState = new ClusterState.Builder(new ClusterName("cluster")).metadata(
340+
Metadata.builder()
341+
.putCustom(
342+
TrainedModelAssignmentMetadata.NAME,
343+
new TrainedModelAssignmentMetadata(
344+
Map.of(
345+
"model",
346+
TrainedModelAssignment.Builder.empty(
347+
new StartTrainedModelDeploymentAction.TaskParams(
348+
"model",
349+
"model-deployment",
350+
400,
351+
1,
352+
2,
353+
100,
354+
null,
355+
Priority.NORMAL,
356+
0L,
357+
0L
358+
),
359+
new AdaptiveAllocationsSettings(true, 0, 4)
360+
).setAssignmentState(AssignmentState.STARTING).build()
361+
)
362+
)
363+
)
364+
.build()
365+
).build();
366+
367+
AutoscalingDeciderResult result = service.scale(
368+
Settings.EMPTY,
369+
new DeciderContext(
370+
clusterState,
371+
new AutoscalingCapacity(AutoscalingCapacity.AutoscalingResources.ZERO, AutoscalingCapacity.AutoscalingResources.ZERO)
372+
)
373+
);
374+
375+
assertThat(result.reason().summary(), containsString("requesting scale up"));
376+
assertThat(result.requiredCapacity().total().memory().getBytes(), greaterThan(TEST_JOB_SIZE));
377+
assertThat(result.requiredCapacity().total().processors().count(), equalTo(2.0));
378+
assertThat(result.requiredCapacity().node().memory().getBytes(), greaterThan(TEST_JOB_SIZE));
379+
assertThat(result.requiredCapacity().node().processors().count(), equalTo(2.0));
380+
}
381+
334382
private DiscoveryNode buildNode(String id, ByteSizeValue machineMemory, int allocatedProcessors) {
335383
return DiscoveryNodeUtils.create(
336384
id,

0 commit comments

Comments
 (0)