-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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 node "roles" to allocation explain response #98550
Changes from 10 commits
7f79eb6
9b14bdd
9a5c6be
9f05f3b
6a274a3
7930fef
d374126
cd0e2aa
5320723
e92f20c
e7d2abe
63bd2d4
4eca1c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 98550 | ||
summary: Report a node's "roles" setting in the /_cluster/allocation/explain response | ||
area: Allocation | ||
type: enhancement | ||
issues: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,3 +92,21 @@ | |
- is_true: can_rebalance_cluster | ||
- is_true: can_rebalance_to_other_node | ||
- is_true: rebalance_explanation | ||
|
||
--- | ||
"Cluster allocation explanation response includes node's roles": | ||
- skip: | ||
version: " - 8.10.99" | ||
reason: The roles field was introduced in 8.11.0 | ||
|
||
- do: | ||
indices.create: | ||
index: test | ||
|
||
- match: { acknowledged: true } | ||
|
||
- do: | ||
cluster.allocation_explain: | ||
body: { "index": "test", "shard": 0, "primary": true } | ||
|
||
- is_true: current_node.roles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Roles are added to other places as well:
I believe the first 2 are not present since this explain is executed against allocated shard that could stay on the current node. I do not think they require additional test case and could be covered by serialization test, see https://github.com/elastic/elasticsearch/pull/98550/files#r1299861004 I wonder about the last one. I think it could be covered with additional: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The YAML tests (sometimes) run in a one-node cluster so we can't assert anything about the other changed locations here. I think we could check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extended |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import org.elasticsearch.cluster.health.ClusterHealthStatus; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodeRole; | ||
import org.elasticsearch.cluster.routing.ShardRoutingState; | ||
import org.elasticsearch.cluster.routing.UnassignedInfo; | ||
import org.elasticsearch.cluster.routing.UnassignedInfo.AllocationStatus; | ||
|
@@ -1150,6 +1151,42 @@ public void testCannotAllocateStaleReplicaExplanation() throws Exception { | |
} | ||
} | ||
|
||
public void testExplainRolesOutput() throws Exception { | ||
logger.info("--> starting 1 node with 'roles' setting specified"); | ||
Settings roleSettings = Settings.builder().putList("node.roles", List.of("master", "data_hot", "ingest")).build(); | ||
internalCluster().startNode(Settings.builder().put(roleSettings).build()); | ||
prepareIndex(1, 0); | ||
|
||
boolean includeYesDecisions = randomBoolean(); | ||
boolean includeDiskInfo = randomBoolean(); | ||
ClusterAllocationExplanation explanation = runExplain(true, includeYesDecisions, includeDiskInfo); | ||
|
||
assertEquals( | ||
Set.of(DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.INGEST_ROLE, DiscoveryNodeRole.MASTER_ROLE), | ||
explanation.getCurrentNode().getRoles() | ||
); | ||
|
||
try (XContentParser parser = getParser(explanation)) { | ||
// Fast-forward to the "current_node" object, which contains "roles". | ||
do { | ||
parser.nextToken(); | ||
assertNotEquals(Token.END_OBJECT, parser.currentToken()); | ||
// The START_OBJECT has a null currentName(), so check for that before de-referencing. | ||
} while (parser.currentName() == null || (parser.currentName().equals("current_node")) == false); | ||
assertEquals(Token.START_OBJECT, parser.nextToken()); | ||
|
||
// Fast-forward to "roles" field in the "current_node" object. | ||
do { | ||
parser.nextToken(); | ||
assertNotEquals(Token.END_OBJECT, parser.currentToken()); | ||
} while ((parser.currentName().equals("roles")) == false); | ||
|
||
// Check that the "roles" reported are those explicitly set via the node Settings. | ||
// Note: list() implicitly consumes the parser START_ARRAY and END_ARRAY tokens. | ||
assertEquals(List.of("data_hot", "ingest", "master"), parser.list()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, I am surprised we have to do this in this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not currently familiar with how AbstractXContentSerializingTestCase works, so can't really weigh in on this without some context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think there's scope for better testing in this area indeed. Not sure |
||
} | ||
|
||
private void verifyClusterInfo(ClusterInfo clusterInfo, boolean includeDiskInfo, int numNodes) { | ||
if (includeDiskInfo) { | ||
assertThat(clusterInfo.getNodeMostAvailableDiskUsages().size(), greaterThanOrEqualTo(0)); | ||
|
@@ -1309,8 +1346,11 @@ private void verifyShardInfo(XContentParser parser, boolean primary, boolean inc | |
parser.currentName().equals("id") | ||
|| parser.currentName().equals("name") | ||
|| parser.currentName().equals("transport_address") | ||
|| parser.currentName().equals("roles") | ||
|| parser.currentName().equals("weight_ranking") | ||
); | ||
} else if (token == Token.START_ARRAY || token == Token.END_ARRAY) { | ||
assertEquals("roles", parser.currentName()); | ||
} else { | ||
assertTrue(token.isValue()); | ||
assertNotNull(parser.text()); | ||
|
@@ -1436,6 +1476,10 @@ private String verifyNodeDecisionPrologue(XContentParser parser) throws IOExcept | |
parser.nextToken(); | ||
assertNotNull(parser.text()); | ||
parser.nextToken(); | ||
assertEquals("roles", parser.currentName()); | ||
parser.nextToken(); | ||
assertNotEquals(0, parser.list().size()); | ||
parser.nextToken(); | ||
assertEquals("node_decision", parser.currentName()); | ||
parser.nextToken(); | ||
return nodeName; | ||
|
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.
nit: (not picked up by the test framework because this example is skipped)
You could also reasonably list fewer roles here, maybe just
data_content, data_hot
, I don't think it helps the docs to have them all.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.
Done