From efd59367f5fa5d8b7ae6aec2ea10ad60e5fe69d3 Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 1 Apr 2025 10:08:13 +1100 Subject: [PATCH 1/6] chore(cloud-sql): migrate mysql, postgres samples to new CI --- .github/config/nodejs-dev.jsonc | 2 ++ .github/config/nodejs-prod.jsonc | 2 -- cloud-sql/mysql/mysql2/ci-setup.json | 14 ++++++++++++++ cloud-sql/mysql/mysql2/index.js | 2 +- cloud-sql/postgres/knex/ci-setup.json | 14 ++++++++++++++ cloud-sql/postgres/knex/package.json | 3 ++- 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 cloud-sql/mysql/mysql2/ci-setup.json create mode 100644 cloud-sql/postgres/knex/ci-setup.json diff --git a/.github/config/nodejs-dev.jsonc b/.github/config/nodejs-dev.jsonc index 627ae0a1da..b2192a0525 100644 --- a/.github/config/nodejs-dev.jsonc +++ b/.github/config/nodejs-dev.jsonc @@ -101,6 +101,8 @@ "batch", "cloud-language", "cloud-sql/mysql/mysql", + "cloud-sql/mysql/mysql2", + "cloud-sql/postgres/knex", "cloud-tasks/snippets", "cloud-tasks/tutorial-gcf/app", "cloud-tasks/tutorial-gcf/function", diff --git a/.github/config/nodejs-prod.jsonc b/.github/config/nodejs-prod.jsonc index 8d66993653..da7625698a 100644 --- a/.github/config/nodejs-prod.jsonc +++ b/.github/config/nodejs-prod.jsonc @@ -77,8 +77,6 @@ // TODO: fix these "ai-platform/snippets", // PERMISSION_DENIED: Permission denied: Consumer 'projects/undefined' has been suspended. "automl", // (untested) FAILED_PRECONDITION: Google Cloud AutoML Natural Language was retired on March 15, 2024. Please migrate to Vertex AI instead - "cloud-sql/mysql/mysql2", // (untested) Error: Cannot find module './connect-connector-with-iam-authn.js' - "cloud-sql/postgres/knex", // (untested) CloudSQLConnectorError: Malformed instance connection name provided: expected format of "PROJECT:REGION:INSTANCE", got undefined "cloud-sql/sqlserver/mssql", // (untested) TypeError: The "config.server" property is required and must be of type string. "cloud-sql/sqlserver/tedious", // (untested) TypeError: The "config.server" property is required and must be of type string. "compute", // GoogleError: The resource 'projects/long-door-651/zones/us-central1-a/disks/disk-from-pool-name' was not found diff --git a/cloud-sql/mysql/mysql2/ci-setup.json b/cloud-sql/mysql/mysql2/ci-setup.json new file mode 100644 index 0000000000..0ebf98a2f6 --- /dev/null +++ b/cloud-sql/mysql/mysql2/ci-setup.json @@ -0,0 +1,14 @@ +{ + "env": { + "INSTANCE_HOST": "127.0.0.1", + "INSTANCE_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:mysql-ci", + "UNIX_SOCKET_DIR": "tmp/cloudsql", + "CLOUD_SQL_CONNECTION_NAME": "$INSTANCE_CONNECTION_NAME", + "INSTANCE_UNIX_SOCKET": "$UNIX_SOCKET_DIR/$INSTANCE_CONNECTION_NAME", + "DB_NAME": "kokoro_ci", + "DB_USER": "kokoro_ci" + }, + "secrets": { + "DB_PASS": "nodejs-docs-samples-tests/nodejs-docs-samples-sql-password" + } + } diff --git a/cloud-sql/mysql/mysql2/index.js b/cloud-sql/mysql/mysql2/index.js index 8fccda235f..6000dbdebf 100644 --- a/cloud-sql/mysql/mysql2/index.js +++ b/cloud-sql/mysql/mysql2/index.js @@ -15,7 +15,7 @@ 'use strict'; const express = require('express'); -const createConnectorIAMAuthnPool = require('./connect-connector-with-iam-authn.js'); +const createConnectorIAMAuthnPool = require('./connect-connector-auto-iam-authn.js'); const createConnectorPool = require('./connect-connector.js'); const createTcpPool = require('./connect-tcp.js'); const createUnixSocketPool = require('./connect-unix.js'); diff --git a/cloud-sql/postgres/knex/ci-setup.json b/cloud-sql/postgres/knex/ci-setup.json new file mode 100644 index 0000000000..2ab7576602 --- /dev/null +++ b/cloud-sql/postgres/knex/ci-setup.json @@ -0,0 +1,14 @@ +{ + "env": { + "INSTANCE_HOST": "127.0.0.1", + "INSTANCE_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:postgres-ci", + "UNIX_SOCKET_DIR": "tmp/cloudsql", + "CLOUD_SQL_CONNECTION_NAME": "$INSTANCE_CONNECTION_NAME", + "INSTANCE_UNIX_SOCKET": "$UNIX_SOCKET_DIR/$INSTANCE_CONNECTION_NAME", + "DB_NAME": "kokoro_ci", + "DB_USER": "kokoro_ci" + }, + "secrets": { + "DB_PASS": "nodejs-docs-samples-tests/nodejs-docs-samples-sql-password" + } + } diff --git a/cloud-sql/postgres/knex/package.json b/cloud-sql/postgres/knex/package.json index 82e204f2f5..6451fdf699 100644 --- a/cloud-sql/postgres/knex/package.json +++ b/cloud-sql/postgres/knex/package.json @@ -14,8 +14,9 @@ }, "scripts": { "start": "node server/server.js", + "proxy": "$GITHUB_WORKSPACE/.github/workflows/utils/sql-proxy.sh", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -dir=/cloudsql -instances=$INSTANCE_CONNECTION_NAME &", - "test": "c8 mocha -p -j 2 test/*.test.js --timeout=60000 --exit" + "test": "npm run proxy -- c8 mocha -p -j 2 test/*.test.js --timeout=60000 --exit" }, "dependencies": { "@google-cloud/cloud-sql-connector": "^1.0.0", From f59eff6e88f92abb92642b28fea71bcae6ef0962 Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 1 Apr 2025 10:24:47 +1100 Subject: [PATCH 2/6] rename to match postgres version --- ...or-auto-iam-authn.js => connect-connector-with-iam-authn.js} | 0 cloud-sql/mysql/mysql2/index.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename cloud-sql/mysql/mysql2/{connect-connector-auto-iam-authn.js => connect-connector-with-iam-authn.js} (100%) diff --git a/cloud-sql/mysql/mysql2/connect-connector-auto-iam-authn.js b/cloud-sql/mysql/mysql2/connect-connector-with-iam-authn.js similarity index 100% rename from cloud-sql/mysql/mysql2/connect-connector-auto-iam-authn.js rename to cloud-sql/mysql/mysql2/connect-connector-with-iam-authn.js diff --git a/cloud-sql/mysql/mysql2/index.js b/cloud-sql/mysql/mysql2/index.js index 6000dbdebf..8fccda235f 100644 --- a/cloud-sql/mysql/mysql2/index.js +++ b/cloud-sql/mysql/mysql2/index.js @@ -15,7 +15,7 @@ 'use strict'; const express = require('express'); -const createConnectorIAMAuthnPool = require('./connect-connector-auto-iam-authn.js'); +const createConnectorIAMAuthnPool = require('./connect-connector-with-iam-authn.js'); const createConnectorPool = require('./connect-connector.js'); const createTcpPool = require('./connect-tcp.js'); const createUnixSocketPool = require('./connect-unix.js'); From c153239f98717dfadf8610bca786bc2264e062d5 Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 1 Apr 2025 15:32:13 +1100 Subject: [PATCH 3/6] acquireTimeout warns in mysql2, remove --- cloud-sql/mysql/mysql2/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cloud-sql/mysql/mysql2/index.js b/cloud-sql/mysql/mysql2/index.js index 8fccda235f..14fd561961 100644 --- a/cloud-sql/mysql/mysql2/index.js +++ b/cloud-sql/mysql/mysql2/index.js @@ -65,9 +65,7 @@ const createPool = async () => { // 'connectTimeout' is the maximum number of milliseconds before a timeout // occurs during the initial connection to the database. connectTimeout: 10000, // 10 seconds - // 'acquireTimeout' is the maximum number of milliseconds to wait when - // checking out a connection from the pool before a timeout error occurs. - acquireTimeout: 10000, // 10 seconds + // 'acquireTimeout' is currently unsupported by mysql2 // 'waitForConnections' determines the pool's action when no connections are // free. If true, the request will queued and a connection will be presented // when ready. If false, the pool will call back with an error. From 7696606cc2bb53f09b9a6f9d9b822b7798d20c7e Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 1 Apr 2025 15:32:37 +1100 Subject: [PATCH 4/6] mysql2 query returns [results, fields], so only return fields --- cloud-sql/mysql/mysql2/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-sql/mysql/mysql2/index.js b/cloud-sql/mysql/mysql2/index.js index 14fd561961..b5491eee2d 100644 --- a/cloud-sql/mysql/mysql2/index.js +++ b/cloud-sql/mysql/mysql2/index.js @@ -170,7 +170,7 @@ const httpGet = app.get('/', async (req, res) => { // Run queries concurrently, and wait for them to complete // This is faster than await-ing each query object as it is created - const recentVotes = await recentVotesQuery; + const [recentVotes] = await recentVotesQuery; // Return only the results, not the field metadata const [tabsVotes] = await tabsQuery; const [spacesVotes] = await spacesQuery; From 4eaadb5efa3a7f5cb88c4c4d8f18c9110b28bb3a Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 1 Apr 2025 16:01:50 +1100 Subject: [PATCH 5/6] remove unused test scripts --- cloud-sql/mysql/mysql2/package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cloud-sql/mysql/mysql2/package.json b/cloud-sql/mysql/mysql2/package.json index fdc6554372..c3f0b061fd 100644 --- a/cloud-sql/mysql/mysql2/package.json +++ b/cloud-sql/mysql/mysql2/package.json @@ -14,9 +14,7 @@ "scripts": { "start": "node server/server.js", "system-test": "c8 mocha -p -j 2 test/server.test.js --timeout=60000 --exit", - "system-test-tcp": "c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit", - "system-test-unix": "c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit", - "test": "npm run system-test && npm run system-test-tcp && npm run system-test-unix" + "test": "npm run system-test" }, "dependencies": { "@google-cloud/cloud-sql-connector": "^1.0.0", From 969e514bcd17ec0f495acd4bbb6a905cee26f26c Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 1 Apr 2025 16:06:27 +1100 Subject: [PATCH 6/6] revert bot-suggested rename: would cause excessive region tag change --- ...or-with-iam-authn.js => connect-connector-auto-iam-authn.js} | 0 cloud-sql/mysql/mysql2/index.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename cloud-sql/mysql/mysql2/{connect-connector-with-iam-authn.js => connect-connector-auto-iam-authn.js} (100%) diff --git a/cloud-sql/mysql/mysql2/connect-connector-with-iam-authn.js b/cloud-sql/mysql/mysql2/connect-connector-auto-iam-authn.js similarity index 100% rename from cloud-sql/mysql/mysql2/connect-connector-with-iam-authn.js rename to cloud-sql/mysql/mysql2/connect-connector-auto-iam-authn.js diff --git a/cloud-sql/mysql/mysql2/index.js b/cloud-sql/mysql/mysql2/index.js index b5491eee2d..2b333e2e14 100644 --- a/cloud-sql/mysql/mysql2/index.js +++ b/cloud-sql/mysql/mysql2/index.js @@ -15,7 +15,7 @@ 'use strict'; const express = require('express'); -const createConnectorIAMAuthnPool = require('./connect-connector-with-iam-authn.js'); +const createConnectorIAMAuthnPool = require('./connect-connector-auto-iam-authn.js'); const createConnectorPool = require('./connect-connector.js'); const createTcpPool = require('./connect-tcp.js'); const createUnixSocketPool = require('./connect-unix.js');