-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for CPU ranges in desired nodes (#86434)
This commit adds support for CPU ranges in the desired nodes API. This aligns better with environments where administrators/orchestrators can define lower and upper bounds for the amount of CPUs that the desired node would get once deployed. This allows to provide information about the expected CPU and possible allowed overcommit that the desired node will run on. This was the previous expected body for the desired nodes API (we still support it): ``` PUT /_internal/desired_nodes/history/1 { "nodes" : [ { "settings" : { "node.name" : "instance-000187", "node.external_id": "instance-000187", "node.roles" : ["data_hot", "master"], "node.attr.data" : "hot", "node.attr.logical_availability_zone" : "zone-0" }, "processors" : 8, "memory" : "58gb", "storage" : "1700gb", "node_version" : "8.3.0" } ] } ``` Now it's possible to define `processors` or `processors_range` as in: ``` PUT /_internal/desired_nodes/history/1 { "nodes" : [ { "settings" : { "node.name" : "instance-000187", "node.external_id": "instance-000187", "node.roles" : ["data_hot", "master"], "node.attr.data" : "hot", "node.attr.logical_availability_zone" : "zone-0" }, "processors_range" : {"min": 8.0, "max": 16.0}, "memory" : "58gb", "storage" : "1700gb", "node_version" : "8.3.0" } ] } ``` Note that `max` in `processors_range` is optional. This commit also moves from representing CPUs as integers to accept floating point numbers. Note: I disabled the bwc yamlRestTests for versions < 8.3 since we introduced a few "breaking changes" but since this is an internal API it should be fine.
- Loading branch information
Showing
17 changed files
with
1,042 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
pr: 86434 | ||
summary: Add support for CPU ranges in desired nodes | ||
area: Autoscaling | ||
type: enhancement | ||
issues: [] |
This file contains 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 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 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 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 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
117 changes: 117 additions & 0 deletions
117
qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DesiredNodesUpgradeIT.java
This file contains 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,117 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.upgrades; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.cluster.metadata.DesiredNode; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class DesiredNodesUpgradeIT extends AbstractRollingTestCase { | ||
public void testUpgradeDesiredNodes() throws Exception { | ||
// Desired nodes was introduced in 8.1 | ||
if (UPGRADE_FROM_VERSION.before(Version.V_8_1_0)) { | ||
return; | ||
} | ||
|
||
switch (CLUSTER_TYPE) { | ||
case OLD -> { | ||
var response = updateDesiredNodes(1, desiredNodesWithIntegerProcessor()); | ||
var statusCode = response.getStatusLine().getStatusCode(); | ||
assertThat(statusCode, equalTo(200)); | ||
} | ||
case MIXED -> { | ||
final var historyVersion = FIRST_MIXED_ROUND ? 2 : 3; | ||
if (UPGRADE_FROM_VERSION.onOrAfter(DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORT_VERSION)) { | ||
var response = updateDesiredNodes(historyVersion, desiredNodesWithRangeOrFloatProcessors()); | ||
var statusCode = response.getStatusLine().getStatusCode(); | ||
assertThat(statusCode, equalTo(200)); | ||
} else { | ||
// Processor ranges or float processors are forbidden during upgrades: 8.2 -> 8.3 clusters | ||
final var responseException = expectThrows( | ||
ResponseException.class, | ||
() -> updateDesiredNodes(historyVersion, desiredNodesWithRangeOrFloatProcessors()) | ||
); | ||
var statusCode = responseException.getResponse().getStatusLine().getStatusCode(); | ||
assertThat(statusCode, is(equalTo(400))); | ||
} | ||
} | ||
case UPGRADED -> { | ||
var response = updateDesiredNodes(4, desiredNodesWithRangeOrFloatProcessors()); | ||
var statusCode = response.getStatusLine().getStatusCode(); | ||
assertThat(statusCode, equalTo(200)); | ||
} | ||
} | ||
|
||
final var getDesiredNodesRequest = new Request("GET", "/_internal/desired_nodes/_latest"); | ||
Response response = client().performRequest(getDesiredNodesRequest); | ||
assertThat(response.getStatusLine().getStatusCode(), is(equalTo(200))); | ||
} | ||
|
||
private Response updateDesiredNodes(int version, String body) throws Exception { | ||
final var updateDesiredNodesRequest = new Request("PUT", "/_internal/desired_nodes/history/" + version); | ||
updateDesiredNodesRequest.setJsonEntity(body); | ||
return client().performRequest(updateDesiredNodesRequest); | ||
} | ||
|
||
private String desiredNodesWithRangeOrFloatProcessors() { | ||
if (randomBoolean()) { | ||
return """ | ||
{ | ||
"nodes" : [ | ||
{ | ||
"settings" : { | ||
"node.name" : "instance-000187" | ||
}, | ||
"processors_range" : {"min": 9.0, "max": 10.0}, | ||
"memory" : "58gb", | ||
"storage" : "1tb", | ||
"node_version" : "99.1.0" | ||
} | ||
] | ||
}"""; | ||
} else { | ||
return """ | ||
{ | ||
"nodes" : [ | ||
{ | ||
"settings" : { | ||
"node.name" : "instance-000187" | ||
}, | ||
"processors" : 9.5, | ||
"memory" : "58gb", | ||
"storage" : "1tb", | ||
"node_version" : "99.1.0" | ||
} | ||
] | ||
}"""; | ||
} | ||
} | ||
|
||
private String desiredNodesWithIntegerProcessor() { | ||
return """ | ||
{ | ||
"nodes" : [ | ||
{ | ||
"settings" : { | ||
"node.name" : "instance-000187" | ||
}, | ||
"processors" : 9, | ||
"memory" : "58gb", | ||
"storage" : "1tb", | ||
"node_version" : "99.1.0" | ||
} | ||
] | ||
}"""; | ||
} | ||
} |
Oops, something went wrong.