Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Replace aiohttp.ClientSession with AlloyDBAdminAsyncClient #416
base: main
Are you sure you want to change the base?
feat: Replace aiohttp.ClientSession with AlloyDBAdminAsyncClient #416
Changes from all commits
8fdc7d7
72a4814
2bcd203
2d1493a
65e3397
c498957
364c5b1
32cb0b5
edf3372
a3e3bda
a3800ba
9560e2d
4c22d48
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
does this still need to be lazy initialized? This was required for
aiohttp
client to make sure an async event loop was present during initialization. Is the same still needed forAlloyDBAdminAsyncClient
?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.
What do you mean by "lazy initialized"? How is
self._client
being lazy initialized?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.
@rhatgadkar-goog In the Connector initialization, the client is first set to
None
and lazy initialized during the firstconnect
call. Is this still needed for theAlloyDBAdminAsyncClient
?alloydb-python-connector/google/cloud/alloydb/connector/connector.py
Line 125 in 9560e2d
If it is not then you can improve performance of the first connect call by properly initializing client in Connector init.
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.
I don't believe the
AlloyDBAdminAsyncClient
needs to be initialized in an async context. The code snippet here shows that the constructor toAlloyDBAdminAsyncClient
can be called withoutawait
.Why do you think that
aiohttp.ClientSession
needs to be initialized in an async context? TheClientSession
constructor is called withoutawait
here.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.
the
aiohttp.ClientSession
attaches itself to the present event loop. It needs to be initialized after the async entrypoint has been calledconnect_async
forConnector
. Otherwise the client will be attached to a different event loop than the background thread used for refreshes.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.
Oh, I see. Yes, the
aiohttp.ClientSession
constructor is using the current event loop here.But I don't see anything similar to this in the
AlloyDBAdminAsyncClient
constructor.So I'll initialize the client in the Connector init.
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.
We need access to the
driver
. And this is being passed in theconnect()
function.So we can't initialize the
AlloyDBClient
in the connector's constructor unless thedriver
is passed as an argument to the connector's__init()__
function.We could move the
driver
as an argument of the connector's__init__()
function. But this would be a breaking change, right? Because when a customer installs the latest AlloyDB Python connector, their client programs will break, because theconnect()
function won't takedriver
as an argument anymore. And they will need to passdriver
into the__init__()
function now.Is it alright to move
driver
into the__init__()
function? Do we need to somehow communicate this change to customers?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.
We do NOT want to move
driver
into theConnector.__init__
. The whole point of theConnector
class is to share information that is not driver or instance specific. This is more relevant in Cloud SQL as we support more drivers, but for instance, a singleconnector = Connector()
can be used to connect to MySQL, Postgres, and SQL Server drivers viaconnector.connect()
. The same should be true for AlloyDB so that when more drivers are supported in the future, they do not require a newConnector
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.
Ok, I see. For the same argument of not having
driver
inConnector.__init__
, can we also removedriver
fromAlloyDBClient.__init__
? TheAlloyDBClient
isn't instance or driver specific either. To do this, we'll need to make the following changes:AlloyDBClient
class, we can instead pass in ause_metadata
argument into this class's get_connection_info() method.What do you think about this?
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.
aiohttp.ClientSession
has a way to pass in the user agent in the method argument. So we can do something like:Need to check if something similar to this is possible with
AlloyDBAdminAsyncClient