diff --git a/lib/charms/prometheus_k8s/v0/prometheus_scrape.py b/lib/charms/prometheus_k8s/v0/prometheus_scrape.py index 07b67f05..6bb9f3cf 100644 --- a/lib/charms/prometheus_k8s/v0/prometheus_scrape.py +++ b/lib/charms/prometheus_k8s/v0/prometheus_scrape.py @@ -1505,7 +1505,7 @@ def __init__( for event_source in event_sources: self.framework.observe(event_source, self._update_relation_data) - def reload_alert_rules(self): + def _reinitialize_alert_rules(self): """Reloads alert rules and updates all relations.""" self._update_relation_data(None) diff --git a/tests/unit/test_prometheus_rules_provider.py b/tests/unit/test_prometheus_rules_provider.py index 45da8061..1765c2c2 100644 --- a/tests/unit/test_prometheus_rules_provider.py +++ b/tests/unit/test_prometheus_rules_provider.py @@ -66,7 +66,7 @@ def test_reload_when_dir_is_still_empty_changes_nothing(self): # WHEN no rule files are present # AND the reload method is called - self.harness.charm.rules_provider.reload_alert_rules() + self.harness.charm.rules_provider._reinitialize_alert_rules() # THEN relation data is unchanged relation = self.harness.charm.model.get_relation("metrics-endpoint") @@ -82,7 +82,7 @@ def test_reload_after_dir_is_populated_updates_relation_data(self): self.sandbox.put_file(os.path.join(self.alert_rules_path, "alert.rule"), self.ALERT) # AND the reload method is called - self.harness.charm.rules_provider.reload_alert_rules() + self.harness.charm.rules_provider._reinitialize_alert_rules() # THEN relation data is updated relation = self.harness.charm.model.get_relation("metrics-endpoint") @@ -95,13 +95,13 @@ def test_reload_after_dir_is_emptied_updates_relation_data(self): # GIVEN alert files are present and relation data contains respective alerts alert_filename = os.path.join(self.alert_rules_path, "alert.rule") self.sandbox.put_file(alert_filename, self.ALERT) - self.harness.charm.rules_provider.reload_alert_rules() + self.harness.charm.rules_provider._reinitialize_alert_rules() # WHEN all rule files are deleted from the alerts dir self.sandbox.remove(alert_filename) # AND the reload method is called - self.harness.charm.rules_provider.reload_alert_rules() + self.harness.charm.rules_provider._reinitialize_alert_rules() # THEN relation data is empty again relation = self.harness.charm.model.get_relation("metrics-endpoint") @@ -112,14 +112,14 @@ def test_reload_after_dir_itself_removed_updates_relation_data(self): # GIVEN alert files are present and relation data contains respective alerts alert_filename = os.path.join(self.alert_rules_path, "alert.rule") self.sandbox.put_file(alert_filename, self.ALERT) - self.harness.charm.rules_provider.reload_alert_rules() + self.harness.charm.rules_provider._reinitialize_alert_rules() # WHEN the alerts dir itself is deleted self.sandbox.remove(alert_filename) self.sandbox.rmdir(self.alert_rules_path) # AND the reload method is called - self.harness.charm.rules_provider.reload_alert_rules() + self.harness.charm.rules_provider._reinitialize_alert_rules() # THEN relation data is empty again relation = self.harness.charm.model.get_relation("metrics-endpoint")