Skip to content

Add retry for DB connection#208

Merged
zhouzhuojie merged 1 commit into
masterfrom
zz/add-db-connection-retry
Jan 30, 2019
Merged

Add retry for DB connection#208
zhouzhuojie merged 1 commit into
masterfrom
zz/add-db-connection-retry

Conversation

@zhouzhuojie
Copy link
Copy Markdown
Collaborator

Description

Fix #207

Motivation and Context

Add retries so that the DB connection is more reliable when we start the flagr server.

How Has This Been Tested?

Test locally with sqlite3. Will go through integration tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 30, 2019

Codecov Report

Merging #208 into master will increase coverage by 0.59%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
+ Coverage   86.14%   86.73%   +0.59%     
==========================================
  Files          23       23              
  Lines        1335     1342       +7     
==========================================
+ Hits         1150     1164      +14     
+ Misses        135      127       -8     
- Partials       50       51       +1
Impacted Files Coverage Δ
pkg/entity/db.go 76.47% <100%> (+32.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a7397a...30100e0. Read the comment docs.

Comment thread pkg/entity/db.go
return err
},
retry.Attempts(config.Config.DBConnectionRetryAttempts),
retry.Delay(config.Config.DBConnectionRetryDelay),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome. By default 10 retries gives us 25.5 seconds of reconnect time. If we change the default attempts to 9, our retry time comes down to 12.7 seconds. That seems more like a happy medium between long enough and not too long to me. What do you think?

@zhouzhuojie zhouzhuojie requested review from michberr and ziru January 30, 2019 01:49
Comment thread pkg/config/env.go
// DBConnectionDebug controls whether to show the database connection debugging logs
// warning: it may log the credentials to the stdout
DBConnectionDebug bool `env:"FLAGR_DB_DBCONNECTION_DEBUG" envDefault:"true"`
// DBConnectionRetryAttempts controls how we are going to retry on db connection when start the flagr server
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

a note to myself, we probably need to document in the env.go, what are the minimal env variables do we need for a new setup.

Copy link
Copy Markdown
Contributor

@crberube crberube left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks for looking into this so quickly. Only thing I noticed is that the retry-go package was never added to the Gopkg.toml file — I believe it should be there. Retry-go has has a few breaking changes through major releases, so it would be good to protect against that.

Comment thread pkg/entity/db.go
return err
},
retry.Attempts(config.Config.DBConnectionRetryAttempts),
retry.Delay(config.Config.DBConnectionRetryDelay),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome. By default 10 retries gives us 25.5 seconds of reconnect time. If we change the default attempts to 9, our retry time comes down to 12.7 seconds. That seems more like a happy medium between long enough and not too long to me. What do you think?

@zhouzhuojie zhouzhuojie force-pushed the zz/add-db-connection-retry branch from 19aada2 to 71cb04a Compare January 30, 2019 19:17
@zhouzhuojie zhouzhuojie force-pushed the zz/add-db-connection-retry branch from 71cb04a to 30100e0 Compare January 30, 2019 19:36
@zhouzhuojie zhouzhuojie merged commit 4cc964b into master Jan 30, 2019
@zhouzhuojie zhouzhuojie deleted the zz/add-db-connection-retry branch January 30, 2019 19:40
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.

Retry DB Connections

3 participants