Skip to content

Commit

Permalink
Remove transport version from main endpoint response (#97754)
Browse files Browse the repository at this point in the history
This is a partial backport of #97675.

The transport version is a low level detail of how a node behaves in a
cluster. It was recently added to the main endpoint response, but is too
low level and should be moved to another endpoint TBD. This commit
removes it from the main response, though keeps it as part of the wire
format for the MainResponse to avoid any need for a bwc change to the
format.
  • Loading branch information
rjernst authored Jul 18, 2023
1 parent 250307b commit 9728d3d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 56 deletions.
4 changes: 1 addition & 3 deletions docs/reference/setup/install/check-running.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ GET /
"build_snapshot" : false,
"lucene_version" : "{lucene_version}",
"minimum_wire_compatibility_version" : "1.2.3",
"minimum_index_compatibility_version" : "1.2.3",
"transport_version" : "123456"
"minimum_index_compatibility_version" : "1.2.3"
},
"tagline" : "You Know, for Search"
}
Expand All @@ -55,5 +54,4 @@ GET /
// TESTRESPONSE[s/"build_snapshot" : false,/"build_snapshot" : $body.version.build_snapshot,/]
// TESTRESPONSE[s/"minimum_wire_compatibility_version" : "1.2.3"/"minimum_wire_compatibility_version" : $body.version.minimum_wire_compatibility_version/]
// TESTRESPONSE[s/"minimum_index_compatibility_version" : "1.2.3"/"minimum_index_compatibility_version" : $body.version.minimum_index_compatibility_version/]
// TESTRESPONSE[s/"transport_version" : "123456"/"transport_version" : $body.version.transport_version/]
// So much s/// but at least we test that the layout is close to matching....
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class MainResponse extends ActionResponse implements ToXContentObject {

private String nodeName;
private Version version;
private TransportVersion transportVersion;
private ClusterName clusterName;
private String clusterUuid;
private Build build;
Expand All @@ -39,23 +38,18 @@ public class MainResponse extends ActionResponse implements ToXContentObject {
super(in);
nodeName = in.readString();
version = Version.readVersion(in);
transportVersion = in.getTransportVersion().onOrAfter(TransportVersion.V_8_500_014) ? TransportVersion.readVersion(in) : null;
// ignoring transport version that was temporarily part of the response
if (in.getTransportVersion().onOrAfter(TransportVersion.V_8_500_014)) {
TransportVersion.readVersion(in);
}
clusterName = new ClusterName(in);
clusterUuid = in.readString();
build = Build.readBuild(in);
}

public MainResponse(
String nodeName,
Version version,
TransportVersion transportVersion,
ClusterName clusterName,
String clusterUuid,
Build build
) {
public MainResponse(String nodeName, Version version, ClusterName clusterName, String clusterUuid, Build build) {
this.nodeName = nodeName;
this.version = version;
this.transportVersion = transportVersion;
this.clusterName = clusterName;
this.clusterUuid = clusterUuid;
this.build = build;
Expand All @@ -69,10 +63,6 @@ public Version getVersion() {
return version;
}

public TransportVersion getTransportVersion() {
return transportVersion;
}

public ClusterName getClusterName() {
return clusterName;
}
Expand All @@ -90,7 +80,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(nodeName);
Version.writeVersion(version, out);
if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_500_019)) {
TransportVersion.writeVersion(transportVersion, out);
TransportVersion.writeVersion(TransportVersion.current(), out);
}
clusterName.writeTo(out);
out.writeString(clusterUuid);
Expand All @@ -113,7 +103,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
.field("lucene_version", version.luceneVersion().toString())
.field("minimum_wire_compatibility_version", version.minimumCompatibilityVersion().toString())
.field("minimum_index_compatibility_version", version.minimumIndexCompatibilityVersion().toString())
.field("transport_version", transportVersion.toString())
.endObject();
builder.field("tagline", "You Know, for Search");
builder.endObject();
Expand Down Expand Up @@ -147,7 +136,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
response.version = Version.fromString(
((String) value.get("number")).replace("-SNAPSHOT", "").replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "")
);
response.transportVersion = TransportVersion.fromString(((String) value.get("transport_version")));
}, (parser, context) -> parser.map(), new ParseField("version"));
}

Expand All @@ -166,15 +154,14 @@ public boolean equals(Object o) {
MainResponse other = (MainResponse) o;
return Objects.equals(nodeName, other.nodeName)
&& Objects.equals(version, other.version)
&& Objects.equals(transportVersion, other.transportVersion)
&& Objects.equals(clusterUuid, other.clusterUuid)
&& Objects.equals(build, other.build)
&& Objects.equals(clusterName, other.clusterName);
}

@Override
public int hashCode() {
return Objects.hash(nodeName, version, transportVersion, clusterUuid, build, clusterName);
return Objects.hash(nodeName, version, clusterUuid, build, clusterName);
}

@Override
Expand All @@ -185,8 +172,6 @@ public String toString() {
+ '\''
+ ", version="
+ version
+ ", transportVersion="
+ transportVersion
+ ", clusterName="
+ clusterName
+ ", clusterUuid='"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.elasticsearch.rest.root;

import org.elasticsearch.Build;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
Expand Down Expand Up @@ -43,14 +42,7 @@ public TransportMainAction(
protected void doExecute(Task task, MainRequest request, ActionListener<MainResponse> listener) {
ClusterState clusterState = clusterService.state();
listener.onResponse(
new MainResponse(
nodeName,
Version.CURRENT,
TransportVersion.current(),
clusterState.getClusterName(),
clusterState.metadata().clusterUUID(),
Build.CURRENT
)
new MainResponse(nodeName, Version.CURRENT, clusterState.getClusterName(), clusterState.metadata().clusterUUID(), Build.CURRENT)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
package org.elasticsearch.rest.root;

import org.elasticsearch.Build;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.AbstractXContentSerializingTestCase;
import org.elasticsearch.test.TransportVersionUtils;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
Expand All @@ -35,9 +33,8 @@ protected MainResponse createTestInstance() {
String nodeName = randomAlphaOfLength(10);
final String date = new Date(randomNonNegativeLong()).toString();
Version version = VersionUtils.randomIndexCompatibleVersion(random());
TransportVersion transportVersion = TransportVersionUtils.randomVersion();
Build build = new Build(Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(), version.toString());
return new MainResponse(nodeName, version, transportVersion, clusterName, clusterUuid, build);
return new MainResponse(nodeName, version, clusterName, clusterUuid, build);
}

@Override
Expand All @@ -55,8 +52,7 @@ public void testToXContent() throws IOException {
final Build current = Build.CURRENT;
Build build = new Build(current.type(), current.hash(), current.date(), current.isSnapshot(), current.qualifiedVersion());
Version version = Version.CURRENT;
TransportVersion transportVersion = TransportVersion.current();
MainResponse response = new MainResponse("nodeName", version, transportVersion, new ClusterName("clusterName"), clusterUUID, build);
MainResponse response = new MainResponse("nodeName", version, new ClusterName("clusterName"), clusterUUID, build);
XContentBuilder builder = XContentFactory.jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertEquals(
Expand All @@ -76,8 +72,7 @@ public void testToXContent() throws IOException {
"build_snapshot": %s,
"lucene_version": "%s",
"minimum_wire_compatibility_version": "%s",
"minimum_index_compatibility_version": "%s",
"transport_version": "%s"
"minimum_index_compatibility_version": "%s"
},
"tagline": "You Know, for Search"
}
Expand All @@ -90,8 +85,7 @@ public void testToXContent() throws IOException {
current.isSnapshot(),
version.luceneVersion().toString(),
version.minimumCompatibilityVersion().toString(),
version.minimumIndexCompatibilityVersion().toString(),
transportVersion.toString()
version.minimumIndexCompatibilityVersion().toString()
)
),
Strings.toString(builder)
Expand All @@ -103,19 +97,17 @@ protected MainResponse mutateInstance(MainResponse mutateInstance) {
String clusterUuid = mutateInstance.getClusterUuid();
Build build = mutateInstance.getBuild();
Version version = mutateInstance.getVersion();
TransportVersion transportVersion = mutateInstance.getTransportVersion();
String nodeName = mutateInstance.getNodeName();
ClusterName clusterName = mutateInstance.getClusterName();
switch (randomIntBetween(0, 5)) {
switch (randomIntBetween(0, 4)) {
case 0 -> clusterUuid = clusterUuid + randomAlphaOfLength(5);
case 1 -> nodeName = nodeName + randomAlphaOfLength(5);
case 2 ->
// toggle the snapshot flag of the original Build parameter
build = new Build(Build.Type.UNKNOWN, build.hash(), build.date(), build.isSnapshot() == false, build.qualifiedVersion());
case 3 -> version = randomValueOtherThan(version, () -> VersionUtils.randomVersion(random()));
case 4 -> clusterName = new ClusterName(clusterName + randomAlphaOfLength(5));
case 5 -> transportVersion = randomValueOtherThan(transportVersion, () -> TransportVersionUtils.randomVersion(random()));
}
return new MainResponse(nodeName, version, transportVersion, clusterName, clusterUuid, build);
return new MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.elasticsearch.rest.root;

import org.elasticsearch.Build;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.bytes.BytesReference;
Expand All @@ -35,10 +34,9 @@ public void testHeadResponse() throws Exception {
final ClusterName clusterName = new ClusterName("cluster1");
final String clusterUUID = randomAlphaOfLengthBetween(10, 20);
final Version version = Version.CURRENT;
final TransportVersion transportVersion = TransportVersion.current();
final Build build = Build.CURRENT;

final MainResponse mainResponse = new MainResponse(nodeName, version, transportVersion, clusterName, clusterUUID, build);
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build);
XContentBuilder builder = JsonXContent.contentBuilder();
RestRequest restRequest = new FakeRestRequest() {
@Override
Expand All @@ -60,11 +58,10 @@ public void testGetResponse() throws Exception {
final ClusterName clusterName = new ClusterName("cluster1");
final String clusterUUID = randomAlphaOfLengthBetween(10, 20);
final Version version = Version.CURRENT;
final TransportVersion transportVersion = TransportVersion.current();
final Build build = Build.CURRENT;
final boolean prettyPrint = randomBoolean();

final MainResponse mainResponse = new MainResponse(nodeName, version, transportVersion, clusterName, clusterUUID, build);
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build);
XContentBuilder builder = JsonXContent.contentBuilder();

Map<String, String> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package org.elasticsearch.xpack.sql.jdbc;

import org.elasticsearch.Build;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.rest.root.MainResponse;
Expand Down Expand Up @@ -50,8 +49,7 @@ MainResponse createMainResponse(Version version) {
String nodeName = randomAlphaOfLength(10);
final String date = new Date(randomNonNegativeLong()).toString();
Build build = new Build(Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(), version.toString());
TransportVersion transportVersion = TransportVersion.current();
return new MainResponse(nodeName, version, transportVersion, clusterName, clusterUuid, build);
return new MainResponse(nodeName, version, clusterName, clusterUuid, build);
}

String webServerAddress() {
Expand Down

0 comments on commit 9728d3d

Please sign in to comment.