-
Notifications
You must be signed in to change notification settings - Fork 82
feat(main): Add support for psycopg (Issue #214) #1311
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
base: main
Are you sure you want to change the base?
feat(main): Add support for psycopg (Issue #214) #1311
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
2c802ae
to
4753351
Compare
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
9da84d8
to
0ba0fb7
Compare
Thank you for the contribution! We are excited to add this to the code. I will give this careful review and get back in touch soon with some additional comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work so far. This is going to be a very popular enhancement.
You may want to look at a similar local unix proxy implementation in the node connector.
There are a few things I'd like you to add to this PR. This will get it closer to production-worthy code:
- The socket path should be a configuration parameter
local_socket_path
onconnector.connect()
instead of being hard-coded. This will allow an application to open many connectors to different database instances. - When the listener opens the unix socket, it should set the file permissions to be readable only by the user.
- Handle exceptions from creating and binding the unix socket, log an appropriate error, and raise a LocalProxyStartupError. Define this new exception in google/cloud/sql/connector/exceptions.py
- Consider using asyncio instead of a thread to copy data to and from the proxy.
- When the connector is closed, the
local_communication
loop must be stopped and the socket file removed.
Again, I'm grateful that you put in the time and wrote this feature. Thank you.
cc @rhatgadkar-goog who owns the AlloyDB Python Connector and will be interested to see this. Big +1 on what @hessjcg. This will be a huge win for people wanting to use psycopg and Cloud SQL (or AlloyDB). |
All your comments were addressed on my last commit, I even improve the integration test to use SQLAlchemy like other tests.
Not sure how to handle or if it is expected, this is caused because the |
Changelog: - Add proxy for connections that can only be made through an unix socket, to support the TLS connection - Add support for psycopg, using the proxy server - Add unit and integration tests - Update docs
Changelog: - Make local_socket_path configurable - Set right file permissions - Handle exceptions properly - Use asyncio and the main loop to stop the local proxy and clear the file when the connector is stopped
bb2e9d8
to
28c1c40
Compare
FYI: The last issue I mentioned is only a warning, so, actually, it is not affecting the feature. |
Thank you for this PR of adding support for psycopg! We really appreciate this change. I took a look at this StackOverflow post to help understand what might be happening here: https://stackoverflow.com/questions/71542947/how-can-i-fix-task-was-destroyed-but-it-is-pending. I think you're getting the error, because when the connector closes, you're not cancelling the local proxy server task and waiting for it to shutdown. So maybe you can try making the following changes:
|
Changelog: - Return the asyncio task from `start_local_proxy` - Handle it in `close_async` to cancel it gracefully
@rhatgadkar-goog It worked!, now the warning is gone and the server is being stopped gracefully. Thanks! So, I think the PR is ready for a review, let me know if you want me to do some other modifications. :) |
/gcbrun |
Changelog: - Fix linting issues - Define `self.proxy` on the constructor - Prevent issues with undefined variables
Also fixed a unit test, test coverage is restored to 100% |
/gcbrun |
Trying to add tests for the proxy server, to increase code coverage. |
Changelog: - Add unit tests for proxy - Add test case to connector for drivers that require the local proxy - Make proper adjustments to code
Tests were added, code coverage is now at 94% |
/gcbrun |
Huh, do I need to also keep support for python 3.9? let me check then the fixes I need to do for it. :) |
Added support for Python 3.9, only needed to add some exceptions to handle when I close the server |
/gcbrun |
Still not able to merge it, it says changes requested |
Only maintainers can merge. @kgala2 will have to merge. Great work on this @UzielSilva 👏. |
Hi @UzielSilva, The overall PR looks good, I am checking for corner cases that might not be covered, I'll comment on this PR if I find anything and have psyopg support available as soon as possible. Thanks |
See #214
Changelog: