I have the following code...
val jdbcURL: String = String.format("jdbc:postgresql:///%s", dbName)
val connProps = new Properties
connProps.setProperty("user", dbUser)
// Note: a non-empty string value for the password property must be set. While this property will be ignored when connecting with the Cloud SQL Connector using IAM auth, leaving it empty will cause driver-level validations to fail.
if( dbUseIAM.equals("true") ){
println("Using IAM password is ignored")
connProps.setProperty("password", "ignored")
} else {
println("Using manual, password must be provided")
connProps.setProperty("password", dbPassword)
}
connProps.setProperty("sslmode", ssoMode)
connProps.setProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory")
connProps.setProperty("cloudSqlInstance", instanceConnectionName)
connProps.setProperty("enableIamAuth", dbUseIAM)
// Initialize connection pool
val config = new HikariConfig
config.setJdbcUrl(jdbcURL)
config.setDataSourceProperties(connProps)
config.setMaximumPoolSize(1)
config.setConnectionTimeout(15000) // 80% of 10s (Per Auth0 Action)
config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE") // TODO: Make configureable
println("Config created")
val pool : DataSource = new HikariDataSource(config) // Do we really need Hikari here if it doesn't need pooling?
println("Returning the datasource")
Some(pool)
It gets called locally and deployed as a cloud function. Locally the script runs in less than 3 seconds. However, when I deploy to GCP as a Cloud function I see...
2022-07-19T20:10:36.833369Z
identity-corporatesru1oceg4a79 Config created
Info
2022-07-19T20:10:37.331144Z
identity-corporatesru1oceg4a79 Connecting to Cloud SQL instance [...:us-central1:db] via SSL socket.
Info
2022-07-19T20:10:37.331453Z
identity-corporatesru1oceg4a79 First Cloud SQL connection, generating RSA key pair.
Default
2022-07-19T20:10:52.434953Z
identity-corporatesru1oceg4a79 Returning the datasource
Notice it took about 5 seconds to return the datasource. What is going on here and why is it taking so long from the cloud function? It is causing 504 timeouts on my postman client.