Skip to content

Conversation

@rhatgadkar-goog
Copy link
Collaborator

@rhatgadkar-goog rhatgadkar-goog commented Dec 24, 2024

This is a port of GoogleCloudPlatform/alloydb-go-connector#572 for the AlloyDB Python connector. It allows connecting to a sandbox AlloyDB instance using connection info properties from a JSON file, instead of calling the AlloyDB APIs to get this information (which is done by the internal and lazy caches).

Using a static connection info currently works for the sync client (pg8000), but doesn't work for the async client (asyncpg). When using the async client, getting timeout errors here, due to ConnectionDoesNotExistError. This is fine for now, as long as we can use the Python connector (using the sync client) to connect to a sandbox AlloyDB instance.

@jackwotherspoon
Copy link
Collaborator

@rhatgadkar-goog With no PR description I do not yet fully see the benefit or use-case of this change...

Is it to allow to customize the certs more easily?

@enocom
Copy link
Member

enocom commented Jan 30, 2025

This is a peer of what we did in Go: https://github.com/GoogleCloudPlatform/alloydb-go-connector/blob/main/options.go#L218-L246

The primary use case is for development-time convenience by removing the control plane from the connection flow. I would guess there aren't many production uses for this, but it's a big convenience for development.


while True:
with context.wrap_socket(sock, server_side=True) as ssock:
with context.wrap_socket(sock, server_side=True) as ssock:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change is needed to run multiple tests that use the same proxy_server fixture. Without it, only 1 test can successfully run. The other tests fail with "Connection refused" errors.

thread.start()
yield thread
thread.join()
thread.join(0.1) # wait 100ms to allow the proxy server to start
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change is required when implementing the change above (swapping the order of while True and with context.wrap_socket) to prevent the test from hanging

@rhatgadkar-goog rhatgadkar-goog force-pushed the static-connection-info branch 2 times, most recently from 3e74127 to 013375f Compare January 31, 2025 03:44
@rhatgadkar-goog rhatgadkar-goog marked this pull request as ready for review January 31, 2025 19:11
@rhatgadkar-goog rhatgadkar-goog requested a review from a team as a code owner January 31, 2025 19:11
Copy link
Collaborator

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

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

I still am not sold on this approach being the best one. There are ways to load static info without changes to the public interface. I would highly suggest looking into them more instead of just doing this purely because the Go Connector did it this way.

One example being I don't think it would be much effort to make a SandBoxClient testing object similar to FakeAlloyDBClient that is wired up to always return static connection info.

class FakeAlloyDBClient:

This way you could write a simple private helper method _create_sandbox_connector that would look something like this:

def _create_sandbox_connector(static_info, *args, **kwargs):
    connector = Connector(*args, **kwargs)
    client = SandBoxClient(static_info)
    connector._client = client
    return connector

This lets you not mess with the public interface for something that will never be used by customers, reducing confusion in the code and making things more readable.

@rhatgadkar-goog
Copy link
Collaborator Author

I still am not sold on this approach being the best one. There are ways to load static info without changes to the public interface. I would highly suggest looking into them more instead of just doing this purely because the Go Connector did it this way.

One example being I don't think it would be much effort to make a SandBoxClient testing object similar to FakeAlloyDBClient that is wired up to always return static connection info.

class FakeAlloyDBClient:

This way you could write a simple private helper method _create_sandbox_connector that would look something like this:

def _create_sandbox_connector(static_info, *args, **kwargs):
    connector = Connector(*args, **kwargs)
    client = SandBoxClient(static_info)
    connector._client = client
    return connector

This lets you not mess with the public interface for something that will never be used by customers, reducing confusion in the code and making things more readable.

We discussed that for now we will keep the current approach of having the static_conn_info as an argument in the public interface. If in the future, we find that there are more dev-only parameters, we can decide to not include dev-only parameters in the public interface and use an approach similar to this.

@rhatgadkar-goog rhatgadkar-goog changed the title feat: support static connection info chore: support static connection info Feb 7, 2025
Copy link
Collaborator

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

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

LGTM ✅

@rhatgadkar-goog rhatgadkar-goog merged commit c6ddd3f into main Feb 11, 2025
15 checks passed
@rhatgadkar-goog rhatgadkar-goog deleted the static-connection-info branch February 11, 2025 20:40
rhatgadkar-goog added a commit that referenced this pull request Jul 19, 2025
#406
added support for static connection info. But
5d9c473
accidentally deleted actually using the static connection info to create
the cache. So re-adding that change in this PR.
rhatgadkar-goog added a commit that referenced this pull request Jul 21, 2025
#406
added support for static connection info. But
5d9c473
accidentally deleted actually using the static connection info to create
the cache. So re-adding that change in this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants