Skip to content

Commit

Permalink
* scenario test updates
Browse files Browse the repository at this point in the history
* formatting
  • Loading branch information
MichaelThamm committed Jan 13, 2025
1 parent 0b814d4 commit c50043c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/charms/grafana_agent/v0/cos_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/scenario/test_alert_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion tests/scenario/test_cos_agent_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c50043c

Please sign in to comment.