Skip to content

Commit

Permalink
fix(health): correctly check reports service health (cryostatio#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored May 10, 2024
1 parent e5abe7a commit 000c3de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions src/main/java/io/cryostat/Health.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -58,6 +62,9 @@ class Health {
@ConfigProperty(name = ConfigProperties.GRAFANA_DATASOURCE_URL)
Optional<String> datasourceURL;

@ConfigProperty(name = ConfigProperties.REPORTS_SIDECAR_URL)
String reportsClientURL;

@Inject Logger logger;
@Inject WebClient webClient;

Expand All @@ -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(
Expand All @@ -88,9 +109,9 @@ public Response health() {
"datasourceAvailable",
datasourceAvailable.join(),
"reportsConfigured",
false,
reportsConfigured,
"reportsAvailable",
false)))
reportsAvailable.join())))
.build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/cryostat/HealthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testHealth() {
"datasourceConfigured", is(true),
"datasourceAvailable", is(true),
"reportsConfigured", is(false),
"reportsAvailable", is(false));
"reportsAvailable", is(true));
}

@Test
Expand Down

0 comments on commit 000c3de

Please sign in to comment.