Fix _cluster/state to always return cluster_uuid (#30656)

Since #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.
This commit is contained in:
Tanguy Leroux 2018-05-17 10:58:25 +02:00 committed by GitHub
parent 7915b5f7aa
commit 2ac1f9fe89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View File

@ -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

View File

@ -98,14 +98,11 @@ public class TransportClusterStateAction extends TransportMasterNodeReadAction<C
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) {
@ -114,17 +111,19 @@ public class TransportClusterStateAction extends TransportMasterNodeReadAction<C
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) {