Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
acc22e2
[ci] Add PR pipeline for testing ipv6
brianseeders Jan 9, 2026
55207ec
Change instance type
brianseeders Jan 9, 2026
dec7f15
Fix run-gradle script
brianseeders Jan 12, 2026
01cacac
Try to prefer ipv6
brianseeders Jan 14, 2026
b79c700
Merge remote-tracking branch 'origin/main' into ipv6-pipelines
brianseeders Jan 14, 2026
6ebd30f
Try m7a instead
brianseeders Jan 14, 2026
a470f50
Add --continue
brianseeders Jan 15, 2026
c5a2633
Try to disable docker tests
brianseeders Jan 15, 2026
98f2a65
Try fixing some ipv6 address formatting failures
brianseeders Jan 16, 2026
2000c33
Another ipv6 fix
brianseeders Jan 16, 2026
e1de058
ipv6 fix
brianseeders Jan 16, 2026
fdf819d
Some more attempted fixes
brianseeders Jan 20, 2026
77eee74
Merge remote-tracking branch 'origin/main' into ipv6-pipelines
brianseeders Jan 20, 2026
4fab1e7
Another try
brianseeders Jan 20, 2026
027b067
Undo last fix and DRY up the address formatting
brianseeders Jan 21, 2026
2dd2ab8
Fix a bunch more issues
brianseeders Jan 21, 2026
57406bc
Fix another issue, and try to ensure localhost always resolves to ipv6
brianseeders Jan 21, 2026
51f4312
Merge branch 'main' into ipv6-pipelines
brianseeders Jan 22, 2026
7fa28ad
Add a global test task timeout
brianseeders Jan 22, 2026
aea692d
Merge branch 'ipv6-pipelines' of github.com:brianseeders/elasticsearc…
brianseeders Jan 22, 2026
8c717c2
Move timeout
brianseeders Jan 22, 2026
ab7681f
Several more fixes
brianseeders Jan 23, 2026
a05c97b
Merge remote-tracking branch 'origin/main' into ipv6-pipelines
brianseeders Jan 23, 2026
53280ff
A few more fixes and debugging
brianseeders Jan 23, 2026
ebdebbb
Remove from hosts file and see what happens
brianseeders Jan 23, 2026
01b539a
Fix a few failing tests due to incorrect url
brianseeders Jan 28, 2026
173f8bf
Fix another http address
brianseeders Jan 28, 2026
6fb1050
Add ipv6 address to allow list
brianseeders Jan 28, 2026
0011ceb
Fix more tests
brianseeders Jan 28, 2026
cd59f52
Fix url formatting in ldap test
brianseeders Jan 28, 2026
427069f
WIP vibe coding
brianseeders Jan 29, 2026
a6a911c
More vibe coded fixes
brianseeders Jan 29, 2026
fadbf03
One azure fix
brianseeders Jan 29, 2026
6d68bca
More fixes
brianseeders Jan 29, 2026
26c2d66
More fixes
brianseeders Jan 29, 2026
33472c3
More fixes
brianseeders Jan 29, 2026
78b6d6c
Default to ipv6 for test clusters, which fixes some tests
brianseeders Jan 30, 2026
27651f4
spotless
brianseeders Jan 30, 2026
5f869cd
Add some vibe coded fixes, mostly just to test out
brianseeders Jan 31, 2026
4be39c0
Undo some vibe code changes
brianseeders Feb 2, 2026
100274a
Disable HDFS tests when in ipv6 mode
brianseeders Feb 2, 2026
3a0566f
Fix S3 tests with invalid yaml
brianseeders Feb 2, 2026
518fc26
More fixes
brianseeders Feb 2, 2026
298629c
Fix some AI slop
brianseeders Feb 3, 2026
c033daf
Fix more ai slop
brianseeders Feb 3, 2026
c1ead4a
Skip some azure tests in ipv6
brianseeders Feb 3, 2026
acd5e6c
Cleanup
brianseeders Feb 3, 2026
8c02aa4
Spotless
brianseeders Feb 3, 2026
719796d
Merge remote-tracking branch 'origin/main' into ipv6-pipelines
brianseeders Feb 3, 2026
34e2564
Spotless
brianseeders Feb 3, 2026
3a6e050
Fix missing equals
brianseeders Feb 3, 2026
0e9d212
Simplify and remove forbidden api
brianseeders Feb 4, 2026
cbe82d3
Test fixes, forbidden api fixes
brianseeders Feb 4, 2026
ed48e51
[CI] Auto commit changes from spotless
Feb 4, 2026
2f8a8bd
Fix allowlist
brianseeders Feb 5, 2026
5e96315
Fix password reset tool tests and add some logging for future
brianseeders Feb 5, 2026
07942f4
Fix forbidden api
brianseeders Feb 5, 2026
602f9fc
Merge branch 'ipv6-pipelines' of github.com:brianseeders/elasticsearc…
brianseeders Feb 5, 2026
c4ec0b9
Spotless
brianseeders Feb 5, 2026
0fceab8
Skip certain rest compat tests in IPv6 mode because they will fail wi…
brianseeders Feb 9, 2026
0ab8f88
Merge branch 'main' into ipv6-pipelines
brianseeders Feb 9, 2026
e226ae3
IPv6 binding only in ipv6 mode
brianseeders Feb 10, 2026
5f0f774
Merge remote-tracking branch 'origin/main' into ipv6-pipelines
brianseeders Feb 10, 2026
cae3468
Merge branch 'main' into ipv6-pipelines
brianseeders Feb 10, 2026
510f372
iterating
brianseeders Feb 11, 2026
0ad5459
Remove duplicated string checks all over the place
brianseeders Feb 11, 2026
9c15a40
Spotless
brianseeders Feb 11, 2026
0c97b0a
Add weekly pipeline, and update key in PR pipeline
brianseeders Feb 11, 2026
9140484
Merge branch 'main' into ipv6-pipelines
brianseeders Feb 12, 2026
7c26c15
Merge branch 'ipv6-pipelines' of github.com:brianseeders/elasticsearc…
brianseeders Feb 12, 2026
3ce3533
Try in-memory workspace
brianseeders Feb 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

if [[ "${USE_IPV6_TESTING:-}" == "true" ]]; then
# Ensure that `localhost` resolves to only `::1`
sudo bash -c 'echo "::1 localhost" | cat - /etc/hosts > temp_file && mv temp_file /etc/hosts'
sudo sed -i '/^127\.0\.0\.1/d' /etc/hosts
sudo resolvectl flush-caches || true
fi

# On some distros, this directory ends up not readable by the `elasticsearch` user that gets created during tests
# This fixes that
chmod 755 ~
Expand Down
30 changes: 30 additions & 0 deletions .buildkite/pipelines/periodic.weekly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
steps:
- group: ipv6-tests
steps:
- label: "{{matrix.GRADLE_TASK}} / ipv6-tests"
command: .ci/scripts/run-gradle.sh --continue -Djava.net.preferIPv6Addresses=true -Dbwc.checkout.align=true -Dorg.elasticsearch.build.cache.push=true -Dignore.tests.seed -Dscan.capture-file-fingerprints {{matrix.GRADLE_TASK}}
timeout_in_minutes: 300
agents:
provider: aws
imagePrefix: elasticsearch-aws-ubuntu-2404-nvidia
instanceType: m7a.8xlarge
diskSizeGb: 150
diskType: gp3
diskName: /dev/sda1
buildDirectory: /dev/shm/bk
ipv6Only: true
env:
GRADLE_TASK: "{{matrix.GRADLE_TASK}}"
JAVA_TOOL_OPTIONS: "-Djava.net.preferIPv6Addresses=true"
_JAVA_OPTIONS: "-Djava.net.preferIPv6Addresses=true"
USE_IPV6_TESTING: "true"
DISABLE_DOCKER_TESTS: "true"
matrix:
setup:
GRADLE_TASK:
- checkPart1
- checkPart2
- checkPart3
- checkPart4
- checkPart5
- checkPart6
35 changes: 35 additions & 0 deletions .buildkite/pipelines/pull-request/ipv6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
config:
allow-labels: test-ipv6
skip-labels:
- ">test-mute"
steps:
- group: ipv6-tests
steps:
- label: "{{matrix.GRADLE_TASK}} / ipv6-tests"
key: "ipv6-tests"
command: .ci/scripts/run-gradle.sh --continue -Djava.net.preferIPv6Addresses=true -Dbwc.checkout.align=true -Dorg.elasticsearch.build.cache.push=true -Dignore.tests.seed -Dscan.capture-file-fingerprints {{matrix.GRADLE_TASK}}
timeout_in_minutes: 300
agents:
provider: aws
imagePrefix: elasticsearch-aws-ubuntu-2404-nvidia
instanceType: m7a.8xlarge
diskSizeGb: 150
diskType: gp3
diskName: /dev/sda1
buildDirectory: /dev/shm/bk
ipv6Only: true
env:
GRADLE_TASK: "{{matrix.GRADLE_TASK}}"
JAVA_TOOL_OPTIONS: "-Djava.net.preferIPv6Addresses=true"
_JAVA_OPTIONS: "-Djava.net.preferIPv6Addresses=true"
USE_IPV6_TESTING: "true"
DISABLE_DOCKER_TESTS: "true"
matrix:
setup:
GRADLE_TASK:
- checkPart1
- checkPart2
- checkPart3
- checkPart4
- checkPart5
- checkPart6
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,9 @@ private void createConfiguration() {
baseConfig.put("path.repo", confPathRepo.toAbsolutePath().toString());
baseConfig.put("path.data", confPathData.toAbsolutePath().toString());
baseConfig.put("path.logs", confPathLogs.toAbsolutePath().toString());
if (Boolean.getBoolean("java.net.preferIPv6Addresses")) {
baseConfig.put("network.host", "_local:ipv6_");
}
baseConfig.put("node.attr.testattr", "test");
baseConfig.put("node.portsfile", "true");
baseConfig.put("http.port", httpPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.test.ESTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -117,7 +118,7 @@ public static void stopServer() {
}

private static String url(final String path) {
String hostname = server.getAddress().getHostString();
String hostname = InetAddresses.toUriString(server.getAddress().getAddress());
int port = server.getAddress().getPort();
return "http://" + hostname + ":" + port + path;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ testClusters.configureEach {
module ':modules:lang-painless'
module ':modules:rest-root'
// Whitelist reindexing from the local node so we can test reindex-from-remote.
setting 'reindex.remote.whitelist', '127.0.0.1:*'
setting 'reindex.remote.whitelist', '127.0.0.1:*,[::1]:*'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected boolean addMockHttpTransport() {
protected Settings nodeSettings() {
Settings.Builder settings = Settings.builder().put(super.nodeSettings());
// Whitelist reindexing from the http host we're going to use
settings.put(TransportReindexAction.REMOTE_CLUSTER_WHITELIST.getKey(), "127.0.0.1:*");
settings.put(TransportReindexAction.REMOTE_CLUSTER_WHITELIST.getKey(), "127.0.0.1:*,::1:*");
settings.put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME);
return settings.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.common.BackoffPolicy;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
Expand Down Expand Up @@ -91,7 +92,7 @@ protected boolean addMockHttpTransport() {
final Settings nodeSettings() {
return Settings.builder()
// whitelist reindexing from the HTTP host we're going to use
.put(TransportReindexAction.REMOTE_CLUSTER_WHITELIST.getKey(), "127.0.0.1:*")
.put(TransportReindexAction.REMOTE_CLUSTER_WHITELIST.getKey(), "127.0.0.1:*,[::1]:*")
.build();
}

Expand All @@ -118,9 +119,10 @@ public void testReindexFromRemote() throws Exception {
assertNotNull(masterNode);

TransportAddress address = masterNode.getInfo(HttpInfo.class).getAddress().publishAddress();
String host = InetAddresses.toUriString(address.address().getAddress());
RemoteInfo remote = new RemoteInfo(
"http",
address.getAddress(),
host,
address.getPort(),
null,
new BytesArray("{\"match_all\":{}}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static Iterable<Object[]> parameters() throws Exception {
.module("lang-painless")
.module("parent-join")
.module("rest-root")
.setting("reindex.remote.whitelist", "127.0.0.1:*")
.setting("reindex.remote.whitelist", "127.0.0.1:*,[::1]:*")
.build();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
}

// see com.azure.storage.blob.BlobUrlParts.parseIpUrl
final String endpoint = "ignored;DefaultEndpointsProtocol=http;BlobEndpoint=" + httpServerUrl() + "/" + accountName;
final String endpoint = "ignored;DefaultEndpointsProtocol=http;BlobEndpoint=" + httpServerUrlLocalhost() + "/" + accountName;

// The first node configured sets these for all nodes
MAX_CONNECTION_SETTING.compareAndSet(-1, randomIntBetween(10, 30));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ protected static Optional<Integer> getRangeEnd(HttpExchange exchange) {

protected String getEndpointForServer(HttpServer server, String accountName) {
InetSocketAddress address = server.getAddress();
return "http://" + InetAddresses.toUriString(address.getAddress()) + ":" + address.getPort() + "/" + accountName;
// Use "localhost" for loopback addresses to work around Azure SDK's inability to parse bracketed IPv6 addresses
String host = address.getAddress().isLoopbackAddress() ? "localhost" : InetAddresses.toUriString(address.getAddress());
return "http://" + host + ":" + address.getPort() + "/" + accountName;
}

public static void readFromInputStream(InputStream inputStream, long bytesToRead) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,9 @@ private void warnIfUnsupportedSettingSet(String settingName, Object value) {

private String getEndpointForServer(HttpServer server, String accountName) {
InetSocketAddress address = server.getAddress();
return "http://" + InetAddresses.toUriString(address.getAddress()) + ":" + address.getPort() + "/" + accountName;
// Use "localhost" for loopback addresses to work around Azure SDK's inability to parse bracketed IPv6 addresses
String host = address.getAddress().isLoopbackAddress() ? "localhost" : InetAddresses.toUriString(address.getAddress());
return "http://" + host + ":" + address.getPort() + "/" + accountName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.sun.net.httpserver.HttpServer;

import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.SuppressForbidden;
Expand Down Expand Up @@ -97,7 +98,8 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
CREDENTIALS_FILE_SETTING.getConcreteSettingForNamespace("test").getKey(),
TestUtils.createServiceAccount(random())
);
String upstreamServerUrl = "http://" + upstreamServer.getAddress().getHostString() + ":" + upstreamServer.getAddress().getPort();
String host = InetAddresses.toUriString(upstreamServer.getAddress().getAddress());
String upstreamServerUrl = "http://" + host + ":" + upstreamServer.getAddress().getPort();
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal, otherSettings))
.put(ENDPOINT_SETTING.getConcreteSettingForNamespace("test").getKey(), upstreamServerUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.common.blobstore.support.BlobMetadata;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.BigArrays;
Expand Down Expand Up @@ -279,7 +280,8 @@ private ContainerAndBlobStore createBlobContainer(final String repositoryName) t

protected String getEndpointForServer(final HttpServer server) {
final InetSocketAddress address = server.getAddress();
return "http://" + address.getHostString() + ":" + address.getPort();
String host = InetAddresses.toUriString(address.getAddress());
return "http://" + host + ":" + address.getPort();
}

private record ContainerAndBlobStore(GoogleCloudStorageBlobContainer blobContainer, GoogleCloudStorageBlobStore blobStore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class RepositoryS3ExplicitProtocolRestIT extends AbstractRepositoryS3Rest
private static String getEndpoint() {
final var s3FixtureAddress = s3Fixture.getAddress();
assertThat(s3FixtureAddress, startsWith("http://"));
return s3FixtureAddress.substring("http://".length());
return "\"" + s3FixtureAddress.substring("http://".length()) + "\"";
}

public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void setUp() throws Exception {
DEFAULT_REGION_UNAVAILABLE
) {
private InetAddress[] resolveHost(String host) throws UnknownHostException {
assertEquals("127.0.0.1", host);
assertTrue(InetAddress.getByName(host).isLoopbackAddress());
if (shouldErrorOnDns && randomBoolean() && randomBoolean()) {
throw new UnknownHostException(host);
}
Expand Down Expand Up @@ -204,7 +204,8 @@ protected BlobContainer createBlobContainer(
final String clientName = randomAlphaOfLength(5).toLowerCase(Locale.ROOT);

final InetSocketAddress address = httpServer.getAddress();
final String endpoint = "http://" + InetAddresses.toUriString(address.getAddress()) + ":" + address.getPort();
String host = InetAddresses.toUriString(address.getAddress());
final String endpoint = "http://" + host + ":" + address.getPort();
logger.info("--> creating client with endpoint [{}]", endpoint);
clientSettings.put(ENDPOINT_SETTING.getConcreteSettingForNamespace(clientName).getKey(), endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ public void testDifferentPorts() throws Exception {
assertThat(boundTransportAddress.boundAddresses()[0].getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
} else {
assertThat(boundTransportAddress.boundAddresses().length, greaterThan(1));
// Determine if the publish address is IPv4 or IPv6
boolean publishIsV4 = boundTransportAddress.publishAddress().address().getAddress() instanceof Inet4Address;
for (TransportAddress boundAddress : boundTransportAddress.boundAddresses()) {
assertThat(boundAddress, instanceOf(TransportAddress.class));
TransportAddress inetBoundAddress = boundAddress;
if (inetBoundAddress.address().getAddress() instanceof Inet4Address) {
// IPv4 address is preferred publish address for _local_
boolean boundIsV4 = inetBoundAddress.address().getAddress() instanceof Inet4Address;
if (boundIsV4 == publishIsV4) {
// The bound address matching the publish address type should have the same port
assertThat(inetBoundAddress.getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
import org.elasticsearch.cluster.node.VersionInformation;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
Expand Down Expand Up @@ -92,7 +93,9 @@ public void testConnectException() throws UnknownHostException {
null
);
assertThat(e.getMessage(), containsString("connect_exception"));
assertThat(e.getMessage(), containsString("[127.0.0.1:9876]"));

String loopback = InetAddresses.toUriString(InetAddress.getByName("localhost"));
assertThat(e.getMessage(), containsString("[" + loopback + ":9876]"));
}

public void testDefaultKeepAliveSettings() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.discovery.DiscoveryModule;
import org.elasticsearch.env.Environment;
Expand Down Expand Up @@ -88,6 +89,17 @@ protected void before() {
}
};

@ClassRule
public static final ExternalResource MUTE_IN_IPV6 = new ExternalResource() {
@Override
protected void before() {
assumeFalse(
"Tests not currently working correctly with IPv6",
Booleans.parseBoolean(System.getProperty("java.net.preferIPv6Addresses", "true"))
);
}
};

@BeforeClass
public static void setupKeyStore() throws IOException {
Path tempDir = createTempDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ protected boolean addMockHttpTransport() {

void verifyPublishAddress(String publishAddressSetting, String expectedAddress) throws IOException {
final var node = internalCluster().startNode(Settings.builder().put("http.publish_host", publishAddressSetting));
assertEquals(
expectedAddress,
internalCluster().getInstance(HttpServerTransport.class, node).boundAddress().publishAddress().getAddress()
);
String actualAddress = internalCluster().getInstance(HttpServerTransport.class, node).boundAddress().publishAddress().getAddress();

if (actualAddress.equals("::1") && expectedAddress.equals("127.0.0.1")) {
expectedAddress = "::1";
}

assertEquals(expectedAddress, actualAddress);
internalCluster().stopNode(node);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.http.client.utils.URLEncodedUtils;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.util.PageCacheRecycler;
Expand All @@ -30,12 +31,12 @@
import org.hamcrest.Matchers;

import java.io.IOException;
import java.net.InetAddress;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.Matchers.aMapWithSize;
Expand Down Expand Up @@ -63,7 +64,11 @@ protected MockTransportService createTransportService() {

public void testEC2DiscoveryRetriesOnRateLimiting() throws IOException {
final String accessKey = "ec2_access";
final List<String> hosts = List.of("127.0.0.1:9300");
final InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
// For the EC2 response, we use the plain IP address without port
final String loopbackAddressString = NetworkAddress.format(loopbackAddress);
// For the expected TransportAddress, use proper IPv6 formatting with brackets
final String expectedHost = NetworkAddress.format(loopbackAddress, 9300);
final Map<String, Integer> failedRequests = new ConcurrentHashMap<>();
// retry the same request 5 times at most
final int maxRetries = randomIntBetween(1, 5);
Expand All @@ -88,9 +93,7 @@ public void testEC2DiscoveryRetriesOnRateLimiting() throws IOException {
for (NameValuePair parse : URLEncodedUtils.parse(request, UTF_8)) {
if ("Action".equals(parse.getName())) {
responseBody = generateDescribeInstancesResponse(
hosts.stream()
.map(address -> Instance.builder().publicIpAddress(address).build())
.collect(Collectors.toList())
List.of(Instance.builder().publicIpAddress(loopbackAddressString).build())
);
break;
}
Expand All @@ -111,7 +114,7 @@ public void testEC2DiscoveryRetriesOnRateLimiting() throws IOException {
resolver.start();
final List<TransportAddress> addressList = seedHostsProvider.getSeedAddresses(resolver);
assertThat(addressList, Matchers.hasSize(1));
assertThat(addressList.get(0).toString(), is(hosts.get(0)));
assertThat(addressList.get(0).toString(), is(expectedHost));
assertThat(failedRequests, aMapWithSize(1));
assertThat(failedRequests.values().iterator().next(), is(maxRetries));
}
Expand Down
Loading