Open norrs opened 4 years ago
ATM I have no example code to share as it was from a private code base. :/
I really have no experience with GraalVM, so I'm not really sure what the problem might be. I'm not even sure the underlying API client (google-api-services-sqladmin
) is compatible with GraalVM at the moment (/cc @lesv, who's been looking at these types of things)
One thing I see is:
2020-03-20T23:05:27.304627ZCaused by: java.lang.RuntimeException: Could not load platform constants for ProtocolFamily
which makes me think that it's actually jnr.unixsocket
that isn't compatible, which also wouldn't surprise me.
You could try connecting directly instead of using the unix socket, which is the default behavior in the latest version.
@kurtisvg : Regarding connecting directly, what do you mean here?
From last time I checked the source code of this library (20 March), the contract was that it knew it was used inside a Cloud Run environment, and the configuring of the cloud run application needed a "configuration/mapping" setup for the application telling it should be able to connect to a given cloudsql instance. And my assumption is that this configuring made available an cloudsqlproxy instance listning on unix sockets for being able to allow the cloud run application to connect to the cloud sql database. Has this changed? Is this listening by IP-address now? (which would make it not use unix sockets)
I believe no due to https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/blob/master/core/src/main/java/com/google/cloud/sql/core/CoreSocketFactory.java#L158
What's interesting is from my comment https://github.com/quarkusio/quarkus/pull/6634#issuecomment-603997307 which mentions https://github.com/oracle/graal/issues/1696 which shows an example of using unix sockets and the host has IPv6 interface available and throws the similar exception. I find https://github.com/oracle/graal/issues/1696#issuecomment-533788348 particular interesting, but I tried asking both Quarkus-dev and Graalvm-dev in their respective channels about how I could "link with Linux AMD 64 bindings" (??) when I assembled the Quarkus application. Sadly I got no feedback from how to do it with my quarkus application...
So it would be interesting to see if anyone else is capable of trying what is mentioned, to see if that solves connecting to cloudsql with a native binary in cloud run.
This is kinda a huge blocker for Java developers that are keen on pursuing serverless infrastructure with native binaries having small memory footprint and fast startup times while depending on connecting to a database.
@kurtisvg : Regarding connecting directly, what do you mean here?
In v1.0.16, we no longer attempt to guess if we are on any specific environment, and instead default to connecting via TCP. It's possible to specify you wish to connect using the unix socket, but it's typically not preferable because:
This is kinda a huge blocker for Java developers that are keen on pursuing serverless infrastructure with native binaries having small memory footprint and fast startup times while depending on connecting to a database.
If there is something specific to this library I can do to work around this, please let me know. I suspect the root problem is a conflict between either jnr-unixsocket
or GraalVM configuration settings, and there may not be anything specific to this library that I can do.
@kurtisvg : Regarding connecting directly, what do you mean here?
In v1.0.16, we no longer attempt to guess if we are on any specific environment, and instead default to connecting via TCP.
Ill give this a new try during the weekend then!
This is kinda a huge blocker for Java developers that are keen on pursuing serverless infrastructure with native binaries having small memory footprint and fast startup times while depending on connecting to a database.
If there is something specific to this library I can do to work around this, please let me know. I suspect the root problem is a conflict between either
jnr-unixsocket
or GraalVM configuration settings, and there may not be anything specific to this library that I can do.
Just to clarify , I'm not blaming the library here, just hoping to maybe find some GraalVM experts that might have some more insights, but maybe this wont be an issue with v1.0.16! :-)
Roy - did upgrading to v1.0.16 work?
On Wed, May 6, 2020 at 2:44 PM Roy Sindre Norangshol < notifications@github.com> wrote:
@kurtisvg https://github.com/kurtisvg : Regarding connecting directly, what do you mean here?
In v1.0.16 https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/releases/tag/v1.0.16, we no longer attempt to guess if we are on any specific environment, and instead default to connecting via TCP.
Ill give this a new try during the weekend then!
This is kinda a huge blocker for Java developers that are keen on pursuing serverless infrastructure with native binaries having small memory footprint and fast startup times while depending on connecting to a database.
If there is something specific to this library I can do to work around this, please let me know. I suspect the root problem is a conflict between either jnr-unixsocket or GraalVM configuration settings, and there may not be anything specific to this library that I can do.
Just to clarify , I'm not blaming the library here, just hoping to maybe find some GraalVM experts that might have some more insights, but maybe this wont be an issue with v1.0.16! :-)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/issues/217#issuecomment-624907488, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIVLDSWU6SSYIRAZJMQYNTRQHK43ANCNFSM4MZY65LA .
--
Sorry, I had personal matter that needed my attention this weekend @lesv, I'll research some time tonight from 20:00 to 21:30 to see if I can get something done for testing this. If unable to do it this evening, I'll have a look at it the following weekend. Apologize for this.
@lesv @kurtisvg :
2020-05-13 22:59:31.619 CEST2020-05-13 20:59:31,619 INFO [com.goo.clo.sql.cor.CoreSocketFactory] (Agroal_960983821) Connecting to Cloud SQL instance [coastal-dynamo-219717:europe-north1:frivillig] via SSL socket.
2020-05-13 22:59:31.619 CEST2020-05-13 20:59:31,619 INFO [com.goo.clo.sql.cor.CoreSocketFactory] (Agroal_960983821) First Cloud SQL connection, generating RSA key pair.
2020-05-13 22:59:31.830 CEST2020-05-13 20:59:31,830 CONFIG [com.goo.api.cli.htt.HttpTransport] (pool-5-thread-2) -------------- REQUEST --------------
2020-05-13 22:59:31.831 CESTGET http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
2020-05-13 22:59:31.831 CESTmetadata-flavor: Google
2020-05-13 22:59:31.831 CEST
2020-05-13 22:59:31.831 CEST2020-05-13 20:59:31,830 CONFIG [com.goo.api.cli.htt.HttpTransport] (pool-5-thread-2) curl -v --compressed -H 'metadata-flavor: Google' -- 'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token'
2020-05-13 22:59:31.847 CEST2020-05-13 20:59:31,847 CONFIG [com.goo.api.cli.htt.HttpTransport] (pool-5-thread-2) -------------- RESPONSE --------------
2020-05-13 22:59:31.847 CESTHTTP/1.1 200 OK
2020-05-13 22:59:31.848 CESTServer: Metadata Server for Serverless
2020-05-13 22:59:31.848 CESTMetadata-Flavor: Google
2020-05-13 22:59:31.848 CESTContent-Length: 290
2020-05-13 22:59:31.848 CESTDate: Wed, 13 May 2020 20:59:31 GMT
2020-05-13 22:59:31.848 CESTContent-Type: application/json
2020-05-13 22:59:31.848 CEST
2020-05-13 22:59:31.850 CEST2020-05-13 20:59:31,849 CONFIG [com.goo.api.cli.htt.HttpTransport] (pool-5-thread-2) Total: 290 bytes
2020-05-13 22:59:31.850 CEST2020-05-13 20:59:31,850 CONFIG [com.goo.api.cli.htt.HttpTransport] (pool-5-thread-2) {"access_token":"<MY SECRET>","expires_in":1799,"token_type":"Bearer"}
2020-05-13 22:59:31.851 CEST2020-05-13 20:59:31,850 WARN [io.agr.pool] (Agroal_960983821) Datasource '<default>': Could not create connection to database server.
2020-05-13 22:59:31.851 CEST2020-05-13 20:59:31,851 DEBUG [io.agr.pool] (Agroal_960983821) Cause: : java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1009)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
2020-05-13 22:59:31.851 CEST at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
2020-05-13 22:59:31.851 CEST at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:200)
2020-05-13 22:59:31.851 CEST at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:390)
2020-05-13 22:59:31.851 CEST at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:372)
2020-05-13 22:59:31.851 CEST at java.util.concurrent.FutureTask.run(FutureTask.java:264)
2020-05-13 22:59:31.851 CEST at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:65)
2020-05-13 22:59:31.851 CEST at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1126)
2020-05-13 22:59:31.851 CEST at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
2020-05-13 22:59:31.851 CEST at java.lang.Thread.run(Thread.java:834)
2020-05-13 22:59:31.851 CEST at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:497)
2020-05-13 22:59:31.851 CEST at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
2020-05-13 22:59:31.851 CESTCaused by: java.lang.IllegalArgumentException:
2020-05-13 22:59:31.851 CEST at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:902)
2020-05-13 22:59:31.851 CEST at com.google.api.client.json.JsonParser.parse(JsonParser.java:362)
2020-05-13 22:59:31.851 CEST at com.google.api.client.json.JsonParser.parse(JsonParser.java:337)
2020-05-13 22:59:31.851 CEST at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
2020-05-13 22:59:31.851 CEST at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73)
2020-05-13 22:59:31.852 CEST at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:444)
2020-05-13 22:59:31.852 CEST at com.google.auth.oauth2.ComputeEngineCredentials.refreshAccessToken(ComputeEngineCredentials.java:153)
2020-05-13 22:59:31.852 CEST at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:157)
2020-05-13 22:59:31.852 CEST at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:145)
2020-05-13 22:59:31.852 CEST at com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:91)
2020-05-13 22:59:31.852 CEST at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:88)
2020-05-13 22:59:31.852 CEST at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:430)
2020-05-13 22:59:31.852 CEST at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:549)
2020-05-13 22:59:31.852 CEST at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:482)
2020-05-13 22:59:31.852 CEST at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:599)
2020-05-13 22:59:31.852 CEST at com.google.cloud.sql.core.CloudSqlInstance.fetchMetadata(CloudSqlInstance.java:277)
2020-05-13 22:59:31.852 CEST at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
2020-05-13 22:59:31.852 CEST at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:57)
2020-05-13 22:59:31.852 CEST at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
2020-05-13 22:59:31.852 CEST at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
2020-05-13 22:59:31.852 CEST at java.util.concurrent.FutureTask.run(FutureTask.java:264)
2020-05-13 22:59:31.852 CEST at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
2020-05-13 22:59:31.852 CEST at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
2020-05-13 22:59:31.852 CEST ... 4 more
2020-05-13 22:59:31.852 CESTCaused by: java.lang.IllegalArgumentException: unable to create new instance of class com.google.api.client.util.GenericData because it has no accessible default constructor
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Types.handleExceptionForNewInstance(Types.java:162)
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Types.newInstance(Types.java:117)
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Data.newMapInstance(Data.java:539)
2020-05-13 22:59:31.852 CEST at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:768)
2020-05-13 22:59:31.852 CEST ... 26 more
2020-05-13 22:59:31.852 CESTCaused by: java.lang.InstantiationException: Type `com.google.api.client.util.GenericData` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
2020-05-13 22:59:31.852 CEST at java.lang.Class.newInstance(DynamicHub.java:796)
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Types.newInstance(Types.java:113)
2020-05-13 22:59:31.852 CEST ... 28 more
So errors while deserializing into a POJO from the response body from the metaserver while retrieving a token?
Added some more stuff to my configuration and seem to get past this error now by providing the following maven configuration:
<quarkus.native.additional-build-args>-H:+ReportUnsupportedElementsAtRuntime \
-H:ReflectionConfigurationFiles=/usr/src/app/reflection-config.json \
--rerun-class-initialization-at-runtime=javax.net.ssl.SSLContext \
-H:-UseServiceLoaderFeature \
--enable-all-security-services</quarkus.native.additional-build-args>
Together with the reflection-config.json content of:
[
{
"name" : "com.google.cloud.sql.mysql.SocketFactory",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.google.api.client.json.GenericJson",
"methods": [
{ "name": "<init>", "parameterTypes": [] }
],
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true
},
{
"name" : "com.google.api.client.util.GenericData",
"methods": [
{ "name": "<init>", "parameterTypes": [] }
],
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true
}
]
But now Im treated with :
20-05-13 23:44:23.125 CEST2020-05-13 21:44:23,125 DEBUG [io.agr.pool] (Agroal_12332094751) Cause: : java.sql.SQLNonTransientConnectionException: Cannot connect to MySQL server on localhost:3,306.
2020-05-13 23:44:23.125 CEST
2020-05-13 23:44:23.125 CESTMake sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.
2020-05-13 23:44:23.125 CEST
2020-05-13 23:44:23.125 CEST
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:470)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
2020-05-13 23:44:23.125 CEST at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:200)
2020-05-13 23:44:23.125 CEST at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:390)
2020-05-13 23:44:23.125 CEST at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:372)
2020-05-13 23:44:23.125 CEST at java.util.concurrent.FutureTask.run(FutureTask.java:264)
2020-05-13 23:44:23.125 CEST at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:65)
2020-05-13 23:44:23.125 CEST at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1126)
2020-05-13 23:44:23.125 CEST at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
2020-05-13 23:44:23.125 CEST at java.lang.Thread.run(Thread.java:834)
2020-05-13 23:44:23.125 CEST at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:497)
2020-05-13 23:44:23.125 CEST at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
2020-05-13 23:44:23.125 CESTCaused by: java.lang.NullPointerException
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:980)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
2020-05-13 23:44:23.125 CEST at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
2020-05-13 23:44:23.125 CEST ... 12 more
2020-05-13 23:44:23.128 CEST2020-05-13 21:44:23,127 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-1) SQL Error: 0, SQLState: 08S01
2020-05-13 23:44:23.128 CEST2020-05-13 21:44:23,127 ERROR [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-1) Cannot connect to MySQL server on localhost:3,306.
2020-05-13 23:44:23.128 CEST
2020-05-13 23:44:23.128 CESTMake sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.
Sadly 08S01
seems like it can be many things according to https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-error-sqlstates.html
Another ugly side effect is that quarkus is logging the jdbc url with the secrets (but this is something Quarkus should fix) :
2020-05-13 21:36:05,012 DEBUG [io.qua.agr.run.AbstractDataSourceProducer] (main) Started datasource <default> connected to jdbc:mysql:///quarkus_test?cloudSqlInstance=coastal-dynamo-219717:europe-north1:frivillig&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=quarkus_test&password=<eeek>&useSSL=false
Have a look by checking https://github.com/norrs/quarkus-quickstarts/tree/mysql_cloudrun_cloudsql/hibernate-orm-panache-quickstart . A hint for compiling and deploying can be done by :
rockj@qhira:~/dev/quarkus-quickstarts/hibernate-orm-panache-quickstart (mysql_cloudrun_cloudsql=)$ cloud-build-local -dryrun=false -config=cloudbuild-native.yaml -substitutions=TAG_NAME=demo-0.0.7 -bind-mount-source=false .
Notice after the first deploy, you need to edit the cloud run deployment and add the Cloud SQL and you need to add two additional properties, DB_USER
and DB_PASSWORD
This time I tried MySQL btw and not PostgreSQL. I can also jump on a meet session if that is helpful, my timezone is CEST. (GMT+2). Time for :zzz: now.
Looks to me like the problem is originating from the google-api-client:
2020-05-13 22:59:31.852 CESTCaused by: java.lang.IllegalArgumentException: unable to create new instance of class com.google.api.client.util.GenericData because it has no accessible default constructor
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Types.handleExceptionForNewInstance(Types.java:162)
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Types.newInstance(Types.java:117)
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Data.newMapInstance(Data.java:539)
2020-05-13 22:59:31.852 CEST at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:768)
2020-05-13 22:59:31.852 CEST ... 26 more
2020-05-13 22:59:31.852 CESTCaused by: java.lang.InstantiationException: Type `com.google.api.client.util.GenericData` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
2020-05-13 22:59:31.852 CEST at java.lang.Class.newInstance(DynamicHub.java:796)
2020-05-13 22:59:31.852 CEST at com.google.api.client.util.Types.newInstance(Types.java:113)
2020-05-13 22:59:31.852 CEST ... 28 more
So it looks like we've traded one dependency issue for another unfortunately.
@lesv - have you tried any of the generated libraries with GraalVM before?
No, but @ludoch has, he wrote a doc, I was going to get into it in a few weeks. My understanding is that there are some issues w/ protobuf handling and some issues w/ gRPC. @kurtisvg If you'd like me to setup an experiment, I can do it next week.
I haven't had the opportunity to experiment with GraalVM, so any suggestions are welcome.
I don't think this is necessarily a blocker, as Cloud Run now has Serverless VPC access in beta. This means it's possible to connect directly to Cloud SQL via Private IP without the use of this library.
Because I got stuck on this two months ago, I thought it may be worthwhile sharing some of my findings too
PostgreSQL does not seems to be supported due the fact the driver users jnr-ffi and that does not seems to be supported.
I tried mysql, but according to the micronaut docs, there seems to be an issue with mysql driver too: issue
I got mariadb driver to work in a native build using SQL proxy not this connector. Trying to use the connector I had several issues with our GCP libraries and SSL, after creating my own SocketFactory for mariadb, I got past the errors on the DB and then issues happened at the auth libraries. Followed all the instructions on the doc mentioned here (just happens I work at google and have access to the doc too), but still had issues with several of our libraries. I got stuck at the Keystore throwing NPE, even after bundling the cacerts with the application as instructed.
I have not tried the VPC service connector, that may be a good approach, as mariadb driver works fine to write native code with micronaut at least.
@kurtisvg : So the sad part about Serverless VPC access is additional charges for network traffic, it might be fine for larger enterprises who has too much money :upside_down_face: EDIT: Also feels weird having to enable a VPC when it is within the same project as well.
GraalVM is taking off, and many apps will need a SQL story with it... Beta and expensive workarounds will not work with all customers. Also, do not under estimate local development and local testing, so I would recommend we spend time to address this issue (and all related to GraalVM in GCP libraries)...
Another thing I bumped into, after being able to deploy the micronaut + cloud sql using VPC connector is that the image is consuming all available memory that is given to it. As reported here: https://github.com/oracle/graal/issues/2428 seems to be an issue that some GraalVM applications have.
I noticed that the java version does not "leak" memory, it does however requires more memory to start, and takes way longer to bootstrap too, but at least its not having GC issues.
Update on this: we're currently blocked from moving forward on GraalVM support because the SQLAdmin API client, which the socket factory depends on, is not supported.
Do we have any new update about this? 1.3.0
was released https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/releases
1.3.0
give error while builing with quarkus
Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: com.google.auth.http.HttpCredentialsAdapter.getCredentials(). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time.
Detailed message:
Trace:
at parsing com.google.cloud.sql.core.CloudSqlInstance.<init>(CloudSqlInstance.java:154)
Call path from entry point to com.google.cloud.sql.core.CloudSqlInstance.<init>(String, SQLAdmin, boolean, CredentialFactory, ListeningScheduledExecutorService, ListenableFuture):
at com.google.cloud.sql.core.CloudSqlInstance.<init>(CloudSqlInstance.java:133)
I've tried to reach the same error of @norrs, with v1.2.3
but i'm stuck with some SSL problem
2021-06-06T15:12:43.067057Z{"severity": "ERROR", "at": "2021-06-06T15:12:43+0000", "class": "io.quarkus.runtime.ApplicationLifecycleManager", "message": "Failed to start application (with profile prod)", "error": ": java.lang.NullPointerException
Default
2021-06-06T15:12:43.067075Z at com.google.api.client.util.SecurityUtils.loadKeyStore(SecurityUtils.java:82)
Default
2021-06-06T15:12:43.067080Z at com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:86)
Do we have any new update about this?
1.3.0
was released https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/releases
1.3.0
give error while builing with quarkusError: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: com.google.auth.http.HttpCredentialsAdapter.getCredentials(). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time. Detailed message: Trace: at parsing com.google.cloud.sql.core.CloudSqlInstance.<init>(CloudSqlInstance.java:154) Call path from entry point to com.google.cloud.sql.core.CloudSqlInstance.<init>(String, SQLAdmin, boolean, CredentialFactory, ListeningScheduledExecutorService, ListenableFuture): at com.google.cloud.sql.core.CloudSqlInstance.<init>(CloudSqlInstance.java:133)
I've tried to reach the same error of @norrs, with
v1.2.3
but i'm stuck with some SSL problem2021-06-06T15:12:43.067057Z{"severity": "ERROR", "at": "2021-06-06T15:12:43+0000", "class": "io.quarkus.runtime.ApplicationLifecycleManager", "message": "Failed to start application (with profile prod)", "error": ": java.lang.NullPointerException Default 2021-06-06T15:12:43.067075Z at com.google.api.client.util.SecurityUtils.loadKeyStore(SecurityUtils.java:82) Default 2021-06-06T15:12:43.067080Z at com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:86)
We're currently working on getting Cloud SQL working for GraalVM native image in the google-cloud-graalvm-support
project here: https://github.com/GoogleCloudPlatform/google-cloud-graalvm-support/pull/143
We got a sample successfully working for Cloud SQL with MySQL in the PR, though our method relies on using the --allow-incomplete-classpath
setting.
Question
How may I connect to CloudSQL via Cloud Run using a native binary with graalvm?
(I tried Quarkus and couldn't get it working with native binary, but it worked with JVM.)
I got stuck with the following stacktrace:
Additional Context
https://github.com/quarkusio/quarkus/pull/6634 https://github.com/quarkusio/quarkus/pull/6634#issuecomment-603997307