From a1ca7b1862f0bf8991387ad5fde158574433d372 Mon Sep 17 00:00:00 2001 From: Joshua Adams Date: Tue, 1 Jul 2025 10:14:43 +0100 Subject: [PATCH 1/3] Add Cluster Allocation Explain API Tests Adds tests for the `cluster/allocation/explain` API for when non-integer values are passed as the integer expected shard parameter. This change does not modify the `cluster/allocation/explain` API itself. --- .../cluster.allocation_explain/10_basic.yml | 98 ++++++++++++++++--- 1 file changed, 85 insertions(+), 13 deletions(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml index caf4c55e00e7e..ba87c5efde7e0 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml @@ -5,7 +5,28 @@ cluster.allocation_explain: {} --- -"cluster shard allocation explanation test": +"cluster shard allocation explanation test with empty request": + - do: + indices.create: + index: test + body: { "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 9 } } + + - do: + cluster.allocation_explain: + include_disk_info: true + + - match: { current_state: "unassigned" } + - match: { unassigned_info.reason: "INDEX_CREATED" } + - is_true: unassigned_info.at + - match: { index: "test" } + - match: { shard: 0 } + - match: { primary: false } + - is_true: cluster_info + - is_true: can_allocate + +--- +# This test has a valid integer input, but it's above the shard limit, so the index cannot be located +"cluster shard allocation explanation test with max integer shard value": - do: indices.create: index: test @@ -13,13 +34,40 @@ - match: { acknowledged: true } - do: + catch: /shard_not_found_exception/ cluster.allocation_explain: - body: { "index": "test", "shard": 0, "primary": true } + body: { "index": "test", "shard": 2147483647, "primary": true } + +--- +"cluster shard allocation explanation test with long shard value": + - do: + indices.create: + index: test + + - match: { acknowledged: true } + + - do: + catch: /x_content_parse_exception/ + cluster.allocation_explain: + body: { "index": "test", "shard": 214748364777, "primary": true } + +--- +"cluster shard allocation explanation test with float shard value": + - do: + indices.create: + index: test + body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 0 } } + + - match: { acknowledged: true } + + - do: + cluster.allocation_explain: + body: { "index": "test", "shard": 1.0, "primary": true } - match: { current_state: "started" } - is_true: current_node.id - match: { index: "test" } - - match: { shard: 0 } + - match: { shard: 1 } - match: { primary: true } - is_true: can_remain_on_current_node - is_true: can_rebalance_cluster @@ -27,25 +75,49 @@ - is_true: rebalance_explanation --- -"cluster shard allocation explanation test with empty request": +"cluster shard allocation explanation test with double shard value": - do: indices.create: index: test - body: { "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 9 } } + body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 9 } } + + - match: { acknowledged: true } - do: cluster.allocation_explain: - include_disk_info: true + body: { "index": "test", "shard": 2.1234567891234567, "primary": true } - - match: { current_state: "unassigned" } - - match: { unassigned_info.reason: "INDEX_CREATED" } - - is_true: unassigned_info.at + - match: { current_state: "started" } + - is_true: current_node.id - match: { index: "test" } - - match: { shard: 0 } - - match: { primary: false } - - is_true: cluster_info - - is_true: can_allocate + - match: { shard: 2 } + - match: { primary: true } + - is_true: can_remain_on_current_node + - is_true: can_rebalance_cluster + - is_true: can_rebalance_to_other_node + - is_true: rebalance_explanation +--- +"cluster shard allocation explanation test with three valid body parameters": + - do: + indices.create: + index: test + + - match: { acknowledged: true } + + - do: + cluster.allocation_explain: + body: { "index": "test", "shard": 0, "primary": true } + + - match: { current_state: "started" } + - is_true: current_node.id + - match: { index: "test" } + - match: { shard: 0 } + - match: { primary: true } + - is_true: can_remain_on_current_node + - is_true: can_rebalance_cluster + - is_true: can_rebalance_to_other_node + - is_true: rebalance_explanation --- "Cluster shard allocation explanation test with a closed index": From 7ef9f72dc1b2dffbad7659cdc892dbabaed634f3 Mon Sep 17 00:00:00 2001 From: Joshua Adams Date: Tue, 1 Jul 2025 10:19:47 +0100 Subject: [PATCH 2/3] Fix Changed `cluster shard allocation explanation test with double shard value` to 0 replicas --- .../rest-api-spec/test/cluster.allocation_explain/10_basic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml index ba87c5efde7e0..7789ff07fc5a6 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml @@ -79,7 +79,7 @@ - do: indices.create: index: test - body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 9 } } + body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 0 } } - match: { acknowledged: true } From ea4f991ef33667e1928992db575d6bc296e33b4e Mon Sep 17 00:00:00 2001 From: Joshua Adams Date: Tue, 1 Jul 2025 10:48:11 +0100 Subject: [PATCH 3/3] Fix Changed double shard value from 2.1... to 1.1... --- .../test/cluster.allocation_explain/10_basic.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml index 7789ff07fc5a6..1a1fee6e04559 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml @@ -85,12 +85,12 @@ - do: cluster.allocation_explain: - body: { "index": "test", "shard": 2.1234567891234567, "primary": true } + body: { "index": "test", "shard": 1.1234567891234567, "primary": true } - match: { current_state: "started" } - is_true: current_node.id - match: { index: "test" } - - match: { shard: 2 } + - match: { shard: 1 } - match: { primary: true } - is_true: can_remain_on_current_node - is_true: can_rebalance_cluster