Skip to content

Commit fab31ab

Browse files
author
Andrey Ershov
authored
Log deprecation warning if es.transport.cname_in_publish_address property is specified (#45662)
Follow-up of #45626. Now we always output transport.publish_address with CNAME and log deprecation warning if es.transport.cname_in_publish_address property is specified. This commit also adds a test which will fail once Elasticsearch version is changed to 9, to make sure we remove the property when doing reversioning. Closes #39970
1 parent 8010dd0 commit fab31ab

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

server/src/main/java/org/elasticsearch/transport/TransportInfo.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ public class TransportInfo implements Writeable, ToXContentFragment {
4747

4848
private BoundTransportAddress address;
4949
private Map<String, BoundTransportAddress> profileAddresses;
50-
private final boolean cnameInPublishAddress;
50+
private final boolean cnameInPublishAddressProperty;
5151

5252
public TransportInfo(BoundTransportAddress address, @Nullable Map<String, BoundTransportAddress> profileAddresses) {
5353
this(address, profileAddresses, CNAME_IN_PUBLISH_ADDRESS);
5454
}
5555

5656
public TransportInfo(BoundTransportAddress address, @Nullable Map<String, BoundTransportAddress> profileAddresses,
57-
boolean cnameInPublishAddress) {
57+
boolean cnameInPublishAddressProperty) {
5858
this.address = address;
5959
this.profileAddresses = profileAddresses;
60-
this.cnameInPublishAddress = cnameInPublishAddress;
60+
this.cnameInPublishAddressProperty = cnameInPublishAddressProperty;
6161
}
6262

6363
public TransportInfo(StreamInput in) throws IOException {
@@ -71,7 +71,7 @@ public TransportInfo(StreamInput in) throws IOException {
7171
profileAddresses.put(key, value);
7272
}
7373
}
74-
this.cnameInPublishAddress = CNAME_IN_PUBLISH_ADDRESS;
74+
this.cnameInPublishAddressProperty = CNAME_IN_PUBLISH_ADDRESS;
7575
}
7676

7777
@Override
@@ -97,17 +97,15 @@ static final class Fields {
9797
static final String PROFILES = "profiles";
9898
}
9999

100-
private String formatPublishAddressString(String propertyName, TransportAddress publishAddress){
100+
private String formatPublishAddressString(String propertyName, TransportAddress publishAddress) {
101101
String publishAddressString = publishAddress.toString();
102102
String hostString = publishAddress.address().getHostString();
103103
if (InetAddresses.isInetAddress(hostString) == false) {
104-
if (cnameInPublishAddress) {
105-
publishAddressString = hostString + '/' + publishAddress.toString();
106-
} else {
104+
publishAddressString = hostString + '/' + publishAddress.toString();
105+
if (cnameInPublishAddressProperty) {
107106
deprecationLogger.deprecated(
108-
propertyName + " was printed as [ip:port] instead of [hostname/ip:port]. "
109-
+ "This format is deprecated and will change to [hostname/ip:port] in a future version. "
110-
+ "Use -Des.transport.cname_in_publish_address=true to enforce non-deprecated formatting."
107+
"es.transport.cname_in_publish_address system property is deprecated and no longer affects " + propertyName +
108+
" formatting. Remove this property to get rid of this deprecation warning."
111109
);
112110
}
113111
}

server/src/test/java/org/elasticsearch/transport/TransportInfoTests.java

+17-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.transport;
2121

22+
import org.elasticsearch.Version;
2223
import org.elasticsearch.common.network.NetworkAddress;
2324
import org.elasticsearch.common.transport.BoundTransportAddress;
2425
import org.elasticsearch.common.transport.TransportAddress;
@@ -34,45 +35,47 @@
3435

3536
public class TransportInfoTests extends ESTestCase {
3637

37-
private TransportInfo createTransportInfo(InetAddress address, int port, boolean cnameInPublishAddress) {
38+
private TransportInfo createTransportInfo(InetAddress address, int port, boolean cnameInPublishAddressProperty) {
3839
BoundTransportAddress boundAddress = new BoundTransportAddress(
3940
new TransportAddress[]{new TransportAddress(address, port)},
4041
new TransportAddress(address, port)
4142
);
4243
Map<String, BoundTransportAddress> profiles = Collections.singletonMap("test_profile", boundAddress);
43-
return new TransportInfo(boundAddress, profiles, cnameInPublishAddress);
44+
return new TransportInfo(boundAddress, profiles, cnameInPublishAddressProperty);
45+
}
46+
47+
public void testDoNotForgetToRemoveProperty() {
48+
assertTrue("Remove es.transport.cname_in_publish_address property from TransportInfo in 9.0.0", Version.CURRENT.major < 9);
4449
}
4550

4651
public void testCorrectlyDisplayPublishedCname() throws Exception {
4752
InetAddress address = InetAddress.getByName("localhost");
4853
int port = 9200;
4954
assertPublishAddress(
50-
createTransportInfo(address, port,true),
55+
createTransportInfo(address, port, false),
5156
"localhost/" + NetworkAddress.format(address) + ':' + port
5257
);
5358
}
5459

55-
public void testHideCnameIfDeprecatedFormat() throws Exception {
60+
public void testDeprecatedWarningIfPropertySpecified() throws Exception {
5661
InetAddress address = InetAddress.getByName("localhost");
5762
int port = 9200;
5863
assertPublishAddress(
59-
createTransportInfo(address, port,false),
60-
NetworkAddress.format(address) + ':' + port
64+
createTransportInfo(address, port, true),
65+
"localhost/" + NetworkAddress.format(address) + ':' + port
6166
);
62-
assertWarnings("transport.publish_address was printed as [ip:port] instead of [hostname/ip:port]. " +
63-
"This format is deprecated and will change to [hostname/ip:port] in a future version. " +
64-
"Use -Des.transport.cname_in_publish_address=true to enforce non-deprecated formatting.",
67+
assertWarnings("es.transport.cname_in_publish_address system property is deprecated and no longer affects " +
68+
"transport.publish_address formatting. Remove this property to get rid of this deprecation warning.",
6569

66-
"transport.test_profile.publish_address was printed as [ip:port] instead of [hostname/ip:port]. " +
67-
"This format is deprecated and will change to [hostname/ip:port] in a future version. " +
68-
"Use -Des.transport.cname_in_publish_address=true to enforce non-deprecated formatting.");
70+
"es.transport.cname_in_publish_address system property is deprecated and no longer affects " +
71+
"transport.test_profile.publish_address formatting. Remove this property to get rid of this deprecation warning.");
6972
}
7073

7174
public void testCorrectDisplayPublishedIp() throws Exception {
7275
InetAddress address = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("localhost")));
7376
int port = 9200;
7477
assertPublishAddress(
75-
createTransportInfo(address, port,true),
78+
createTransportInfo(address, port, false),
7679
NetworkAddress.format(address) + ':' + port
7780
);
7881
}
@@ -81,7 +84,7 @@ public void testCorrectDisplayPublishedIpv6() throws Exception {
8184
InetAddress address = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("0:0:0:0:0:0:0:1")));
8285
int port = 9200;
8386
assertPublishAddress(
84-
createTransportInfo(address, port,true),
87+
createTransportInfo(address, port, false),
8588
new TransportAddress(address, port).toString()
8689
);
8790
}

0 commit comments

Comments
 (0)