Skip to content

Commit 26a57b4

Browse files
Fix es.http.cname_in_publish_address Deprecation Logging (#47451) (#47497)
Since the property defaulted to `true` this deprecation logging runs every time unless its set to `false` manually (in which case it should've also logged but didn't). I didn't add a tests and removed the tests we had in `7.x` that covered this logging. I did move the check out of the `if (InetAddresses.isInetAddress(hostString) == false) {` condition so this is sort-of covered by the REST tests. IMO, any unit-test of this would be somewhat redundant and would've forced adding a field that just indicates that the deprecated property was used to every instance which seemed pointless. Closes #47436
1 parent e82ccbf commit 26a57b4

File tree

2 files changed

+12
-36
lines changed

2 files changed

+12
-36
lines changed

server/src/main/java/org/elasticsearch/http/HttpInfo.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,23 @@
3333

3434
import java.io.IOException;
3535

36-
import static org.elasticsearch.common.Booleans.parseBoolean;
37-
3836
public class HttpInfo implements Writeable, ToXContentFragment {
3937

4038
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(HttpInfo.class));
4139

42-
/** Whether to add hostname to publish host field when serializing. */
43-
private static final boolean CNAME_IN_PUBLISH_HOST =
44-
parseBoolean(System.getProperty("es.http.cname_in_publish_address"), true);
40+
/** Deprecated property, just here for deprecation logging in 7.x. */
41+
private static final boolean CNAME_IN_PUBLISH_HOST = System.getProperty("es.http.cname_in_publish_address") != null;
4542

4643
private final BoundTransportAddress address;
4744
private final long maxContentLength;
48-
private final boolean cnameInPublishHostProperty;
4945

5046
public HttpInfo(StreamInput in) throws IOException {
51-
this(new BoundTransportAddress(in), in.readLong(), CNAME_IN_PUBLISH_HOST);
47+
this(new BoundTransportAddress(in), in.readLong());
5248
}
5349

5450
public HttpInfo(BoundTransportAddress address, long maxContentLength) {
55-
this(address, maxContentLength, CNAME_IN_PUBLISH_HOST);
56-
}
57-
58-
HttpInfo(BoundTransportAddress address, long maxContentLength, boolean cnameInPublishHostProperty) {
5951
this.address = address;
6052
this.maxContentLength = maxContentLength;
61-
this.cnameInPublishHostProperty = cnameInPublishHostProperty;
6253
}
6354

6455
@Override
@@ -82,14 +73,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
8273
TransportAddress publishAddress = address.publishAddress();
8374
String publishAddressString = publishAddress.toString();
8475
String hostString = publishAddress.address().getHostString();
76+
if (CNAME_IN_PUBLISH_HOST) {
77+
deprecationLogger.deprecated(
78+
"es.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " +
79+
"formatting. Remove this property to get rid of this deprecation warning."
80+
);
81+
}
8582
if (InetAddresses.isInetAddress(hostString) == false) {
8683
publishAddressString = hostString + '/' + publishAddress.toString();
87-
if (cnameInPublishHostProperty) {
88-
deprecationLogger.deprecated(
89-
"es.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " +
90-
"formatting. Remove this property to get rid of this deprecation warning."
91-
);
92-
}
9384
}
9485
builder.field(Fields.PUBLISH_ADDRESS, publishAddressString);
9586
builder.humanReadableField(Fields.MAX_CONTENT_LENGTH_IN_BYTES, Fields.MAX_CONTENT_LENGTH, maxContentLength());

server/src/test/java/org/elasticsearch/http/HttpInfoTests.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,11 @@ public void testCorrectlyDisplayPublishedCname() throws Exception {
4040
new BoundTransportAddress(
4141
new TransportAddress[]{new TransportAddress(localhost, port)},
4242
new TransportAddress(localhost, port)
43-
), 0L, false
43+
), 0L
4444
), "localhost/" + NetworkAddress.format(localhost) + ':' + port
4545
);
4646
}
4747

48-
public void testDeprecatedWarningIfPropertySpecified() throws Exception {
49-
InetAddress localhost = InetAddress.getByName("localhost");
50-
int port = 9200;
51-
assertPublishAddress(
52-
new HttpInfo(
53-
new BoundTransportAddress(
54-
new TransportAddress[]{new TransportAddress(localhost, port)},
55-
new TransportAddress(localhost, port)
56-
), 0L, true
57-
), "localhost/" + NetworkAddress.format(localhost) + ':' + port
58-
);
59-
assertWarnings(
60-
"es.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " +
61-
"formatting. Remove this property to get rid of this deprecation warning.");
62-
}
6348

6449
public void testCorrectDisplayPublishedIp() throws Exception {
6550
InetAddress localhost = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("localhost")));
@@ -69,7 +54,7 @@ public void testCorrectDisplayPublishedIp() throws Exception {
6954
new BoundTransportAddress(
7055
new TransportAddress[]{new TransportAddress(localhost, port)},
7156
new TransportAddress(localhost, port)
72-
), 0L, false
57+
), 0L
7358
), NetworkAddress.format(localhost) + ':' + port
7459
);
7560
}
@@ -80,7 +65,7 @@ public void testCorrectDisplayPublishedIpv6() throws Exception {
8065
new TransportAddress(InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("0:0:0:0:0:0:0:1"))), port);
8166
assertPublishAddress(
8267
new HttpInfo(
83-
new BoundTransportAddress(new TransportAddress[]{localhost}, localhost), 0L, false
68+
new BoundTransportAddress(new TransportAddress[]{localhost}, localhost), 0L
8469
), localhost.toString()
8570
);
8671
}

0 commit comments

Comments
 (0)