Deprecate es.http.cname_in_publish_address setting (#45616)

Follow up on #32806.

The system property es.http.cname_in_publish_address is deprecated
starting from 7.0.0 and deprecation warning should be added if the
property is specified.
This PR will go to 7.x and master.
Follow-up PR to remove es.http.cname_in_publish_address property
completely will go to the master.

(cherry picked from commit a5ceca7715818f47ec87dd5f17f8812c584b592b)
This commit is contained in:
Andrey Ershov 2019-08-22 13:04:38 +02:00
parent 57a36eb373
commit ed8307c198
2 changed files with 26 additions and 25 deletions

View File

@ -45,7 +45,7 @@ public class HttpInfo implements Writeable, ToXContentFragment {
private final BoundTransportAddress address; private final BoundTransportAddress address;
private final long maxContentLength; private final long maxContentLength;
private final boolean cnameInPublishHost; private final boolean cnameInPublishHostProperty;
public HttpInfo(StreamInput in) throws IOException { public HttpInfo(StreamInput in) throws IOException {
this(new BoundTransportAddress(in), in.readLong(), CNAME_IN_PUBLISH_HOST); this(new BoundTransportAddress(in), in.readLong(), CNAME_IN_PUBLISH_HOST);
@ -55,10 +55,10 @@ public class HttpInfo implements Writeable, ToXContentFragment {
this(address, maxContentLength, CNAME_IN_PUBLISH_HOST); this(address, maxContentLength, CNAME_IN_PUBLISH_HOST);
} }
HttpInfo(BoundTransportAddress address, long maxContentLength, boolean cnameInPublishHost) { HttpInfo(BoundTransportAddress address, long maxContentLength, boolean cnameInPublishHostProperty) {
this.address = address; this.address = address;
this.maxContentLength = maxContentLength; this.maxContentLength = maxContentLength;
this.cnameInPublishHost = cnameInPublishHost; this.cnameInPublishHostProperty = cnameInPublishHostProperty;
} }
@Override @Override
@ -83,13 +83,11 @@ public class HttpInfo implements Writeable, ToXContentFragment {
String publishAddressString = publishAddress.toString(); String publishAddressString = publishAddress.toString();
String hostString = publishAddress.address().getHostString(); String hostString = publishAddress.address().getHostString();
if (InetAddresses.isInetAddress(hostString) == false) { if (InetAddresses.isInetAddress(hostString) == false) {
if (cnameInPublishHost) {
publishAddressString = hostString + '/' + publishAddress.toString(); publishAddressString = hostString + '/' + publishAddress.toString();
} else { if (cnameInPublishHostProperty) {
deprecationLogger.deprecated( deprecationLogger.deprecated(
"[http.publish_host] was printed as [ip:port] instead of [hostname/ip:port]. " "es.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " +
+ "This format is deprecated and will change to [hostname/ip:port] in a future version. " "formatting. Remove this property to get rid of this deprecation warning."
+ "Use -Des.http.cname_in_publish_address=true to enforce non-deprecated formatting."
); );
} }
} }

View File

@ -40,14 +40,30 @@ public class HttpInfoTests extends ESTestCase {
new BoundTransportAddress( new BoundTransportAddress(
new TransportAddress[]{new TransportAddress(localhost, port)}, new TransportAddress[]{new TransportAddress(localhost, port)},
new TransportAddress(localhost, port) new TransportAddress(localhost, port)
), 0L, true ), 0L, false
), "localhost/" + NetworkAddress.format(localhost) + ':' + port ), "localhost/" + NetworkAddress.format(localhost) + ':' + port
); );
} }
public void hideCnameIfDeprecatedFormat() throws Exception { public void testDeprecatedWarningIfPropertySpecified() throws Exception {
InetAddress localhost = InetAddress.getByName("localhost"); InetAddress localhost = InetAddress.getByName("localhost");
int port = 9200; int port = 9200;
assertPublishAddress(
new HttpInfo(
new BoundTransportAddress(
new TransportAddress[]{new TransportAddress(localhost, port)},
new TransportAddress(localhost, port)
), 0L, true
), "localhost/" + NetworkAddress.format(localhost) + ':' + port
);
assertWarnings(
"es.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " +
"formatting. Remove this property to get rid of this deprecation warning.");
}
public void testCorrectDisplayPublishedIp() throws Exception {
InetAddress localhost = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("localhost")));
int port = 9200;
assertPublishAddress( assertPublishAddress(
new HttpInfo( new HttpInfo(
new BoundTransportAddress( new BoundTransportAddress(
@ -58,26 +74,13 @@ public class HttpInfoTests extends ESTestCase {
); );
} }
public void testCorrectDisplayPublishedIp() throws Exception {
InetAddress localhost = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("localhost")));
int port = 9200;
assertPublishAddress(
new HttpInfo(
new BoundTransportAddress(
new TransportAddress[]{new TransportAddress(localhost, port)},
new TransportAddress(localhost, port)
), 0L, true
), NetworkAddress.format(localhost) + ':' + port
);
}
public void testCorrectDisplayPublishedIpv6() throws Exception { public void testCorrectDisplayPublishedIpv6() throws Exception {
int port = 9200; int port = 9200;
TransportAddress localhost = TransportAddress localhost =
new TransportAddress(InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("0:0:0:0:0:0:0:1"))), port); new TransportAddress(InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("0:0:0:0:0:0:0:1"))), port);
assertPublishAddress( assertPublishAddress(
new HttpInfo( new HttpInfo(
new BoundTransportAddress(new TransportAddress[]{localhost}, localhost), 0L, true new BoundTransportAddress(new TransportAddress[]{localhost}, localhost), 0L, false
), localhost.toString() ), localhost.toString()
); );
} }