diff --git a/extensions/neo4j/runtime/src/main/java/io/quarkus/neo4j/runtime/health/Neo4jHealthCheck.java b/extensions/neo4j/runtime/src/main/java/io/quarkus/neo4j/runtime/health/Neo4jHealthCheck.java index caa1bc77e6fdf..37dd41b0c213f 100644 --- a/extensions/neo4j/runtime/src/main/java/io/quarkus/neo4j/runtime/health/Neo4jHealthCheck.java +++ b/extensions/neo4j/runtime/src/main/java/io/quarkus/neo4j/runtime/health/Neo4jHealthCheck.java @@ -10,9 +10,10 @@ import org.jboss.logging.Logger; import org.neo4j.driver.AccessMode; import org.neo4j.driver.Driver; +import org.neo4j.driver.Record; import org.neo4j.driver.Session; import org.neo4j.driver.SessionConfig; -import org.neo4j.driver.exceptions.SessionExpiredException; +import org.neo4j.driver.internal.retry.ExponentialBackoffRetryLogic; import org.neo4j.driver.summary.ResultSummary; import org.neo4j.driver.summary.ServerInfo; @@ -25,7 +26,7 @@ public class Neo4jHealthCheck implements HealthCheck { /** * The Cypher statement used to verify Neo4j is up. */ - private static final String CYPHER = "RETURN 1 AS result"; + private static final String CYPHER = "CALL dbms.components() YIELD versions, name, edition WHERE name = 'Neo4j Kernel' RETURN edition, versions[0] as version"; /** * Message indicating that the health check failed. */ @@ -49,15 +50,16 @@ public HealthCheckResponse call() { HealthCheckResponseBuilder builder = HealthCheckResponse.named("Neo4j connection health check").up(); try { - ResultSummary resultSummary; // Retry one time when the session has been expired try { - resultSummary = runHealthCheckQuery(); - } catch (SessionExpiredException sessionExpiredException) { - log.warn(MESSAGE_SESSION_EXPIRED); - resultSummary = runHealthCheckQuery(); + return runHealthCheckQuery(builder); + } catch (Throwable exception) { + if (ExponentialBackoffRetryLogic.isRetryable(exception)) { + log.warn(MESSAGE_SESSION_EXPIRED); + return runHealthCheckQuery(builder); + } + throw exception; } - return buildStatusUp(resultSummary, builder); } catch (Exception e) { return builder.down().withData("reason", e.getMessage()).build(); } @@ -67,29 +69,34 @@ public HealthCheckResponse call() { * Applies the given {@link ResultSummary} to the {@link HealthCheckResponseBuilder builder} and calls {@code build} * afterwards. * + * @param editionAndVersion a single record containing edition and version * @param resultSummary the result summary returned by the server * @param builder the health builder to be modified * @return the final {@link HealthCheckResponse health check response} */ - private static HealthCheckResponse buildStatusUp(ResultSummary resultSummary, HealthCheckResponseBuilder builder) { + private static HealthCheckResponse buildStatusUp(Record editionAndVersion, ResultSummary resultSummary, + HealthCheckResponseBuilder builder) { ServerInfo serverInfo = resultSummary.server(); - builder.withData("server", serverInfo.version() + "@" + serverInfo.address()); + builder.withData("server", "Neo4j/" + editionAndVersion.get("version").asString() + "@" + serverInfo.address()); String databaseName = resultSummary.database().name(); if (!(databaseName == null || databaseName.trim().isEmpty())) { builder.withData("database", databaseName.trim()); } + builder.withData("edition", editionAndVersion.get("edition").asString()); return builder.build(); } - private ResultSummary runHealthCheckQuery() { + private HealthCheckResponse runHealthCheckQuery(HealthCheckResponseBuilder builder) { // We use WRITE here to make sure UP is returned for a server that supports // all possible workloads try (Session session = this.driver.session(DEFAULT_SESSION_CONFIG)) { - ResultSummary resultSummary = session.run(CYPHER).consume(); - return resultSummary; + var result = session.run(CYPHER); + var editionAndVersion = result.single(); + ResultSummary resultSummary = result.consume(); + return buildStatusUp(editionAndVersion, resultSummary, builder); } } } diff --git a/integration-tests/neo4j/src/test/java/io/quarkus/it/neo4j/Neo4jFunctionalityTest.java b/integration-tests/neo4j/src/test/java/io/quarkus/it/neo4j/Neo4jFunctionalityTest.java index 0f8255e973d99..8055bd7d5e855 100644 --- a/integration-tests/neo4j/src/test/java/io/quarkus/it/neo4j/Neo4jFunctionalityTest.java +++ b/integration-tests/neo4j/src/test/java/io/quarkus/it/neo4j/Neo4jFunctionalityTest.java @@ -52,7 +52,8 @@ public void health() { .body("status", is("UP"), "checks.status", containsInAnyOrder("UP"), "checks.name", containsInAnyOrder("Neo4j connection health check"), - "checks.data.server", containsInAnyOrder(matchesRegex("Neo4j/.*@.*:\\d*"))); + "checks.data.server", containsInAnyOrder(matchesRegex("Neo4j/.*@.*:\\d*")), + "checks.data.edition", containsInAnyOrder(is(notNullValue()))); } @Test