Skip to content

Commit

Permalink
Fix _cluster/state to always return cluster_uuid (elastic#30656)
Browse files Browse the repository at this point in the history
Since elastic#30143, the Cluster State API should always returns the current
cluster_uuid in the response body, regardless of the metrics filters.

This is not exactly true as it is returned only if metadata metrics and
no specific indices are requested.

This commit fixes the behavior to always return the cluster_uuid and
add new test.
  • Loading branch information
tlrx authored and ywelsch committed May 23, 2018
1 parent c37fc34 commit cc06997
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,24 @@ setup:
version: " - 6.3.99"
reason: "cluster state including cluster_uuid at the top level is new in v6.4.0 and higher"

# Get the current cluster_uuid
- do:
cluster.state: {}
- set: { metadata.cluster_uuid : cluster_uuid }

- do:
cluster.state:
metric: [ master_node, version, metadata ]
metric: [ master_node, version ]

- is_true: cluster_uuid
- match: { cluster_uuid: $cluster_uuid }
- is_true: master_node
- is_true: version
- is_true: state_uuid
- is_true: metadata

- do:
cluster.state:
metric: [ routing_table ]
index: testidx

- match: { cluster_uuid: $cluster_uuid }
- is_true: routing_table
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,11 @@ protected void masterOperation(final ClusterStateRequest request, final ClusterS
if (request.blocks()) {
builder.blocks(currentState.blocks());
}
if (request.metaData()) {
MetaData.Builder mdBuilder;
if (request.indices().length == 0) {
mdBuilder = MetaData.builder(currentState.metaData());
} else {
mdBuilder = MetaData.builder();
}

MetaData.Builder mdBuilder = MetaData.builder();
mdBuilder.clusterUUID(currentState.metaData().clusterUUID());

if (request.metaData()) {
if (request.indices().length > 0) {
String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request);
for (String filteredIndex : indices) {
Expand All @@ -114,17 +111,19 @@ protected void masterOperation(final ClusterStateRequest request, final ClusterS
mdBuilder.put(indexMetaData, false);
}
}
} else {
mdBuilder = MetaData.builder(currentState.metaData());
}

// Filter our metadata that shouldn't be returned by API
for(ObjectObjectCursor<String, Custom> custom : currentState.metaData().customs()) {
for(ObjectObjectCursor<String, Custom> custom : currentState.metaData().customs()) {
if(!custom.value.context().contains(MetaData.XContentContext.API)) {
mdBuilder.removeCustom(custom.key);
}
}

builder.metaData(mdBuilder);
}
builder.metaData(mdBuilder);

if (request.customs()) {
for (ObjectObjectCursor<String, ClusterState.Custom> custom : currentState.customs()) {
if (custom.value.isPrivate() == false) {
Expand Down

0 comments on commit cc06997

Please sign in to comment.