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

Migrate to using the charmed-mysql snap #39

Closed
wants to merge 7 commits into from

Conversation

shayancanonical
Copy link
Contributor

dpe-1628

Issue

We are currently using the mysqlrouter installed from an apt package.

Solution

We would like to move to using the charmed-mysql snap

@codecov
Copy link

codecov bot commented Apr 17, 2023

Codecov Report

Merging #39 (13a59c8) into main (577493c) will increase coverage by 0.30%.
The diff coverage is 67.50%.

@@            Coverage Diff             @@
##             main      #39      +/-   ##
==========================================
+ Coverage   57.66%   57.97%   +0.30%     
==========================================
  Files           7        7              
  Lines         437      395      -42     
  Branches      138      113      -25     
==========================================
- Hits          252      229      -23     
+ Misses        185      166      -19     
Impacted Files Coverage Δ
src/charm.py 66.98% <37.50%> (-0.95%) ⬇️
src/mysql_router_helpers.py 68.05% <65.21%> (+3.76%) ⬆️
src/constants.py 100.00% <100.00%> (ø)
src/relations/database_provides.py 39.65% <100.00%> (+0.26%) ⬆️
src/relations/shared_db.py 38.02% <100.00%> (-2.48%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

MYSQL_ROUTER_USER = "mysql"
MYSQL_HOME_DIRECTORY = "/var/lib/mysql"
CHARMED_MYSQL_SNAP = "charmed-mysql"
CHARMED_MYSQL_SNAP_REVISION = 48
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: change revision to latest 8.0/edge revision once charmed mysql snap PR 21 is merged

Comment on lines -142 to -143
"--directory",
f"{MYSQL_HOME_DIRECTORY}/{name}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since there is a 1:1 relation between mysqlrouter and the database (at least in the VM charm), I envisioned multiple mysqlrouter charms deployed to the same machine achieve parallelism using parallel installs with the charmed-mysql snap itself.

However, may be we need --directory to support relations with multiple applications in the k8s charm.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, makes sense!

For the k8s charm I don't think we need multiple instances of mysqlrouter running—if we need to support relations with multiple applications, I think we would still have one instance of mysqlrouter. Does that sound right to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think that that makes sense. I wonder if the --name flag becomes obsolete in that case in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see the use-cases to install 2+ mysql-router as subordinate charms in the same app.
e.g. you have two independent clusters and app need access there.
@shayancanonical I think we discussed this yesterday, did we misunderstand each other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

based on our discussion during the previous database office hours: we will only ever need the mysqlrouter process to connect to one database cluster at a time. however, the application can relate to mysqlrouter multiple times to request different databases in the same database cluster. since the current operator does not correctly support multiple relations with the application, i suggest we leave this PR as is. however, @carlcsaposs-canonical's refactor of the charm will address this concern

to install 2 different mysqlrouter applications as subordinate charms on the same machine, we need to utilize the experimental feature parallel installs for snaps. however, the details there are still murky and hard to project (the changes to the snap charm library in operator-libs-linux are not immediately clear)

@shayancanonical shayancanonical marked this pull request as ready for review April 19, 2023 20:15
src/mysql_router_helpers.py Outdated Show resolved Hide resolved
src/mysql_router_helpers.py Outdated Show resolved Hide resolved
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

LGTM in general, have some questions inside.

Comment on lines -142 to -143
"--directory",
f"{MYSQL_HOME_DIRECTORY}/{name}",
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the use-cases to install 2+ mysql-router as subordinate charms in the same app.
e.g. you have two independent clusters and app need access there.
@shayancanonical I think we discussed this yesterday, did we misunderstand each other?

Comment on lines +121 to +128
replace_socket_location_command = [
"sudo",
"sed",
"-Ei",
f"s:/tmp/(.+).sock:{CHARMED_MYSQL_COMMON_DIRECTORY}/var/run/mysqlrouter/\\1.sock:g",
f"{CHARMED_MYSQL_DATA_DIRECTORY}/etc/mysqlrouter/mysqlrouter.conf",
]
subprocess.run(replace_socket_location_command, check=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

@delgod mysqlrouter --bootstrap doesn't allow to specify socket location.
Should we consider to send improvement PR to the vendor or stay with sed forever?

"sed",
"-Ei",
"s:/tmp/(.+).sock:/var/snap/charmed-mysql/common/var/run/mysqlrouter/\\1.sock:g",
"/var/snap/charmed-mysql/current/etc/mysqlrouter/mysqlrouter.conf",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

General comment: having copy&paste duplicates in test and in charm.py for bootstrap_cmd and replace_socket_location_cmd leads to the human mistakes in the future. Can/should we extract it to the common resource?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that would kinda defeat the point of having a test. Maybe a unit test for this isn't helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, extracting it would defeat the point of having a test. I modified the existing tests so they pass, but the tests will need to be adjusted when carl's refactor is applied to this operator

@carlcsaposs-canonical
Copy link
Contributor

Superseded by #44

@carlcsaposs-canonical carlcsaposs-canonical deleted the feature/charmed_mysql_snap branch June 27, 2023 18:57
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.

4 participants