fix(opensearch): report an endpoint for a domain with no container behind it (#4284)

* fix(opensearch): report an endpoint for a domain with no container behind it

A domain reports Processing false as soon as it is created, but Endpoint stays
blank whenever there is no container: the service is mocked, or the container
could not be started. SDK waiters poll DescribeDomain until the domain is
active and names an endpoint, so neither exit is ever reached and a create
hangs until the caller's own deadline instead of failing.

Both paths now synthesize an AWS-shaped endpoint,
search-<domain>-<suffix>.<region>.es.amazonaws.com, with the suffix derived
from the domain name so it survives a restart. The container path is
unchanged.

* docs(opensearch): say which cases the synthesized endpoint covers

The javadoc claimed SDK waiters poll DescribeDomain until the domain names an
endpoint. botocore ships no waiters for opensearch or es, and Terraform's
create wait only checks that Endpoint is non-nil, which "" already satisfies.

It also claimed the fallback covers a container that could not be started.
tryStartDomain rethrows whenever Docker is reachable, so it returns false only
when no daemon is reachable at all.

Both now say what they actually cover: mock mode and an unreachable Docker
daemon, reporting an AWS-shaped endpoint in place of a blank one. The test's
class comment carried the same two claims.

* fix(opensearch): take the synthesized endpoint's DNS suffix from the partition

The endpoint hardcoded .es.amazonaws.com, so a cn or gov region reported a
commercial hostname. AwsRegions.dnsSuffixFor resolves it from the region, which
is what the partition-literals gate asks for.

theEndpointTakesItsDnsSuffixFromThePartition creates a domain in cn-north-1 and
asserts the endpoint ends in .amazonaws.com.cn.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-24 12:04:44 -04:00
1 parent ec40bcf5f4
commit db07c56704
2 files changed
+111

No files matched your search

@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackend;
@@ -149,10 +150,12 @@ public class OpenSearchService implements ResourceProvider {
if (config.services().opensearch().mock()) {
domain.setProcessing(false);
domain.setEndpoint(synthesizedEndpoint(domainName, region));
} else {
domain.setProcessing(true);
if (!domainManager.tryStartDomain(domain)) {
domain.setProcessing(false);
domain.setEndpoint(synthesizedEndpoint(domainName, region));
}
}
@@ -161,6 +164,24 @@ public class OpenSearchService implements ResourceProvider {
return domain;
}
/**
* The endpoint reported for a domain with no container behind it. Two cases reach this: the
* service is mocked, and no Docker daemon is reachable, which is the only condition under which
* {@link OpenSearchDomainManager#tryStartDomain} returns false rather than rethrowing.
*
* <p>It reports an AWS-shaped endpoint in place of a blank one,
* {@code search-<domain>-<suffix>.<region>.es.<dnsSuffix>}, taking the DNS suffix from the
* region's partition rather than assuming the commercial one, with the name suffix derived from the
* domain name so it survives a restart. A domain reporting {@code Processing false} alongside
* {@code Endpoint ""} describes a state AWS never returns, and a client that reads the endpoint
* to address the domain gets an empty string to connect to.
*/
private static String synthesizedEndpoint(String domainName, String region) {
String suffix = Integer.toHexString(domainName.hashCode() & 0x7fffffff);
return "search-" + domainName + "-" + suffix + "." + region + ".es."
+ AwsRegions.dnsSuffixFor(region);
}
public Domain describeDomain(String domainName) {
return domainStore.get(domainName)
.orElseThrow(() -> new AwsException("ResourceNotFoundException",