diff --git a/lib/charms/prometheus_k8s/v0/prometheus_scrape.py b/lib/charms/prometheus_k8s/v0/prometheus_scrape.py index b277c751..d93f2ca1 100644 --- a/lib/charms/prometheus_k8s/v0/prometheus_scrape.py +++ b/lib/charms/prometheus_k8s/v0/prometheus_scrape.py @@ -1413,7 +1413,7 @@ def __init__( files. Defaults to "./prometheus_alert_rules", resolved relative to the directory hosting the charm entry file. The alert rules are automatically updated on charm upgrade. - forward_alert_rules: a boolean flag to toggle forwarding alert rules. + forward_alert_rules: a boolean flag to toggle forwarding of charmed alert rules. refresh_event: an optional bound event or list of bound events which will be observed to re-set scrape job data (IP address and others) external_url: an optional argument that represents an external url that @@ -1452,7 +1452,7 @@ def __init__( self._charm = charm self._alert_rules_path = alert_rules_path - self._enable_alerts = forward_alert_rules + self._forward_alert_rules = forward_alert_rules self._relation_name = relation_name # sanitize job configurations to the supported subset of parameters jobs = [] if jobs is None else jobs @@ -1534,7 +1534,7 @@ def set_scrape_job_spec(self, _=None): return alert_rules = AlertRules(query_type="promql", topology=self.topology) - if self._enable_alerts: + if self._forward_alert_rules: alert_rules.add_path(self._alert_rules_path, recursive=True) alert_rules.add( generic_alert_groups.application_rules, group_name_prefix=self.topology.identifier diff --git a/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py b/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py index 2964fadd..d86232db 100644 --- a/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py +++ b/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py @@ -402,6 +402,7 @@ def __init__( relation_name: str = DEFAULT_CONSUMER_NAME, alert_rules_path: str = DEFAULT_ALERT_RULES_RELATIVE_PATH, refresh_event: Optional[Union[BoundEvent, List[BoundEvent]]] = None, + *, forward_alert_rules: bool = True, ): """API to manage a required relation with the `prometheus_remote_write` interface. @@ -413,7 +414,7 @@ def __init__( alert_rules_path: Path of the directory containing the alert rules. refresh_event: an optional bound event or list of bound events which will be observed to re-set alerts data. - forward_alert_rules: Flag to toggle alert rule forwarding. + forward_alert_rules: Flag to toggle forwarding of charmed alert rules. Raises: RelationNotFoundError: If there is no relation in the charm's metadata.yaml @@ -442,7 +443,7 @@ def __init__( self._charm = charm self._relation_name = relation_name self._alert_rules_path = alert_rules_path - self._enable_alerts = forward_alert_rules + self._forward_alert_rules = forward_alert_rules self.topology = JujuTopology.from_charm(charm) @@ -495,7 +496,7 @@ def _push_alerts_to_relation_databag(self, relation: Relation) -> None: return alert_rules = AlertRules(query_type="promql", topology=self.topology) - if self._enable_alerts: + if self._forward_alert_rules: alert_rules.add_path(self._alert_rules_path) alert_rules.add( generic_alert_groups.aggregator_rules, group_name_prefix=self.topology.identifier @@ -503,8 +504,7 @@ def _push_alerts_to_relation_databag(self, relation: Relation) -> None: alert_rules_as_dict = alert_rules.as_dict() - if alert_rules_as_dict or not self._enable_alerts: - relation.data[self._charm.app]["alert_rules"] = json.dumps(alert_rules_as_dict) + relation.data[self._charm.app]["alert_rules"] = json.dumps(alert_rules_as_dict) def reload_alerts(self) -> None: """Reload alert rules from disk and push to relation data."""