Skip to content

Commit

Permalink
DPE-2352 Restart mysql exporter upon monitoring password change (#285)
Browse files Browse the repository at this point in the history
* Restart mysql exporter upon monitoring password change

* Add restart_mysql_exporter as an abstract method on MySQLBase
  • Loading branch information
shayancanonical authored Aug 10, 2023
1 parent c6c906a commit c196fde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/charms/mysql/v0/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def wait_until_mysql_connection(self) -> None:
BACKUPS_USERNAME,
CLUSTER_ADMIN_PASSWORD_KEY,
CLUSTER_ADMIN_USERNAME,
COS_AGENT_RELATION_NAME,
MONITORING_PASSWORD_KEY,
MONITORING_USERNAME,
PASSWORD_LENGTH,
Expand All @@ -110,7 +111,7 @@ 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 = 38
LIBPATCH = 39

UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
UNIT_ADD_LOCKNAME = "unit-add"
Expand Down Expand Up @@ -404,6 +405,12 @@ def _on_set_password(self, event: ActionEvent) -> None:

self.set_secret("app", secret_key, new_password)

if (
username == MONITORING_USERNAME
and len(self.model.relations.get(COS_AGENT_RELATION_NAME, [])) > 0
):
self._mysql.restart_mysql_exporter()

def _get_cluster_status(self, event: ActionEvent) -> None:
"""Action used to retrieve the cluster status."""
if status := self._mysql.get_cluster_status():
Expand Down Expand Up @@ -2295,6 +2302,11 @@ def start_mysqld(self) -> None:
"""Starts the mysqld process."""
raise NotImplementedError

@abstractmethod
def restart_mysql_exporter(self) -> None:
"""Restart the mysqld exporter."""
raise NotImplementedError

@abstractmethod
def wait_until_mysql_connection(self) -> None:
"""Wait until a connection to MySQL has been obtained.
Expand Down
5 changes: 5 additions & 0 deletions src/mysql_vm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ def stop_mysql_exporter(self) -> None:
logger.exception("An exception occurred when stopping mysqld-exporter")
raise MySQLExporterConnectError("Error stopping mysqld-exporter")

def restart_mysql_exporter(self) -> None:
"""Restart the mysqld exporter."""
self._stop_mysql_exporter()
self._connect_mysql_exporter()

def _run_mysqlsh_script(self, script: str, timeout=None) -> str:
"""Execute a MySQL shell script.
Expand Down

0 comments on commit c196fde

Please sign in to comment.