-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[7.x] [ML] adding ml autoscaling integration test (#65638) #65775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
...ode-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/AutoscalingIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.ml.integration; | ||
|
||
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.xpack.autoscaling.Autoscaling; | ||
import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingCapacityAction; | ||
import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; | ||
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult; | ||
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResults; | ||
import org.elasticsearch.xpack.core.ml.job.config.AnalysisConfig; | ||
import org.elasticsearch.xpack.core.ml.job.config.AnalysisLimits; | ||
import org.elasticsearch.xpack.core.ml.job.config.DataDescription; | ||
import org.elasticsearch.xpack.core.ml.job.config.Detector; | ||
import org.elasticsearch.xpack.core.ml.job.config.Job; | ||
import org.elasticsearch.xpack.ml.MachineLearning; | ||
import org.elasticsearch.xpack.ml.autoscaling.MlAutoscalingDeciderService; | ||
import org.elasticsearch.xpack.ml.autoscaling.NativeMemoryCapacity; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasKey; | ||
|
||
public class AutoscalingIT extends MlNativeAutodetectIntegTestCase { | ||
|
||
private static final long BASIC_REQUIREMENT_MB = 10; | ||
private static final long NATIVE_PROCESS_OVERHEAD_MB = 30; | ||
private static final long BASELINE_OVERHEAD_MB = BASIC_REQUIREMENT_MB + NATIVE_PROCESS_OVERHEAD_MB; | ||
|
||
// This test assumes that xpack.ml.max_machine_memory_percent is 30 | ||
// and that xpack.ml.use_auto_machine_memory_percent is false | ||
public void testMLAutoscalingCapacity() { | ||
SortedMap<String, Settings> deciders = new TreeMap<>(); | ||
deciders.put(MlAutoscalingDeciderService.NAME, | ||
Settings.builder().put(MlAutoscalingDeciderService.DOWN_SCALE_DELAY.getKey(), TimeValue.ZERO).build()); | ||
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request( | ||
"ml_test", | ||
new TreeSet<>(), | ||
deciders | ||
); | ||
assertAcked(client().execute(PutAutoscalingPolicyAction.INSTANCE, request).actionGet()); | ||
|
||
assertMlCapacity( | ||
client().execute( | ||
GetAutoscalingCapacityAction.INSTANCE, | ||
new GetAutoscalingCapacityAction.Request() | ||
).actionGet(), | ||
"Requesting scale down as tier and/or node size could be smaller", | ||
0L, | ||
0L); | ||
|
||
putJob("job1", 100); | ||
putJob("job2", 200); | ||
openJob("job1"); | ||
openJob("job2"); | ||
long expectedTierBytes = (long)Math.ceil( | ||
ByteSizeValue.ofMb(100 + BASELINE_OVERHEAD_MB + 200 + BASELINE_OVERHEAD_MB).getBytes() * 100 / 30.0 | ||
); | ||
long expectedNodeBytes = (long)Math.ceil(ByteSizeValue.ofMb(200 + BASELINE_OVERHEAD_MB).getBytes() * 100 / 30.0); | ||
|
||
assertMlCapacity( | ||
client().execute( | ||
GetAutoscalingCapacityAction.INSTANCE, | ||
new GetAutoscalingCapacityAction.Request() | ||
).actionGet(), | ||
"Requesting scale down as tier and/or node size could be smaller", | ||
expectedTierBytes, | ||
expectedNodeBytes); | ||
|
||
putJob("bigjob1", 60_000); | ||
putJob("bigjob2", 50_000); | ||
openJob("bigjob1"); | ||
openJob("bigjob2"); | ||
List<DiscoveryNode> mlNodes = admin() | ||
.cluster() | ||
.prepareNodesInfo() | ||
.all() | ||
.get() | ||
.getNodes() | ||
.stream() | ||
.map(NodeInfo::getNode) | ||
.filter(MachineLearning::isMlNode) | ||
.collect(Collectors.toList()); | ||
NativeMemoryCapacity currentScale = MlAutoscalingDeciderService.currentScale(mlNodes, 30, false); | ||
expectedTierBytes = (long)Math.ceil( | ||
(ByteSizeValue.ofMb(50_000 + BASIC_REQUIREMENT_MB + 60_000 + BASIC_REQUIREMENT_MB).getBytes() | ||
+ currentScale.getTier() | ||
) * 100 / 30.0 | ||
); | ||
expectedNodeBytes = (long)Math.ceil(ByteSizeValue.ofMb(60_000 + BASELINE_OVERHEAD_MB).getBytes() * 100 / 30.0); | ||
|
||
|
||
assertMlCapacity( | ||
client().execute( | ||
GetAutoscalingCapacityAction.INSTANCE, | ||
new GetAutoscalingCapacityAction.Request() | ||
).actionGet(), | ||
"requesting scale up as number of jobs in queues exceeded configured limit", | ||
expectedTierBytes, | ||
expectedNodeBytes); | ||
|
||
expectedTierBytes = (long)Math.ceil( | ||
ByteSizeValue.ofMb(100 + BASELINE_OVERHEAD_MB + 200 + BASELINE_OVERHEAD_MB).getBytes() * 100 / 30.0 | ||
); | ||
expectedNodeBytes = (long)Math.ceil(ByteSizeValue.ofMb(200 + BASELINE_OVERHEAD_MB).getBytes() * 100 / 30.0); | ||
closeJob("bigjob1"); | ||
closeJob("bigjob2"); | ||
|
||
assertMlCapacity( | ||
client().execute( | ||
GetAutoscalingCapacityAction.INSTANCE, | ||
new GetAutoscalingCapacityAction.Request() | ||
).actionGet(), | ||
"Requesting scale down as tier and/or node size could be smaller", | ||
expectedTierBytes, | ||
expectedNodeBytes); | ||
closeJob("job1"); | ||
closeJob("job2"); | ||
|
||
assertMlCapacity( | ||
client().execute( | ||
GetAutoscalingCapacityAction.INSTANCE, | ||
new GetAutoscalingCapacityAction.Request() | ||
).actionGet(), | ||
"Requesting scale down as tier and/or node size could be smaller", | ||
0L, | ||
0L); | ||
} | ||
|
||
private void assertMlCapacity(GetAutoscalingCapacityAction.Response capacity, String reason, long tierBytes, long nodeBytes) { | ||
assertThat(capacity.getResults(), hasKey("ml_test")); | ||
AutoscalingDeciderResults autoscalingDeciderResults = capacity.getResults().get("ml_test"); | ||
assertThat(autoscalingDeciderResults.results(), hasKey("ml")); | ||
|
||
AutoscalingDeciderResult autoscalingDeciderResult = autoscalingDeciderResults.results().get("ml"); | ||
assertThat(autoscalingDeciderResult.reason().summary(), containsString(reason)); | ||
assertThat(autoscalingDeciderResult.requiredCapacity().tier().memory().getBytes(), equalTo(tierBytes)); | ||
assertThat(autoscalingDeciderResult.requiredCapacity().node().memory().getBytes(), equalTo(nodeBytes)); | ||
} | ||
|
||
private void putJob(String jobId, long limitMb) { | ||
Job.Builder job = | ||
new Job.Builder(jobId) | ||
.setAllowLazyOpen(true) | ||
.setAnalysisLimits(new AnalysisLimits(limitMb, null)) | ||
.setAnalysisConfig( | ||
new AnalysisConfig.Builder((List<Detector>) null) | ||
.setBucketSpan(TimeValue.timeValueHours(1)) | ||
.setDetectors( | ||
Collections.singletonList( | ||
new Detector.Builder("count", null) | ||
.setPartitionFieldName("user") | ||
.build()))) | ||
.setDataDescription( | ||
new DataDescription.Builder() | ||
.setTimeFormat("epoch")); | ||
|
||
registerJob(job); | ||
putJob(job); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benwtrent do you know why this did not work? It is preventing me from getting #66082 merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henningandersen when I tried to supply
"ml"
it complained saying it was not really a valid node role. Now, this may have been due to the ML plugin not being loaded correctly? The easiest way to check is to simply putml
in there in 7.x and ry to run the test. I will double checkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I did that and get the validation error. I only wanted to be sure I was not chasing something you already investigated deeply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henningandersen
I THINK the node role format has changed in master vs 7.x. Passing
ml
as the only role works fine in master.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhh, the validation runs in the transport client and this causes the issue, since the client does not know about the ml plugin. Using a core role like
master
passes that validation (but fails the test with my PR due to validation).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me open a PR to move the validation out of the request in 7.x.