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

Cloud SQL (MySQL): Add Cloud Run support and fix broken implementation #1508

Merged
merged 5 commits into from
Oct 8, 2019

Conversation

grayside
Copy link
Collaborator

@grayside grayside commented Oct 5, 2019

This PR originally intended just the following:

  • Adds a Dockerfile to the MySQL sample for use with Cloud Run, based on the Dockerfiles used in the Cloud Run samples.
  • Adds README instructions on deployment to Cloud Run.
  • Adds the sample to the list of Node.js Cloud Run samples.

In the course of the Cloud Run work, I found the current state of the sample is broken. This PR includes fixes for those problems:

  1. promise-mysql in v4 returns a promise from mysql.createPool(). pool instantiation in the master implementation cannot have worked since the library update. Fix: Hacky top-level async.
  2. The code executed in app.on('listening', async () => {... is not being fired (express 4, node 10), meaning the votes table is never created and the client is left hanging while the Node process crashes. Fix: Move the table creation directly after pool creation. Note also the "votes tables" query is an important step in validating the pool configuration as part of service startup. Cloud Run will flag a revision as unhealthy if it fails before listening.

The top-level async/await is a little kludgy, happy to clean it up with additional guidance. One consideration: the potential errors from the mysql library do not seem to benefit from a stack trace, the error message itself is sufficient for troubleshooting purposes (though maybe the goal is to have automatic Stackdriver Error Reporting support?)

@grayside grayside requested a review from kurtisvg October 5, 2019 06:13
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 5, 2019
Copy link
Contributor

@kurtisvg kurtisvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These samples have tests - is there a reason those tests didn't detect the break when mysql-promise was bumped to 4?

@@ -43,7 +43,7 @@ const logger = winston.createLogger({
});

// [START cloud_sql_mysql_mysql_create]
const pool = mysql.createPool({
const connectionOptions = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes moves the pool creation outside of the snippet, which we probably don't want to do since that's what this snippet is for.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you double-check the diff? I deliberately tried to keep things inside the correct region tags, and it still reads that way to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, I mismatched the tags.

Downgrading this to a small nit: Can we move connectionOptions inline? It's not being used anywhere else, so I think it would be more clear inside of mysql.createPool.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do. I broke it out because I like to be able to read the reasoning around a try/await/catch without scrolling.

@grayside
Copy link
Collaborator Author

grayside commented Oct 7, 2019

These samples have tests - is there a reason those tests didn't detect the break when mysql-promise was bumped to 4?

I took a quick look at the test for this sample, and the test has a high reliance on stubbing. I expect the stubbing mechanism prevented the test from making the distinction between returning the pool and returning a promise.

I'm happy to fix things up a bit, but I don't have bandwidth to deepen the tests.

@fhinkel fhinkel added the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 7, 2019
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 7, 2019
@fhinkel
Copy link
Contributor

fhinkel commented Oct 7, 2019

lgtm. Using less stubbing in the tests is out of scope. Can you make the linter happy?

@@ -43,7 +43,7 @@ const logger = winston.createLogger({
});

// [START cloud_sql_mysql_mysql_create]
const pool = mysql.createPool({
const connectionOptions = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, I mismatched the tags.

Downgrading this to a small nit: Can we move connectionOptions inline? It's not being used anywhere else, so I think it would be more clear inside of mysql.createPool.

cloud-sql/mysql/mysql/server.js Outdated Show resolved Hide resolved
cloud-sql/mysql/mysql/server.js Outdated Show resolved Hide resolved
@grayside
Copy link
Collaborator Author

grayside commented Oct 8, 2019

Feedback incorporated, linting fixed. Waiting for tests.

@grayside grayside merged commit d7ae96f into master Oct 8, 2019
@grayside grayside deleted the run/sql branch October 8, 2019 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants