Skip to content

refactor tsh db#26182

Merged
GavinFrazar merged 1 commit intomasterfrom
gavinfrazar/refactor-tsh-db-fetching
May 19, 2023
Merged

refactor tsh db#26182
GavinFrazar merged 1 commit intomasterfrom
gavinfrazar/refactor-tsh-db-fetching

Conversation

@GavinFrazar
Copy link
Copy Markdown
Contributor

This PR is a precursor to another PR for #22717 that I factored out.

The purpose of this PR is to simplify database info retrieval in tsh db connect/proxy/login and avoid fetching the same database more than once from the remote proxy.

Motivation: I found myself having to add yet another place in the code that needed to check if a passed-in types.Database is nil or fetch it, but since it was passed down, there was no good way to pass the types.Database back up without making a mess, and I wanted to avoid fetching the database multiple times (each fetch incurring a remote proxy dial and API call). Hence: this PR.

The getDatabaseInfo function in particular was the main source of the problem before, because it did not guarantee returning a non-nill types.Database, so the code had to carefully check that it was non-nil or fetch it wherever that database was passed to.

Instead, I created a wrapper type around tlsca.RouteToDatabase and types.Database that will only fetch the database for the route when needed, and saves the result so that we only ever dial the proxy once for it. Most of the PR is just renaming and plumbing that wrapper around.

Stacked this PR on top of another PR for a minor bugfix: #26181

@github-actions github-actions Bot requested review from hugoShaka and ravicious May 13, 2023 05:00
@github-actions github-actions Bot added size/sm tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels May 13, 2023
@GavinFrazar GavinFrazar added ux database-access Database access related issues and PRs labels May 13, 2023
Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

Good cleanup! 👍 I ran tsh db connect and tsh proxy db in a couple of variations to confirm that they still work as expected.

Comment thread tool/tsh/db.go Outdated
Comment thread lib/client/db/dbcmd/dbcmd.go Outdated
Comment thread tool/tsh/db.go Outdated
@smallinsky smallinsky self-requested a review May 16, 2023 17:29
Base automatically changed from gavinfrazar/fix-tsh-db-connect-cassandra to master May 16, 2023 17:36
Comment thread tool/tsh/db.go Outdated
Comment thread tool/tsh/db.go Outdated
@GavinFrazar
Copy link
Copy Markdown
Contributor Author

@hugoShaka needs group 2 approval, could you take a look?

* simplify and consolidate db info retrieval
* avoid fetching the same database multiple times
* simplify tsh db connect local proxy requirements
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/refactor-tsh-db-fetching branch from 816c4c8 to 1464720 Compare May 19, 2023 21:20
@GavinFrazar GavinFrazar enabled auto-merge May 19, 2023 21:22
@GavinFrazar GavinFrazar added this pull request to the merge queue May 19, 2023
Merged via the queue into master with commit dbb2aaf May 19, 2023
@GavinFrazar GavinFrazar deleted the gavinfrazar/refactor-tsh-db-fetching branch May 19, 2023 21:57
GavinFrazar added a commit that referenced this pull request May 20, 2023
backports #26182 to branch/v13.

* simplify and consolidate db info retrieval
* avoid fetching the same database multiple times
* simplify tsh db connect local proxy requirements
GavinFrazar added a commit that referenced this pull request May 20, 2023
backport #26182 to branch/v12.
GavinFrazar added a commit that referenced this pull request May 22, 2023
backports #26182 to branch/v13.

* simplify and consolidate db info retrieval
* avoid fetching the same database multiple times
* simplify tsh db connect local proxy requirements
GavinFrazar added a commit that referenced this pull request May 22, 2023
backport #26182 to branch/v12.
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 size/sm tsh tsh - Teleport's command line tool for logging into nodes running Teleport. ux

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants