Skip to content

Commit

Permalink
Get node ID from nodes info in REST tests (#40052) (#40532)
Browse files Browse the repository at this point in the history
We discussed recently that the cluster state API should be considered
"internal" and therefore our usual cast-iron stability guarantees do not hold
for this API.

However, there are a good number of REST tests that try to identify the master
node. Today they call `GET /_cluster/state` API and extract the master node ID
from the response. In fact many of these tests just want an arbitary node ID
(or perhaps a data node ID) so an alternative is to call `GET _nodes` or `GET
_nodes/data:true` and obtain a node ID from the keys of the `nodes` map in the
response.

This change adds the ability for YAML-based REST tests to extract an arbitrary
key from a map so that they can obtain a node ID from the nodes info API
instead of using the master node ID from the cluster state API.

Relates #40047.
  • Loading branch information
DaveCTurner authored Mar 27, 2019
1 parent 23395a9 commit 5a2ba34
Show file tree
Hide file tree
Showing 18 changed files with 406 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

- match: { acknowledged: true }

- do:
cluster.state:
metric: [ master_node ]

- do:
cluster.allocation_explain:
body: { "index": "test", "shard": 0, "primary": true }
Expand All @@ -37,10 +33,6 @@
index: test
body: { "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 9 } }

- do:
cluster.state:
metric: [ master_node ]

- do:
cluster.allocation_explain:
include_disk_info: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ setup:

---
"Explain API for non-existent node & shard":
- skip:
features: [arbitrary_key]

- do:
cluster.state:
metric: [ master_node ]

- set: {master_node: node_id}
nodes.info:
node_id: data:true
- set:
nodes._arbitrary_key_: node_id

- do:
cluster.reroute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
- skip:
version: " - 6.9.99"
reason: expects warnings that pre-7.0.0 will not send
features: "warnings"
# creates an index with one document solely allocated on the master node
features: [warnings, arbitrary_key]

# creates an index with one document solely allocated on a particular data node
# and shrinks it into a new index with a single shard
# we don't do the relocation to a single node after the index is created
# here since in a mixed version cluster we can't identify
# which node is the one with the highest version and that is the only one that can safely
# be used to shrink the index.
- do:
cluster.state: {}
# Get master node id

- set: { master_node: master }
- do:
nodes.info:
node_id: data:true
- set:
nodes._arbitrary_key_: node_id

- do:
indices.create:
index: source
wait_for_active_shards: 1
body:
settings:
# ensure everything is allocated on a single node
index.routing.allocation.include._id: $master
# ensure everything is allocated on the same data node
index.routing.allocation.include._id: $node_id
index.number_of_shards: 2
index.number_of_replicas: 0
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
- skip:
version: " - 6.9.99"
reason: expects warnings that pre-7.0.0 will not send
features: "warnings"
features: [warnings, arbitrary_key]

- do:
cluster.state: {}
# Get master node id

- set: { master_node: master }
nodes.info:
node_id: data:true
- set:
nodes._arbitrary_key_: node_id

# create index
- do:
Expand All @@ -19,7 +19,7 @@
body:
settings:
# ensure everything is allocated on a single node
index.routing.allocation.include._id: $master
index.routing.allocation.include._id: $node_id
index.number_of_shards: 2
index.number_of_replicas: 0
mappings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
- skip:
version: " - 6.9.99"
reason: expects warnings that pre-7.0.0 will not send
features: "warnings"
features: [warnings, arbitrary_key]

- do:
cluster.state: {}

# get master node id
- set: { master_node: master }
nodes.info:
node_id: data:true
- set:
nodes._arbitrary_key_: node_id

- do:
indices.create:
index: source
wait_for_active_shards: 1
body:
settings:
# ensure everything is allocated on the master node
index.routing.allocation.include._id: $master
# ensure everything is allocated on the same node
index.routing.allocation.include._id: $node_id
index.number_of_shards: 2
index.number_of_replicas: 0
index.merge.scheduler.max_merge_count: 4
Expand Down Expand Up @@ -63,7 +63,7 @@
- match: { copy-settings-target.settings.index.merge.scheduler.max_merge_count: "4" }
- match: { copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { copy-settings-target.settings.index.blocks.write: "true" }
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $master }
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $node_id }

# now we do a actual shrink and copy settings (by default)
- do:
Expand All @@ -89,7 +89,7 @@
- match: { default-copy-settings-target.settings.index.merge.scheduler.max_merge_count: "4" }
- match: { default-copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { default-copy-settings-target.settings.index.blocks.write: "true" }
- match: { default-copy-settings-target.settings.index.routing.allocation.include._id: $master }
- match: { default-copy-settings-target.settings.index.routing.allocation.include._id: $node_id }

# now we do a actual shrink and try to set no copy settings
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
- skip:
version: " - 6.9.99"
reason: expects warnings that pre-7.0.0 will not send
features: "warnings"
features: [arbitrary_key, warnings]

- do:
cluster.state: {}

# get master node id
- set: { master_node: master }
nodes.info:
node_id: data:true
- set:
nodes._arbitrary_key_: node_id

- do:
indices.create:
index: source
wait_for_active_shards: 1
body:
settings:
# ensure everything is allocated on the master node
index.routing.allocation.include._id: $master
# ensure everything is allocated on the same node
index.routing.allocation.include._id: $node_id
index.number_of_replicas: 0
index.number_of_shards: 1
index.number_of_routing_shards: 4
Expand Down Expand Up @@ -66,7 +66,7 @@
- match: { copy-settings-target.settings.index.merge.scheduler.max_merge_count: "4" }
- match: { copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { copy-settings-target.settings.index.blocks.write: "true" }
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $master }
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $node_id }

# now we do a actual shrink and copy settings (by default)
- do:
Expand All @@ -93,7 +93,7 @@
- match: { default-copy-settings-target.settings.index.merge.scheduler.max_merge_count: "4" }
- match: { default-copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { default-copy-settings-target.settings.index.blocks.write: "true" }
- match: { default-copy-settings-target.settings.index.routing.allocation.include._id: $master }
- match: { default-copy-settings-target.settings.index.routing.allocation.include._id: $node_id }

- do:
catch: /illegal_argument_exception/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
setup:
- skip:
features: [arbitrary_key]
---
"node_info test":
- do:
cluster.state: {}

# Get master node id
- set: { master_node: master }

- do:
nodes.info: {}
- set:
nodes._arbitrary_key_: node_id

- is_true: nodes
- is_true: cluster_name
- is_true: nodes.$master.roles
- is_true: nodes.$node_id.roles
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

"node_info test profile is empty":
- skip:
features: stash_in_path
features: [stash_in_path, arbitrary_key]

- do:
cluster.state: {}

- set: {master_node: master}
nodes.info: {}
- set:
nodes._arbitrary_key_: node_id

- do:
nodes.info:
metric: [ transport ]

- is_true: nodes.$master.transport.profiles
- is_true: nodes.$node_id.transport.profiles
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
---
"node_info test flat_settings":
- do:
cluster.state: {}
- skip:
features: [arbitrary_key]

- set: { master_node: master }
- do:
nodes.info: {}
- set:
nodes._arbitrary_key_: node_id

- do:
nodes.info:
metric: [ settings ]

- match : { nodes.$master.settings.client.type: node }
- match : { nodes.$node_id.settings.client.type: node }

- do:
nodes.info:
metric: [ settings ]
flat_settings: true

- match : { nodes.$master.settings.client\.type: node }
- match : { nodes.$node_id.settings.client\.type: node }
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@

---
"Nodes stats level":
- do:
cluster.state: {}
- skip:
features: [arbitrary_key]

- set: { master_node: master }
- do:
nodes.info: {}
- set:
nodes._arbitrary_key_: node_id

- do:
nodes.stats:
metric: [ indices ]
level: "indices"

- is_true: nodes.$master.indices.indices
- is_true: nodes.$node_id.indices.indices

---
"Nodes stats unrecognized parameter":
Expand Down
Loading

0 comments on commit 5a2ba34

Please sign in to comment.