Skip to content
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

Add support for CPU ranges in desired nodes #86434

Merged
merged 27 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c7eb3e2
Add support for CPU ranges in desired nodes
fcofdez May 4, 2022
7384292
Fix mistake
fcofdez May 4, 2022
4a6d0b9
Change backwards compatible policy
fcofdez May 4, 2022
39f3603
Update desired nodes docs
fcofdez May 5, 2022
b2b4f26
Add a few tests
fcofdez May 5, 2022
7751acb
Update docs/changelog/86434.yaml
fcofdez May 5, 2022
6cd28c2
Reviews
fcofdez May 9, 2022
ab44132
Support processor ranges and processors as separate fields
fcofdez May 10, 2022
cb24fdb
Merge remote-tracking branch 'origin/master' into desired-nodes-proce…
fcofdez May 10, 2022
33964ec
Merge branch 'desired-nodes-processors' of github.com:fcofdez/elastic…
fcofdez May 10, 2022
74d4ef8
Max is not rendered
fcofdez May 10, 2022
32934e4
Take into account newer versions in upgrade test
fcofdez May 10, 2022
5bb3f51
Spotless
fcofdez May 10, 2022
9e1990f
Merge remote-tracking branch 'origin/master' into desired-nodes-proce…
fcofdez May 10, 2022
3cc813e
Clarification
fcofdez May 11, 2022
c922cc1
Merge remote-tracking branch 'origin/master' into desired-nodes-proce…
fcofdez May 11, 2022
493e241
Remove unused contains
fcofdez May 11, 2022
4ac2461
Upgrade test
fcofdez May 11, 2022
40190a4
Merge remote-tracking branch 'origin/master' into desired-nodes-proce…
fcofdez May 11, 2022
f56b63e
Change size
fcofdez May 11, 2022
2dfa5e7
Merge remote-tracking branch 'origin/master' into desired-nodes-proce…
fcofdez May 11, 2022
02dceff
Review comments
fcofdez May 18, 2022
1142f69
Merge remote-tracking branch 'origin/master' into desired-nodes-proce…
fcofdez May 18, 2022
7016271
Docs
fcofdez May 18, 2022
68c97cf
Fix docs
fcofdez May 19, 2022
9906fe0
Merge remote-tracking branch 'origin/master' into desired-nodes-proce…
fcofdez May 19, 2022
ea58538
Update server/src/main/java/org/elasticsearch/cluster/metadata/Desire…
fcofdez May 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/86434.yaml
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: []
4 changes: 2 additions & 2 deletions docs/reference/cluster/delete-desired-nodes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ PUT /_internal/desired_nodes/history/1
"node.attr.data" : "hot",
"node.attr.logical_availability_zone" : "zone-0"
},
"processors" : 8,
"processors" : 8.0,
"memory" : "58gb",
"storage" : "1700gb",
"storage" : "2tb",
"node_version" : "{version}"
}
]
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/cluster/get-desired-nodes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ PUT /_internal/desired_nodes/my_history/1
"node.attr.data" : "hot",
"node.attr.logical_availability_zone" : "zone-0"
},
"processors" : 8,
"processors" : 8.0,
"memory" : "59gb",
"storage" : "1700gb",
"storage" : "2tb",
"node_version" : "{version}"
}
]
Expand Down
36 changes: 32 additions & 4 deletions docs/reference/cluster/update-desired-nodes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ PUT /_internal/desired_nodes/<history_id>/<version>
"node.attr.data" : "hot",
"node.attr.logical_availability_zone" : "zone-0"
},
"processors" : 8,
"processors" : 8.0,
"memory" : "58gb",
"storage" : "1700gb",
"storage" : "2tb",
"node_version" : "{version}"
}
]
Expand Down Expand Up @@ -77,9 +77,9 @@ PUT /_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/100
"node.attr.data" : "hot",
"node.attr.logical_availability_zone" : "zone-0"
},
"processors" : 8,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we would not want to keep the processors: 8 case in the documentation (perhaps using 8.0 instead). I think the best world is if we have just the one number rather than multiple and having that case be simpler for those orchestrations that can supply it seems desirable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us also mention that processors can be specified as a range, that makes it easier to see which releases the range syntax is supported in (and documents it).

"processors" : 8.0,
"memory" : "58gb",
"storage" : "1700gb",
"storage" : "2tb",
"node_version" : "{version}"
}
]
Expand All @@ -96,6 +96,34 @@ The API returns the following result:
}
--------------------------------------------------

Additionally, it is possible to specify a processors range.
This is helpful in environments where Elasticsearch nodes can
be deployed in hosts where the number of processors that the
Elasticsearch process can use is guaranteed to be at least the
lower range and up to the upper range. This is a common scenario
in Linux deployments where cgroups is used.
[source,console]
--------------------------------------------------
PUT /_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/101
{
"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": 10.0},
"memory" : "58gb",
"storage" : "2tb",
"node_version" : "{version}"
}
]
}
--------------------------------------------------

//////////////////////////

[source,console]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public enum ValueType {
OBJECT_ARRAY_OR_NULL(START_OBJECT, START_ARRAY, VALUE_NULL),
OBJECT_OR_BOOLEAN(START_OBJECT, VALUE_BOOLEAN),
OBJECT_OR_STRING(START_OBJECT, VALUE_STRING),
OBJECT_OR_LONG(START_OBJECT, VALUE_NUMBER),
OBJECT_OR_NUMBER(START_OBJECT, VALUE_NUMBER),
OBJECT_ARRAY_BOOLEAN_OR_STRING(START_OBJECT, START_ARRAY, VALUE_BOOLEAN, VALUE_STRING),
OBJECT_ARRAY_OR_STRING(START_OBJECT, START_ARRAY, VALUE_STRING),
OBJECT_ARRAY_STRING_OR_NUMBER(START_OBJECT, START_ARRAY, VALUE_STRING, VALUE_NUMBER),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Fields {
// For BWC with nodes pre 7.0
return p.longValue();
}
}, new ParseField("total"), ValueType.OBJECT_OR_LONG);
}, new ParseField("total"), ValueType.OBJECT_OR_NUMBER);
HITS_PARSER.declareObjectArray(constructorArg(), HIT_PARSER, new ParseField("hits"));
}

Expand Down
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"
}
]
}""";
}
}
Loading