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

fix: db connection string lifecycle issues #45

Merged
merged 8 commits into from
Oct 17, 2024

Conversation

matthew-hagemann
Copy link
Collaborator

@matthew-hagemann matthew-hagemann commented Oct 16, 2024

Fixes #37, #42

The underlying issue is that at times, the charm loses state and reverts to original configuration values. When this happens, we were losing the connection string, as the _waiting_for_database_relation flag and the _env_vars we pass into the container were being reset.

This change now has __init__ check for existing db relations, and if one is found, skip setting the _waiting_for_database_relation flag and go straight to setting up and passing in the connection string.

I also added steps to the lifecycle tests that cold boot the charm and swap out ports while connected to the db to ensure we return to a running state and can reach the container.

In the future I want to rework this to trigger on supplying a db_name as config, but until we need to support metrics, I think we can kick the can down the road.

@canonical canonical deleted a comment from codecov bot Oct 17, 2024
@matthew-hagemann matthew-hagemann changed the title Db fix fix: db connection string lifecycle issues Oct 17, 2024
@matthew-hagemann matthew-hagemann merged commit 3b92fa9 into canonical:main Oct 17, 2024
5 checks passed
@matthew-hagemann matthew-hagemann deleted the db-fix branch October 17, 2024 09:44
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 81.65%. Comparing base (8e02275) to head (d7ac42a).
Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
src/charm.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
- Coverage   84.47%   81.65%   -2.82%     
==========================================
  Files           2        2              
  Lines         322      338      +16     
  Branches       25       26       +1     
==========================================
+ Hits          272      276       +4     
- Misses         43       53      +10     
- Partials        7        9       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

bug: updating ports ends with the charm stuck in state "waiting for db relation"
2 participants