Remove distribution from main response in compatibility mode (#898) (#921)

This Change removes version.distribution when the version.number is
overridden with the cluster setting compatibility.override_main_response_version.

Signed-off-by: Marc Handalian <handalm@amazon.com>
This commit is contained in:
Marc Handalian 2021-07-01 19:57:36 -07:00 committed by GitHub
parent 230f90b554
commit b749b38043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -139,9 +139,11 @@ public class MainResponse extends ActionResponse implements ToXContentObject {
builder.field("name", nodeName);
builder.field("cluster_name", clusterName.value());
builder.field("cluster_uuid", clusterUuid);
builder.startObject("version")
.field("distribution", build.getDistribution())
.field("number", versionNumber)
builder.startObject("version");
if (isCompatibilityModeDisabled()) {
builder.field("distribution", build.getDistribution());
}
builder.field("number", versionNumber)
.field("build_type", build.type().displayName())
.field("build_hash", build.hash())
.field("build_date", build.date())
@ -155,6 +157,12 @@ public class MainResponse extends ActionResponse implements ToXContentObject {
return builder;
}
private boolean isCompatibilityModeDisabled() {
// if we are not in compatibility mode (spoofing versionNumber), then
// build.getQualifiedVersion is always used.
return build.getQualifiedVersion().equals(versionNumber);
}
private static final ObjectParser<MainResponse, Void> PARSER = new ObjectParser<>(MainResponse.class.getName(), true,
MainResponse::new);

View File

@ -112,6 +112,7 @@ public class MainResponseTests extends AbstractSerializingTestCase<MainResponse>
XContentBuilder builder = XContentFactory.jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertTrue(Strings.toString(builder).contains("\"number\":\"" + responseVersion + "\","));
assertFalse(Strings.toString(builder).contains("\"distribution\":\"" + Build.CURRENT.getDistribution() + "\","));
}
@Override