From c196fde9896b4d379f3e17f065679db8fd835477 Mon Sep 17 00:00:00 2001 From: shayancanonical <99665202+shayancanonical@users.noreply.github.com> Date: Thu, 10 Aug 2023 07:52:45 -0400 Subject: [PATCH] DPE-2352 Restart mysql exporter upon monitoring password change (#285) * Restart mysql exporter upon monitoring password change * Add restart_mysql_exporter as an abstract method on MySQLBase --- lib/charms/mysql/v0/mysql.py | 14 +++++++++++++- src/mysql_vm_helpers.py | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/charms/mysql/v0/mysql.py b/lib/charms/mysql/v0/mysql.py index ebbd23640..d6711e486 100644 --- a/lib/charms/mysql/v0/mysql.py +++ b/lib/charms/mysql/v0/mysql.py @@ -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, @@ -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" @@ -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(): @@ -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. diff --git a/src/mysql_vm_helpers.py b/src/mysql_vm_helpers.py index 16c37755f..d4e1caacb 100644 --- a/src/mysql_vm_helpers.py +++ b/src/mysql_vm_helpers.py @@ -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.