Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neo4jHealthCheck: Unable to build native image. #3060

Closed
michael-simons opened this issue Jun 1, 2021 · 0 comments · Fixed by #3084
Closed

Neo4jHealthCheck: Unable to build native image. #3060

michael-simons opened this issue Jun 1, 2021 · 0 comments · Fixed by #3084
Assignees
Labels
bug Something isn't working P2

Comments

@michael-simons
Copy link
Contributor

Environment Details

  • Helidon Version: 2.3
  • Helidon SE
  • JDK version:
    openjdk 11.0.11 2021-04-20
    OpenJDK Runtime Environment GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05)
    OpenJDK 64-Bit Server VM GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05, mixed mode, sharing)
  • OS: macOS
  • Docker version (if applicable):

Problem Description

When trying to use the provided Neo4jHealthCheck in an SE application, the application cannot be build natively.

Steps to reproduce

Put the integration on the class path, do somewhere in your SE application

<dependency>
	<groupId>io.helidon.integrations.neo4j</groupId>
	<artifactId>helidon-integrations-neo4j</artifactId>
</dependency>
<dependency>
	<groupId>io.helidon.integrations.neo4j</groupId>
	<artifactId>helidon-integrations-neo4j-health</artifactId>
</dependency>
var driver = config.get("neo4j").as(Neo4j::create).map(Neo4j::driver).orElseThrow();
var readiness = HealthSupport.builder()
			.addReadiness(Neo4jHealthCheck.create(driver))
			.webContext("/management/health/readiness")
			.build();

Reason: The static config here:

https://github.com/oracle/helidon/blob/master/integrations/neo4j/health/src/main/java/io/helidon/integrations/neo4j/health/Neo4jHealthCheck.java#L48-L50

Also, that session will be dangling around:

https://github.com/oracle/helidon/blob/master/integrations/neo4j/health/src/main/java/io/helidon/integrations/neo4j/health/Neo4jHealthCheck.java#L113

Here's a version that does not spot any of this problems:

package org.neo4j.examples.jvm.helidon.se.reactive.support;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.HealthCheckResponseBuilder;
import org.eclipse.microprofile.health.Readiness;
import org.neo4j.driver.Driver;
import org.neo4j.driver.Session;

@Readiness
@ApplicationScoped
public class Neo4jHealthCheck implements HealthCheck {

	/**
	 * The Cypher statement used to verify Neo4j is up.
	 */
	static final String CYPHER = "CALL dbms.components() YIELD name, edition WHERE name = 'Neo4j Kernel' RETURN edition";

	private final Driver driver;

	@Inject
	Neo4jHealthCheck(Driver driver) {
		this.driver = driver;
	}

	public static Neo4jHealthCheck create(Driver driver) {
		return new Neo4jHealthCheck(driver);
	}

	private HealthCheckResponse runHealthCheckQuery(HealthCheckResponseBuilder builder) {

		// We use WRITE here to make sure UP is returned for a server that supports
		// all possible workloads.
		// We also use a transactional function so that we retry this in case the cluster
		// is down.
		try (Session session = this.driver.session()) {

			return session.writeTransaction(tx -> {
				var result = tx.run(CYPHER);

				var edition = result.single().get("edition").asString();
				var resultSummary = result.consume();
				var serverInfo = resultSummary.server();

				var responseBuilder = builder
					.withData("server", serverInfo.version() + "@" + serverInfo.address())
					.withData("edition", edition);

				var databaseInfo = resultSummary.database();
				if (!databaseInfo.name().trim().isBlank()) {
					responseBuilder.withData("database", databaseInfo.name().trim());
				}

				return responseBuilder.up().build();
			});
		}
	}

	@Override
	public HealthCheckResponse call() {

		var builder = HealthCheckResponse.named("Neo4j connection health check");
		try {
			return runHealthCheckQuery(builder);
		} catch (Exception ex) {
			return builder.down().withData("reason", ex.getMessage()).build();
		}
	}
}

I have signed the CLA, you can take this basically as is.

@dalexandrov dalexandrov self-assigned this Jun 2, 2021
@dalexandrov dalexandrov added the bug Something isn't working label Jun 2, 2021
@barchetta barchetta added the P2 label Jun 3, 2021
dalexandrov added a commit that referenced this issue Jun 15, 2021
* Apply fix for Neo4jHealthCheck: Unable to build native image. #3060

* Fix native image build using workaround

* Checkstyle fixes
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants