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

feat(run): Add sigterm handler sample #1902

Merged
merged 25 commits into from
Apr 5, 2021
Merged

feat(run): Add sigterm handler sample #1902

merged 25 commits into from
Apr 5, 2021

Conversation

averikitsch
Copy link
Contributor

No description provided.

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Jan 19, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jan 19, 2021
@snippet-bot
Copy link

snippet-bot bot commented Jan 19, 2021

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@averikitsch averikitsch changed the title Add sigterm handler sample feat: Add sigterm handler sample Jan 19, 2021
run/sigterm-handler/main.go Outdated Show resolved Hide resolved
@tbpg tbpg changed the title feat: Add sigterm handler sample feat(run): Add sigterm handler sample Jan 29, 2021
@tbpg tbpg added the api: run Issues related to the Cloud Run API. label Jan 29, 2021
@averikitsch averikitsch marked this pull request as draft February 9, 2021 17:47
@averikitsch
Copy link
Contributor Author

The testing is not complete, but can you review if this addresses your comments? @ahmetb

Copy link
Contributor

@ahmetb ahmetb left a comment

Choose a reason for hiding this comment

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

Left some more comments.

run/sigterm-handler/main.go Outdated Show resolved Hide resolved
run/sigterm-handler/Dockerfile Show resolved Hide resolved
run/sigterm-handler/main.go Show resolved Hide resolved
@averikitsch
Copy link
Contributor Author

I need guidance on passing the "Build and lint" test. I ran goimports -w . && find . -name go.mod -execdir go mod tidy \; for the run/testing directory based on the error output, but the test isn't passing.

@ahmetb
Copy link
Contributor

ahmetb commented Mar 17, 2021

instead of creating a merge commit, maybe try git rebase origin/master on your last commit (that's not the merge commit).

Comment on lines 65 to 68
defer func() {
// Add extra handling here to close any DB connections, redis, or flush logs
cancel() // Release resources
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

you can shorten this by doing defer cancel() but this is also ok if Adam’s ok with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Normally I'd be for shortening this, but one of our main goals for the sample is to help developers know how to do these cleanup steps, so the extra flag for "drop code here" seems helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect that cleanup code to happen outside this defer, ideally using the same ctx?

I might be missing something.

@ahmetb
Copy link
Contributor

ahmetb commented Mar 18, 2021

Please make sure to test it locally (I'm guessing by adding some time.Sleep in the handler function) and see if it behaves nicely.

@averikitsch
Copy link
Contributor Author

Please make sure to test it locally (I'm guessing by adding some time.Sleep in the handler function) and see if it behaves nicely.

Works locally. Updating Kokoro to run e2e tests on presubmit #2005

@averikitsch averikitsch added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 19, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 19, 2021
run/sigterm-handler/main.go Show resolved Hide resolved
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

defer func() {
// Add extra handling here to close any DB connections, redis, or flush logs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure where the comment went. But, I'd expect any DB connections, etc. to handled outside this defer call. I might be missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@grayside please advise

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the idiomatic approach here, did a little searching to see how folks talk about this, and in the first 5 results, 2 of them do cleanup inside the defer and three just do them after the shutdown.

@ahmetb
Copy link
Contributor

ahmetb commented Mar 29, 2021

This was just asked at https://stackoverflow.com/a/66860299/54929.
It would be good to move this forward.

internal/cloudrunci/cloudrunci.go Outdated Show resolved Hide resolved
internal/cloudrunci/cloudrunci.go Outdated Show resolved Hide resolved
run/sigterm-handler/main.go Outdated Show resolved Hide resolved
run/sigterm-handler/main.go Outdated Show resolved Hide resolved
run/sigterm-handler/main.go Show resolved Hide resolved
run/testing/sigterm_handler.e2e_test.go Outdated Show resolved Hide resolved
@averikitsch
Copy link
Contributor Author

Thank you @tbpg for your help. @grayside the code and tests are ready for a final review.

Copy link
Contributor

@tbpg tbpg left a comment

Choose a reason for hiding this comment

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

One logging comment, otherwise looks good.

@averikitsch
Copy link
Contributor Author

go1.16 tests are successful.
go1.11 tests have Pub/Sub sample failures

@averikitsch
Copy link
Contributor Author

Admins please merge.

@tbpg tbpg added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2021
@tbpg tbpg merged commit e623c04 into master Apr 5, 2021
@tbpg tbpg deleted the sigterm branch April 5, 2021 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: run Issues related to the Cloud Run API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.
Projects
None yet
5 participants