quarkus: Postgres reactive configuration doesn't allow for arbitrary parameters on connect string

Describe the bug

I’m trying to use Hibernate Reactive with Panache to connect the quarkus superheroes rest-heroes app to CockroachDB. The app (Quarkus 2.9.2) works fine with Dev Services or a postgres db I stand up on my own.

I’ve done a similar thing with the quarkus superheroes rest-villains app with JDBC & Hibernate ORM with Panache and everything works fine.

When connecting to the Cockroach DB DBaaS, it is mandatory that you include an options=--clister=<cluster_name> parameter, so I tried this configuration in the application.yml:

quarkus:
  datasource:
    username: myusername
    password: mypassword
    reactive:
      url: postgresql://free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/defaultdb?sslmode=require&options=--cluster%3Dheroes-db-2463
      postgresql:
        ssl-mode: require

Expected behavior

I would expect the options connection param to be passed along to the PG driver.

Actual behavior

Instead I get this error:

15:48:28 INFO  [or.hi.re.pr.im.ReactiveIntegrator] (JPA Startup Thread: default-reactive) HR000001: Hibernate Reactive

15:48:29 WARN  [or.hi.re.pr.se.ReactiveGenerationTarget] (vert.x-eventloop-thread-0) HR000021: DDL command failed [io.vertx.pgclient.PgException: FATAL: codeParamsRoutingFailed: missing cluster identifier (08004)]
15:48:29 WARN  [or.hi.re.pr.se.ReactiveGenerationTarget] (vert.x-eventloop-thread-0) HR000021: DDL command failed [io.vertx.pgclient.PgException: FATAL: codeParamsRoutingFailed: missing cluster identifier (08004)]

This indicated that the parameter was not included.

I did this as a test and it works fine:

@ApplicationScoped
public class StartupHelper {
  private final Vertx vertx;

  public StartupHelper(Vertx vertx) {
    this.vertx = vertx;
  }

  public void config(@Observes StartupEvent startupEvent) {
    Log.infof("Inside %s.config", getClass().getName());

    var connectOptions = new PgConnectOptions()
      .setPort(26257)
      .setHost("free-tier14.aws-us-east-1.cockroachlabs.cloud")
      .setDatabase("defaultdb")
      .setUser("myusername")
      .setPassword("mypassword")
      .setSslMode(SslMode.REQUIRE)
      .addProperty("options", "--cluster=heroes-db-2463");

    var poolOptions = new PoolOptions()
      .setMaxSize(5);

    var client = PgPool.client(this.vertx, connectOptions, poolOptions);

    client.query("DROP TABLE IF EXISTS Hero").execute()
      .onItem().invoke(() -> Log.info("Dropped Hero table"))
      .flatMap(r -> client.query("DROP SEQUENCE IF EXISTS hibernate_sequence").execute()
        .onItem().invoke(() -> Log.info("Dropped hibernate_sequence"))
      )
      .flatMap(r -> client.query("CREATE SEQUENCE hibernate_sequence START 1 INCREMENT 1").execute()
        .onItem().invoke(() -> Log.info("Created hibernate_sequence"))
      )
      .flatMap(r -> client.query("CREATE TABLE Hero (id int8 NOT NULL, level int4 NOT NULL, name VARCHAR(50) NOT NULL, otherName VARCHAR(255), picture VARCHAR(255), powers TEXT, PRIMARY KEY (id))").execute()
        .onItem().invoke(() -> Log.info("Created Hero table"))
      )
      .flatMap(r -> client.query("INSERT INTO hero(id, name, otherName, picture, powers, level) VALUES (nextval('hibernate_sequence'), 'Chewbacca', '', 'https://raw.githubusercontent.com/quarkusio/quarkus-super-heroes/characterdata/images/chewbacca--684239239428094811.jpg', 'Super Strength, Agility, Animal Attributes, Jaw Strength, Longevity, Marksmanship, Weapons Master', 30)").execute()
        .onItem().invoke(() -> Log.info("Inserted record into Hero table"))
      )
      .flatMap(r -> client.query("SELECT * FROM hero").execute()
        .onItem().invoke(ar -> Log.infof("Got %d rows", ar.size()))
      )
      .await().atMost(Duration.ofSeconds(20));

    client.close();
  }
}

Now the question is - how do I get that options parameter to stick in the Quarkus configuration? Is it a problem in the upstream Vert.x pg client? Or is there something we can/should do in Quarkus to solve for this? Maybe adding a config param in io.quarkus.reactive.pg.client.runtime.DataSourceReactivePostgreSQLConfig and read that in io.quarkus.reactive.pg.client.runtime.PgPoolRecorder?

How to Reproduce?

Steps to reproduce:

  1. You will need a cockroach labs account. I have a DB set up with credentials I can share if you would like. Please ping me privately (I don’t want to share publicly).
  2. Clone https://github.com/quarkusio/quarkus-super-heroes
  3. cd into rest-heroes
  4. Add the following to src/main/resources/application.yml:
    quarkus:  
      datasource:
        username: myusername 
        password: mypassword
        reactive:
         url: postgresql://free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/defaultdb?sslmode=require&options=--cluster%3Dheroes-db-2463
         postgresql:
           ssl-mode: require
    
  5. Run quarkus dev

Output of uname -a or ver

Darwin edeandrea-m1pro 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7)
OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.9.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /Users/edeandre/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4
Java version: 17.0.3, vendor: Eclipse Adoptium, runtime: /Users/edeandre/.sdkman/candidates/java/17.0.3-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "aarch64", family: "mac"

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (15 by maintainers)

Commits related to this issue

Most upvoted comments

so it looks like someone just needs to patch the extension to pass these on.

I think @edeandrea already signed up for it 😉