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: only connect to the database once #9456

Merged
merged 5 commits into from
May 31, 2024
Merged

Conversation

NicholasBlaskey
Copy link
Contributor

@NicholasBlaskey NicholasBlaskey commented May 30, 2024

Ticket

Description

Fix flake here https://app.circleci.com/pipelines/github/determined-ai/determined/56315/workflows/f5c22283-01d5-4543-a12b-8b5d42fff926/jobs/2624963

by connecting the to the database once, where retries correctly happen

Test Plan

ci passes

Checklist

  • Changes have been manually QA'd
  • User-facing API changes need the "User-facing API Change" label.
  • Release notes should be added as a separate file under docs/release-notes/.
    See Release Note for details.
  • Licenses should be included for new code which was copied and/or modified from any external code.

@NicholasBlaskey NicholasBlaskey requested a review from a team as a code owner May 30, 2024 20:37
@cla-bot cla-bot bot added the cla-signed label May 30, 2024
Copy link

netlify bot commented May 30, 2024

Deploy Preview for determined-ui canceled.

Name Link
🔨 Latest commit 55b2a6b
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/6658e8585294f200085a1a26

Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 61.11111% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 48.58%. Comparing base (cc4ad2b) to head (55b2a6b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9456   +/-   ##
=======================================
  Coverage   48.57%   48.58%           
=======================================
  Files        1233     1233           
  Lines      159168   159158   -10     
  Branches     2777     2777           
=======================================
+ Hits        77312    77322   +10     
+ Misses      81682    81662   -20     
  Partials      174      174           
Flag Coverage Δ
backend 42.17% <61.11%> (+0.02%) ⬆️
harness 64.08% <ø> (ø)
web 44.29% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
master/internal/core.go 6.47% <78.57%> (+0.88%) ⬆️
master/internal/db/setup.go 43.63% <0.00%> (+9.83%) ⬆️

... and 2 files with indirect coverage changes

func databaseIsFresh() (bool, error) {
fresh, err := Bun().NewSelect().Table("pg_tables").
Where("schemaname = ?", "public").
Where("tablename = ?", "gopg_migrations").
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why this is being done dynamically? Do we plan to parameterize this query?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched to just using tablename = "gopg..."

master/internal/db/setup.go Outdated Show resolved Hide resolved
}
if !exist["gopg_migrations"] {
return true, nil
return db, false, err
Copy link
Contributor

Choose a reason for hiding this comment

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

nit (non-blocking): is there a benefit to returning the db pointer if an error occurs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope that was a mistake, should return nil


exist, err := tablesExist(pgConn, []string{"gopg_migrations", "schema_migrations"})
// Setup connects to the database and run any necessary migrations.
// Takes a list of checks that run after the database is connected on new databases.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a brilliant solution!

@NicholasBlaskey NicholasBlaskey merged commit d960f29 into main May 31, 2024
83 of 97 checks passed
@NicholasBlaskey NicholasBlaskey deleted the fix_db_not_retrying branch May 31, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants