Skip to content

Commit

Permalink
Only insert labels that do not already exist (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
sed-i authored Feb 26, 2024
1 parent 490e5e4 commit 97db0a3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/charms/loki_k8s/v1/loki_push_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def _alert_rules_error(self, event):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 3
LIBPATCH = 4

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -799,7 +799,11 @@ def _from_file(self, root_path: Path, file_path: Path) -> List[dict]:
alert_rule["labels"] = {}

if self.topology:
alert_rule["labels"].update(self.topology.label_matcher_dict)
# only insert labels that do not already exist
for label, val in self.topology.label_matcher_dict.items():
if label not in alert_rule["labels"]:
alert_rule["labels"][label] = val

# insert juju topology filters into a prometheus alert rule
# logql doesn't like empty matchers, so add a job matcher which hits
# any string as a "wildcard" which the topology labels will
Expand Down

0 comments on commit 97db0a3

Please sign in to comment.