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

Move functions to connect to database servers to a common package #49225

Merged

Conversation

gabrielcorado
Copy link
Contributor

Part of #44956 (RFD 0181)

Context: The PostgreSQL access through WebUI requires us to establish connections to database servers from the web package (not implemented yet). This process is the same as that used by the database proxy server (ProxyServer). Instead of duplicating the logic in those two places, we're moving the common pieces into a shared package that both can use.

This PR moves some functions to generate credentials and connect to database servers and updates the ProxyServer to use them. The new package includes three functions that the proxy server and the PostgreSQL access through WebUI will use:

  • GetDatabaseServers: List database servers that can handle a specific database. (previously getDatabaseServers).
  • GetServerTLSConfig: Generates the tls.Config for connecting to a database server. (previously getConfigForServer).
  • Connect: Connects to a database server based on the provided list. (previously Connect).

Note

Those functions have no feature/behavior changes. They were only moved to a different package. The only changes made are in their parameters and return types. Also, this PR includes additional tests specific for those functions.

@gabrielcorado gabrielcorado added the no-changelog Indicates that a PR does not require a changelog entry label Nov 19, 2024
@github-actions github-actions bot added database-access Database access related issues and PRs size/md labels Nov 19, 2024
@github-actions github-actions bot requested a review from espadolini November 19, 2024 18:53
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-49225.d3pp5qlev8mo18.amplifyapp.com

Copy link
Contributor

@Tener Tener left a comment

Choose a reason for hiding this comment

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

This might be a good moment to drop the shuffleFunc global var, if you feel like it.

@greedy52
Copy link
Contributor

Could you share a draft of how the new lib will be used? IMHO, ProxyServer is responsible for handling the proxying, monitoring, stats reporting, etc so it might be better to implement the "new" proxying logic in ProxyServer for web server to call. But it is hard to tell without seeing the caller.

lib/srv/db/common/srvconnect/srvconnect.go Outdated Show resolved Hide resolved
lib/srv/db/common/srvconnect/srvconnect.go Outdated Show resolved Hide resolved
lib/srv/db/common/srvconnect/srvconnect.go Outdated Show resolved Hide resolved
lib/srv/db/proxyserver.go Outdated Show resolved Hide resolved
lib/srv/db/common/srvconnect/srvconnect.go Outdated Show resolved Hide resolved
@gabrielcorado
Copy link
Contributor Author

@espadolini Friendly ping. Thanks!

Copy link
Contributor

@espadolini espadolini left a comment

Choose a reason for hiding this comment

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

Wouldn't lib/srv/db/connect or lib/srv/db/common/connect (maybe declared or just imported as dbconnect) be better? The name srvconnect doesn't really hint at it containing database access functions, and if you're going to have to read the full package path anyway, you might as well make the package name simpler.

I like how common hints at it being good to use from outside of lib/srv/db although maybe we should start putting things that shouldn't be used from outside of a package tree in internal instead (as that will actually be enforced by the linker).

@gabrielcorado gabrielcorado added this pull request to the merge queue Dec 2, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 2, 2024
@gabrielcorado gabrielcorado added this pull request to the merge queue Dec 2, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 2, 2024
@gabrielcorado gabrielcorado added this pull request to the merge queue Dec 2, 2024
Merged via the queue into master with commit 1a45e8a Dec 2, 2024
41 checks passed
@gabrielcorado gabrielcorado deleted the gabrielcorado/move-shared-db-srvconnect-functions branch December 2, 2024 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database-access Database access related issues and PRs no-changelog Indicates that a PR does not require a changelog entry size/md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants