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

chore: Extract internal connector registry implementation #1645

Merged
merged 3 commits into from
Oct 30, 2023

Conversation

hessjcg
Copy link
Collaborator

@hessjcg hessjcg commented Oct 25, 2023

Move the connector registry implementation out of CoreSocketFactory and into InternalConnectorRegistry.

CoreSocketFactory is deprecated and contains only the static public methods used informally by other projects.
It delegates to the InternalConnectorRegistry.

@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from 0aebaac to d0a45f8 Compare October 25, 2023 19:32
@hessjcg hessjcg force-pushed the rename-3-ConnectionInfo branch from 3b08337 to 5bad2c6 Compare October 25, 2023 19:32
@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from d0a45f8 to 3f48b01 Compare October 25, 2023 19:34
@hessjcg hessjcg changed the title refactor: rename CoreSocketFactory to CloudSqlConnectorRegistry. chore: rename CoreSocketFactory to CloudSqlConnectorRegistry. Oct 25, 2023
@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from 3f48b01 to ffd79e4 Compare October 25, 2023 20:00
@hessjcg hessjcg force-pushed the rename-3-ConnectionInfo branch from 5bad2c6 to dce5da6 Compare October 25, 2023 20:00
@hessjcg hessjcg force-pushed the rename-3-ConnectionInfo branch from dce5da6 to 44fa854 Compare October 25, 2023 20:15
@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from ffd79e4 to d96b84d Compare October 25, 2023 20:23
Base automatically changed from rename-3-ConnectionInfo to main October 25, 2023 20:56
@github-actions github-actions bot removed the size: l label Oct 25, 2023
@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from d96b84d to e1064d0 Compare October 25, 2023 21:05
@hessjcg hessjcg marked this pull request as ready for review October 25, 2023 21:05
@hessjcg hessjcg requested a review from a team as a code owner October 25, 2023 21:05
Copy link
Collaborator

@ttosta-google ttosta-google left a comment

Choose a reason for hiding this comment

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

LGTM

@enocom enocom self-requested a review October 26, 2023 21:41
Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

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

Let's frame this as "extract internal-only registry" as we're leaving CoreSocketFactory in place.

* Factory responsible for obtaining an ephemeral certificate, if necessary, and establishing a
* secure connecting to a Cloud SQL instance.
*
* <p>This class should not be used directly, but only through the JDBC driver specific {@code
Copy link
Member

Choose a reason for hiding this comment

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

Let's make it crystal clear: "Internal class made public for module usage only. This is not part of the official public API and should not be used directly." Or something similar.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps with a "WARNING" or similar call-out to lead in.

Copy link
Member

Choose a reason for hiding this comment

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

@hessjcg let's add some more warnings to the doc string.

}

/** Returns the {@link CloudSqlConnectorRegistry} singleton. */
public static synchronized CloudSqlConnectorRegistry getInstance() {
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be public? I know we're going to turn this into an enum as we have in AlloyDB, but shall we keep the API surface as small as possible during that refactor?

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 needs to be public so that it can be accessed by com.google.cloud.sql.ConnectorRegistry, which is in a different package. We can look into restricting external access to the core package using Java Modules some day.

Copy link
Member

Choose a reason for hiding this comment

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

OK that's fine. Let's make it clear that this is a "private" method in that case with a similar warning.

*
* @throws IllegalStateException if the SQLAdmin client has already been initialized
*/
public static void setApplicationName(String applicationName) {
Copy link
Member

Choose a reason for hiding this comment

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

What shall we do about this? I forget what the plan here was.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're going to deprecate this method in favor of ConnectorRegistry.addApplicationId(String id).

@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from e1064d0 to 37b59c7 Compare October 27, 2023 20:35
@hessjcg hessjcg changed the title chore: rename CoreSocketFactory to CloudSqlConnectorRegistry. chore: rename CoreSocketFactory to InternalConnectorRegistry. Oct 27, 2023
@hessjcg hessjcg changed the title chore: rename CoreSocketFactory to InternalConnectorRegistry. chore: Extract internal connector registry implementation from CoreSocketFactory. Oct 27, 2023
@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from 37b59c7 to b31f67d Compare October 27, 2023 21:09
@hessjcg hessjcg requested a review from enocom October 27, 2023 21:19
Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

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

LGTM

I'd like to see some serious warnings around our public methods on the InternalConnectorRegistry before we merge this.

@hessjcg
Copy link
Collaborator Author

hessjcg commented Oct 30, 2023

I'd like to see some serious warnings around our public methods on the InternalConnectorRegistry before we merge this.

I added warnings in a few places about internal classes.

@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from 8e155fc to a5d2892 Compare October 30, 2023 19:27
@enocom enocom changed the title chore: Extract internal connector registry implementation from CoreSocketFactory. chore: Extract internal connector registry implementation Oct 30, 2023
* SocketFactory} implementations.
*
* <p>The API of this class is subject to change without notice.
* @deprecated This will soon be replaced.
Copy link
Member

Choose a reason for hiding this comment

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

Replaced with what? Can we be more specific so if someone sees this they'll know what to look for and do instead?

HttpRequestInitializer credential = instanceCredentialFactory.create();
DefaultConnectionInfoRepository adminApi =
connectionInfoRepositoryFactory.create(credential, config);
@Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention what people should do instead?


/**
* Factory responsible for obtaining an ephemeral certificate, if necessary, and establishing a
* secure connecting to a Cloud SQL instance.
* WARNING: This class is not a stable, public Java API. The class definition may change without
Copy link
Member

Choose a reason for hiding this comment

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

I think we put this in the wrong place -- this needs to be on the InternalConnectorRegistry.

The bit about compatibility should stay.

import jnr.unixsocket.UnixSocketChannel;

/**
* Factory responsible for obtaining an ephemeral certificate, if necessary, and establishing a
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a factory. It's a holder of registered connectors. All the connection related code will move into a Connector in future commits.

* change without notice.
*
* <p>Package com.google.cloud.sql.core holds internal shared packages that implement logic to
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a note about com.google.cloud.sql as holding all the public API.

@hessjcg hessjcg enabled auto-merge (squash) October 30, 2023 20:47
@hessjcg hessjcg force-pushed the rename-4-CoreSocketFactory branch from ff6cf84 to 24bde1a Compare October 30, 2023 20:47
@hessjcg hessjcg merged commit af37fb3 into main Oct 30, 2023
@hessjcg hessjcg deleted the rename-4-CoreSocketFactory branch October 30, 2023 21:03
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.

3 participants