diff --git a/src/main/java/io/cryostat/Health.java b/src/main/java/io/cryostat/Health.java index 7884b3b17..61832981b 100644 --- a/src/main/java/io/cryostat/Health.java +++ b/src/main/java/io/cryostat/Health.java @@ -19,6 +19,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -37,12 +38,15 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.ResponseBuilder; +import org.apache.commons.lang3.StringUtils; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.logging.Logger; @Path("") class Health { + private static final String LOCAL_REPORT_GENERATION_URL = "http://localhost/"; + @ConfigProperty(name = "quarkus.application.name") String name; @@ -58,6 +62,9 @@ class Health { @ConfigProperty(name = ConfigProperties.GRAFANA_DATASOURCE_URL) Optional datasourceURL; + @ConfigProperty(name = ConfigProperties.REPORTS_SIDECAR_URL) + String reportsClientURL; + @Inject Logger logger; @Inject WebClient webClient; @@ -72,7 +79,21 @@ public Response health() { checkUri(dashboardURL, "/api/health", dashboardAvailable); checkUri(datasourceURL, "/", datasourceAvailable); - reportsAvailable.complete(false); + + // the reports URL is always present as it is required for the generated client, so the + // value "http://localhost/" is used to indicate that no sidecar report generation service + // is configured and the Cryostat instance itself should handle report generation. Consider + // this case as reports being unconfigured, but available. If the URL is overridden to some + // other value then this means sidecar report generation is requested, so it is configured + // and the availability must be tested. + boolean reportsConfigured = + StringUtils.isNotBlank(reportsClientURL) + && !Objects.equals(LOCAL_REPORT_GENERATION_URL, reportsClientURL); + if (reportsConfigured) { + checkUri(Optional.of(reportsClientURL), "/health", reportsAvailable); + } else { + reportsAvailable.complete(true); + } return new PermittedResponseBuilder( Response.ok( @@ -88,9 +109,9 @@ public Response health() { "datasourceAvailable", datasourceAvailable.join(), "reportsConfigured", - false, + reportsConfigured, "reportsAvailable", - false))) + reportsAvailable.join()))) .build(); } diff --git a/src/test/java/io/cryostat/HealthTest.java b/src/test/java/io/cryostat/HealthTest.java index e6d9db718..faa80d743 100644 --- a/src/test/java/io/cryostat/HealthTest.java +++ b/src/test/java/io/cryostat/HealthTest.java @@ -66,7 +66,7 @@ public void testHealth() { "datasourceConfigured", is(true), "datasourceAvailable", is(true), "reportsConfigured", is(false), - "reportsAvailable", is(false)); + "reportsAvailable", is(true)); } @Test