From 082a34cfe383f456e99e100338853611cf77e007 Mon Sep 17 00:00:00 2001 From: Michael Thamm Date: Fri, 20 Dec 2024 12:14:08 -0500 Subject: [PATCH] test: update cosl dep to the branch for testing CI --- lib/charms/prometheus_k8s/v0/prometheus_scrape.py | 2 +- .../prometheus_k8s/v1/prometheus_remote_write.py | 1 + requirements.txt | 2 +- tests/unit/test_endpoint_provider.py | 11 +++++++---- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/charms/prometheus_k8s/v0/prometheus_scrape.py b/lib/charms/prometheus_k8s/v0/prometheus_scrape.py index 80c0236c..e5ebb619 100644 --- a/lib/charms/prometheus_k8s/v0/prometheus_scrape.py +++ b/lib/charms/prometheus_k8s/v0/prometheus_scrape.py @@ -574,7 +574,7 @@ def expand_wildcard_targets_into_individual_jobs( job_name = modified_job.get("job_name", "unnamed-job") + "-" + unit_num modified_job["job_name"] = job_name modified_job["metrics_path"] = unit_path + ( - job.get("metrics_path") or "/metrics" + job.get("metrics_path") or "/metrics" ) if topology: diff --git a/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py b/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py index a216389e..94dd78af 100644 --- a/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py +++ b/lib/charms/prometheus_k8s/v1/prometheus_remote_write.py @@ -82,6 +82,7 @@ ) ) + class RelationNotFoundError(Exception): """Raised if there is no relation with the given name.""" diff --git a/requirements.txt b/requirements.txt index 08a78f21..7fc56b1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -cosl>=0.0.46 +git+https://github.com/canonical/cos-lib.git@feature/generic-alerts#egg=cosl cryptography jsonschema ops diff --git a/tests/unit/test_endpoint_provider.py b/tests/unit/test_endpoint_provider.py index 12651b69..f4d69d4f 100644 --- a/tests/unit/test_endpoint_provider.py +++ b/tests/unit/test_endpoint_provider.py @@ -324,7 +324,7 @@ def test_each_alert_rule_is_topology_labeled(self): self.assertIn("alert_rules", data) alerts = json.loads(data["alert_rules"]) self.assertIn("groups", alerts) - self.assertEqual(len(alerts["groups"]), 6) + self.assertEqual(len(alerts["groups"]), 7) for group in alerts["groups"]: for rule in group["rules"]: if "and_unit" not in group["name"]: @@ -360,7 +360,7 @@ def test_each_alert_expression_is_topology_labeled(self): self.assertIn("alert_rules", data) alerts = json.loads(data["alert_rules"]) self.assertIn("groups", alerts) - self.assertEqual(len(alerts["groups"]), 6) + self.assertEqual(len(alerts["groups"]), 7) group = alerts["groups"][0] for rule in group["rules"]: self.assertIn("expr", rule) @@ -753,10 +753,13 @@ def test_unit_label_is_retained_if_hard_coded(self): # check unit topology is present in labels and in alert rule expression relation = self.harness.charm.model.get_relation("metrics-endpoint") alert_rules = json.loads(relation.data[self.harness.charm.app].get("alert_rules")) + from pprint import pprint + pprint(alert_rules) for group in alert_rules["groups"]: for rule in group["rules"]: - self.assertIn("juju_unit", rule["labels"]) - self.assertIn("juju_unit=", rule["expr"]) + if "_HostHealth_alerts" not in group["name"]: # _HostHealth_alerts are injected alerts without juju_unit labels + self.assertIn("juju_unit", rule["labels"]) + self.assertIn("juju_unit=", rule["expr"]) class TestNoLeader(unittest.TestCase):