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

DPE-2654 profile-limits option #331

Merged
merged 19 commits into from
Oct 13, 2023
Merged

Conversation

paulomach
Copy link
Contributor

@paulomach paulomach commented Sep 28, 2023

Issue

  • main issue: no fine tune for memory allocation
  • configurations are being set without validation
  • configurations changes are not triggering changes in the workload

Solution

  • Add profile-limit-memory config option
  • Usage of data platform data-models lib for config validation
  • Usage of rollingOps lib for workload restart orchestration, when the changed configs requires.
    • Add a method to defer primary to be last one to restart (mitigating primary switchover)

Chore

  • refactored get_available_memory to be simpler
  • charm typing for relations/mysql.py
  • typo fix
  • usage of config values as properties, provided by data-models lib

@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

Merging #331 (ea0ecb9) into main (ef2d363) will increase coverage by 0.48%.
The diff coverage is 69.53%.

@@            Coverage Diff             @@
##             main     #331      +/-   ##
==========================================
+ Coverage   64.01%   64.50%   +0.48%     
==========================================
  Files          16       17       +1     
  Lines        2993     3113     +120     
  Branches      389      413      +24     
==========================================
+ Hits         1916     2008      +92     
- Misses        955      979      +24     
- Partials      122      126       +4     
Files Coverage Δ
src/constants.py 100.00% <100.00%> (ø)
src/utils.py 100.00% <100.00%> (ø)
lib/charms/mysql/v0/mysql.py 73.22% <78.57%> (+0.47%) ⬆️
src/relations/mysql.py 53.44% <33.33%> (+0.86%) ⬆️
src/mysql_vm_helpers.py 60.99% <64.70%> (-0.74%) ⬇️
src/config.py 85.45% <85.45%> (ø)
src/charm.py 50.78% <50.98%> (-1.14%) ⬇️

... and 2 files with indirect coverage changes

dpe-2654-profile-limit-option

# Conflicts:
#	lib/charms/mysql/v0/mysql.py
#	src/charm.py
#	src/mysql_vm_helpers.py
@paulomach paulomach marked this pull request as ready for review September 29, 2023 21:13
taurus-forever
taurus-forever previously approved these changes Oct 10, 2023
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.

Nice. The new code it way more pleasant to read!
One question inside, and I hope the answer there is "no", so LGTM.

self.app_peer_data.setdefault(
"cluster-name", self.config.cluster_name or f"cluster-{common_hash}"
)
self.app_peer_data.setdefault("cluster-set-domain-name", f"cluster-set-{common_hash}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: will we overwrite cluster-name and cluster-set-domain-name on the leader move (re-elected)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by using setdefault we avoid overwriting it

Comment on lines +1152 to +1156

# escape variable values when needed
if not re.match(r"^[0-9,a-z,A-Z$_]+$", value):
value = f"`{value}`"

Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to always escape?

Copy link
Contributor

Choose a reason for hiding this comment

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

also do you need to check that

`

is not in the string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really: 096fe7f

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, we cannot escape always - number will fail. rolledback on ea0ecb9

self._mysql.write_content_to_file(
path=MYSQLD_CUSTOM_CONFIG_FILE, content=new_config_content
)
self.on[f"{self.restart.name}"].acquire_lock.emit()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.on[f"{self.restart.name}"].acquire_lock.emit()
self.on[self.restart.name].acquire_lock.emit()

nit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's like that to shut the linter - self.restart.name is typed ad AnyStr and key should be str

Copy link
Contributor

Choose a reason for hiding this comment

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

suggest str() instead of f-string

src/config.py Show resolved Hide resolved
tests/integration/helpers.py Show resolved Hide resolved
src/charm.py Outdated
# the upgrade already restart the daemon
return

if not self._mysql.is_mysqld_running:
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 not a property. should we add () to invoke the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -116,15 +116,17 @@ def wait_until_mysql_connection(self) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 49
LIBPATCH = 50
Copy link
Contributor

Choose a reason for hiding this comment

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

please update to 51 as another PR was merged with libpatch 50

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -773,8 +762,18 @@ def _join_unit_to_cluster(self) -> None:
self.unit.status = WaitingStatus("waiting to join the cluster")
logger.debug("Waiting to joing the cluster, failed to acquire lock.")

def _restart(self, _: EventBase) -> None:
def _restart(self, event: EventBase) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: not all events that isinstance EventBase can be deferred

@paulomach
Copy link
Contributor Author

merging besides the CI error - test passed previously, failing due disk full error. Deal with it on another PR

@paulomach paulomach merged commit 1f72f1b into main Oct 13, 2023
@paulomach paulomach deleted the feature/dpe-2654-profile-limit-option branch October 13, 2023 18:42
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