From c50043cbdf08c6ce5709780adf6ad2808f6fff3d Mon Sep 17 00:00:00 2001 From: Michael Thamm Date: Mon, 13 Jan 2025 12:29:51 -0500 Subject: [PATCH] * scenario test updates * formatting --- lib/charms/grafana_agent/v0/cos_agent.py | 10 ++++++---- tests/scenario/test_alert_labels.py | 2 +- tests/scenario/test_cos_agent_e2e.py | 11 ++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/charms/grafana_agent/v0/cos_agent.py b/lib/charms/grafana_agent/v0/cos_agent.py index 0c92d2e..d6adcc0 100644 --- a/lib/charms/grafana_agent/v0/cos_agent.py +++ b/lib/charms/grafana_agent/v0/cos_agent.py @@ -759,7 +759,10 @@ def _metrics_alert_rules(self) -> Dict: query_type="promql", topology=JujuTopology.from_charm(self._charm) ) alert_rules.add_path(self._metrics_rules, recursive=self._recursive) - alert_rules.add(GENERIC_ALERT_RULES_GROUP, group_name_prefix=JujuTopology.from_charm(self._charm).identifier) + alert_rules.add( + GENERIC_ALERT_RULES_GROUP, + group_name_prefix=JujuTopology.from_charm(self._charm).identifier, + ) return alert_rules.as_dict() @property @@ -801,7 +804,7 @@ def is_ready(self, relation: Optional[Relation] = None): """Is this endpoint ready?""" relation = relation or self._relation if not relation: - logger.debug(f"no relation on {self._relation_name !r}: tracing not ready") + logger.debug(f"no relation on {self._relation_name!r}: tracing not ready") return False if relation.data is None: logger.error(f"relation data is None for {relation}") @@ -1063,8 +1066,7 @@ def _get_requested_protocols(self, relation: Relation): if len(units) > 1: # should never happen raise ValueError( - f"unexpected error: subordinate relation {relation} " - f"should have exactly one unit" + f"unexpected error: subordinate relation {relation} should have exactly one unit" ) unit = next(iter(units), None) diff --git a/tests/scenario/test_alert_labels.py b/tests/scenario/test_alert_labels.py index bfeda06..c7f436a 100644 --- a/tests/scenario/test_alert_labels.py +++ b/tests/scenario/test_alert_labels.py @@ -120,7 +120,7 @@ def test_metrics_alert_rule_labels(charm_config): ) for group in alert_rules["groups"]: for rule in group["rules"]: - if "grafana-agent_alertgroup_alerts" in group["name"]: + if "grafana_agent_alertgroup_alerts" in group["name"]: assert ( rule["labels"]["juju_application"] == "primary" or rule["labels"]["juju_application"] == "subordinate" diff --git a/tests/scenario/test_cos_agent_e2e.py b/tests/scenario/test_cos_agent_e2e.py index 6639312..47e04cd 100644 --- a/tests/scenario/test_cos_agent_e2e.py +++ b/tests/scenario/test_cos_agent_e2e.py @@ -129,7 +129,16 @@ def test_cos_agent_changed_no_remote_data(provider_ctx): config = json.loads( state_out.get_relation(cos_agent.id).local_unit_data[CosAgentPeersUnitData.KEY] ) - assert config["metrics_alert_rules"] == {} + + # the cos_agent lib injects generic (HostHealth) alert rules and should be filtered for the test + filtered_groups = [ + group + for group in config["metrics_alert_rules"]["groups"] + if "_HostHealth_" not in group["name"] + ] + config["metrics_alert_rules"]["groups"] = filtered_groups + + assert config["metrics_alert_rules"] == {"groups": []} assert config["log_alert_rules"] == {} assert len(config["dashboards"]) == 1 assert len(config["metrics_scrape_jobs"]) == 1