Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabello committed Feb 6, 2025
1 parent 0f5b0cd commit 4a6a1ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/charms/prometheus_k8s/v1/prometheus_remote_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -495,16 +496,15 @@ 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
)

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."""
Expand Down

0 comments on commit 4a6a1ea

Please # to comment.