From e9931123aab0140f4974e4cf40b1b348323dcaf2 Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Wed, 3 Jun 2026 20:55:06 -0500 Subject: [PATCH] fix: gcp health check fix --- CHANGELOG.md | 6 ++++ pom.xml | 2 +- .../java/io/floci/cli/GcpGlobalOptions.java | 3 ++ .../cli/commands/gcp/GcpDoctorCommand.java | 2 +- .../cli/commands/gcp/GcpServicesCommand.java | 2 +- .../cli/commands/gcp/GcpStatusCommand.java | 2 +- .../cli/commands/gcp/GcpVersionCommand.java | 2 +- .../cli/commands/gcp/GcpWaitCommand.java | 2 +- .../doctor/checks/EndpointReachableCheck.java | 14 +++++++-- .../io/floci/cli/http/FlociHttpClient.java | 31 ++++++++++++++----- 10 files changed, 50 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db7595e..83a711e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ This project uses [Semantic Versioning](https://semver.org/). ## [Unreleased] +## [0.1.4] — 2026-06-02 + +### Fixed + +- `floci gcp wait` / `status` / `version` / `services` / `doctor` timed out or reported the server unreachable even when the floci-gcp container was healthy — the CLI probed the AWS/Azure control path `/_floci/health`, which the GCP server routes into its GCS service (`object not found bucket=_floci name=health`). The GCP control plane lives under `/_floci-gcp`; `FlociHttpClient` now takes a configurable control-plane prefix and the `floci gcp` commands use `/_floci-gcp` + ## [0.1.3] — 2026-06-02 ### Added diff --git a/pom.xml b/pom.xml index e6111d3..35f96e7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.floci floci-cli - 0.1.3 + 0.1.4 jar Floci CLI diff --git a/src/main/java/io/floci/cli/GcpGlobalOptions.java b/src/main/java/io/floci/cli/GcpGlobalOptions.java index af96645..88d6400 100644 --- a/src/main/java/io/floci/cli/GcpGlobalOptions.java +++ b/src/main/java/io/floci/cli/GcpGlobalOptions.java @@ -10,6 +10,9 @@ import java.net.URI; public class GcpGlobalOptions { + /** Control-plane path prefix exposed by the floci-gcp server (differs from AWS/Azure's {@code /_floci}). */ + public static final String CONTROL_PREFIX = "/_floci-gcp"; + @Option(names = {"--endpoint"}, description = "Floci GCP server endpoint URL", defaultValue = "${FLOCI_GCP_ENDPOINT:-http://localhost:4588}", diff --git a/src/main/java/io/floci/cli/commands/gcp/GcpDoctorCommand.java b/src/main/java/io/floci/cli/commands/gcp/GcpDoctorCommand.java index f1abcfc..20c6b38 100644 --- a/src/main/java/io/floci/cli/commands/gcp/GcpDoctorCommand.java +++ b/src/main/java/io/floci/cli/commands/gcp/GcpDoctorCommand.java @@ -54,7 +54,7 @@ public class GcpDoctorCommand implements Callable { checks.add(new ImagePresentCheck("floci/floci-gcp")); checks.add(new ImageVersionCheck("floci/floci-gcp")); checks.add(new ContainerRunningCheck()); - checks.add(new EndpointReachableCheck()); + checks.add(new EndpointReachableCheck(io.floci.cli.GcpGlobalOptions.CONTROL_PREFIX)); ALL_CHECKS = List.copyOf(checks); } diff --git a/src/main/java/io/floci/cli/commands/gcp/GcpServicesCommand.java b/src/main/java/io/floci/cli/commands/gcp/GcpServicesCommand.java index 66fe541..ee4495b 100644 --- a/src/main/java/io/floci/cli/commands/gcp/GcpServicesCommand.java +++ b/src/main/java/io/floci/cli/commands/gcp/GcpServicesCommand.java @@ -25,7 +25,7 @@ public class GcpServicesCommand implements Callable { @Override public Integer call() { Printer printer = global.printer(); - FlociHttpClient client = new FlociHttpClient(global.endpoint); + FlociHttpClient client = new FlociHttpClient(global.endpoint, GcpGlobalOptions.CONTROL_PREFIX); List services; try { diff --git a/src/main/java/io/floci/cli/commands/gcp/GcpStatusCommand.java b/src/main/java/io/floci/cli/commands/gcp/GcpStatusCommand.java index 0e82c32..ec380d7 100644 --- a/src/main/java/io/floci/cli/commands/gcp/GcpStatusCommand.java +++ b/src/main/java/io/floci/cli/commands/gcp/GcpStatusCommand.java @@ -48,7 +48,7 @@ public class GcpStatusCommand implements Callable { String serverVersion = "unavailable"; String serverEdition = ""; boolean reachable = false; - FlociHttpClient client = new FlociHttpClient(effectiveEndpoint); + FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, GcpGlobalOptions.CONTROL_PREFIX); try { var health = client.health(); serverVersion = health.version(); diff --git a/src/main/java/io/floci/cli/commands/gcp/GcpVersionCommand.java b/src/main/java/io/floci/cli/commands/gcp/GcpVersionCommand.java index 7fe651a..c97fb80 100644 --- a/src/main/java/io/floci/cli/commands/gcp/GcpVersionCommand.java +++ b/src/main/java/io/floci/cli/commands/gcp/GcpVersionCommand.java @@ -35,7 +35,7 @@ public class GcpVersionCommand implements Callable { DockerClient docker = new DockerClient(); String effectiveEndpoint = global.resolvedEndpoint(docker); - FlociHttpClient client = new FlociHttpClient(effectiveEndpoint); + FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, GcpGlobalOptions.CONTROL_PREFIX); try { var info = client.info(); serverVersion = info.version(); diff --git a/src/main/java/io/floci/cli/commands/gcp/GcpWaitCommand.java b/src/main/java/io/floci/cli/commands/gcp/GcpWaitCommand.java index 6b11d63..3261ffa 100644 --- a/src/main/java/io/floci/cli/commands/gcp/GcpWaitCommand.java +++ b/src/main/java/io/floci/cli/commands/gcp/GcpWaitCommand.java @@ -34,7 +34,7 @@ public class GcpWaitCommand implements Callable { Printer printer = global.printer(); long timeoutMillis = WaitCommand.parseDuration(timeout); String effectiveEndpoint = global.resolvedEndpoint(new io.floci.cli.docker.DockerClient()); - FlociHttpClient client = new FlociHttpClient(effectiveEndpoint); + FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, GcpGlobalOptions.CONTROL_PREFIX); Instant deadline = Instant.now().plusMillis(timeoutMillis); while (Instant.now().isBefore(deadline)) { diff --git a/src/main/java/io/floci/cli/doctor/checks/EndpointReachableCheck.java b/src/main/java/io/floci/cli/doctor/checks/EndpointReachableCheck.java index 4fcedcd..3b865ac 100644 --- a/src/main/java/io/floci/cli/doctor/checks/EndpointReachableCheck.java +++ b/src/main/java/io/floci/cli/doctor/checks/EndpointReachableCheck.java @@ -6,9 +6,19 @@ import io.floci.cli.http.FlociHttpClient; public class EndpointReachableCheck implements Check { + private final String controlPrefix; + + public EndpointReachableCheck() { + this(FlociHttpClient.DEFAULT_CONTROL_PREFIX); + } + + public EndpointReachableCheck(String controlPrefix) { + this.controlPrefix = controlPrefix; + } + @Override public CheckResult run(String endpoint, String container) { - FlociHttpClient client = new FlociHttpClient(endpoint); + FlociHttpClient client = new FlociHttpClient(endpoint, controlPrefix); if (client.isReachable()) { try { var health = client.health(); @@ -19,7 +29,7 @@ public class EndpointReachableCheck implements Check { } } return CheckResult.fail("endpoint.reachable", - "GET /_floci/health at " + endpoint + " did not return 200", + "GET " + controlPrefix + "/health at " + endpoint + " did not return 200", "Is Floci running? Try 'floci start'."); } } diff --git a/src/main/java/io/floci/cli/http/FlociHttpClient.java b/src/main/java/io/floci/cli/http/FlociHttpClient.java index 7ea8dc3..1f68505 100644 --- a/src/main/java/io/floci/cli/http/FlociHttpClient.java +++ b/src/main/java/io/floci/cli/http/FlociHttpClient.java @@ -15,18 +15,33 @@ public class FlociHttpClient { private static final ObjectMapper MAPPER = new ObjectMapper(); + /** Default control-plane path prefix used by the AWS and Azure emulators. */ + public static final String DEFAULT_CONTROL_PREFIX = "/_floci"; + private final String endpoint; + private final String controlPrefix; private final HttpClient http; public FlociHttpClient(String endpoint) { + this(endpoint, DEFAULT_CONTROL_PREFIX); + } + + /** + * @param controlPrefix the control-plane path prefix exposed by the target server + * (e.g. {@code /_floci} for AWS/Azure, {@code /_floci-gcp} for GCP). + */ + public FlociHttpClient(String endpoint, String controlPrefix) { this.endpoint = endpoint.endsWith("/") ? endpoint.substring(0, endpoint.length() - 1) : endpoint; + this.controlPrefix = controlPrefix.endsWith("/") + ? controlPrefix.substring(0, controlPrefix.length() - 1) + : controlPrefix; this.http = HttpClient.newBuilder() .connectTimeout(Duration.ofSeconds(5)) .build(); } public HealthInfo health() throws FlociException { - JsonNode node = getJson("/_floci/health"); + JsonNode node = getJson(controlPrefix + "/health"); return new HealthInfo( node.path("version").asText("unknown"), node.path("original_edition").asText(node.path("edition").asText("community")), @@ -44,14 +59,14 @@ public class FlociHttpClient { } public ServerInfo info() throws FlociException { - JsonNode node = getJson("/_floci/info"); + JsonNode node = getJson(controlPrefix + "/info"); return new ServerInfo( node.path("version").asText("unknown"), node.path("original_edition").asText(node.path("edition").asText("community"))); } public InitState initState() throws FlociException { - JsonNode node = getJson("/_floci/init"); + JsonNode node = getJson(controlPrefix + "/init"); JsonNode completed = node.path("completed"); return new InitState( completed.path("boot").asBoolean(), @@ -63,7 +78,7 @@ public class FlociHttpClient { public boolean isReachable() { try { HttpRequest req = HttpRequest.newBuilder() - .uri(URI.create(endpoint + "/_floci/health")) + .uri(URI.create(endpoint + controlPrefix + "/health")) .timeout(Duration.ofSeconds(3)) .GET() .build(); @@ -75,19 +90,19 @@ public class FlociHttpClient { } public Map postSnapshot(String name) throws FlociException { - return postJson("/_floci/snapshots/" + name, "{}"); + return postJson(controlPrefix + "/snapshots/" + name, "{}"); } public Map loadSnapshot(String name) throws FlociException { - return postJson("/_floci/snapshots/" + name + "/load", "{}"); + return postJson(controlPrefix + "/snapshots/" + name + "/load", "{}"); } public JsonNode listSnapshots() throws FlociException { - return getJson("/_floci/snapshots"); + return getJson(controlPrefix + "/snapshots"); } public void deleteSnapshot(String name) throws FlociException { - deleteRequest("/_floci/snapshots/" + name); + deleteRequest(controlPrefix + "/snapshots/" + name); } private JsonNode getJson(String path) throws FlociException {