Skip to content

Commit

Permalink
add a fix for broken event (#407)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Barry
<[email protected]>
  • Loading branch information
beliaev-maksim authored Nov 30, 2022
1 parent cb5e800 commit db5cdbe
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/charms/prometheus_k8s/v0/prometheus_remote_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@

import yaml
from charms.observability_libs.v0.juju_topology import JujuTopology
from ops.charm import CharmBase, HookEvent, RelationEvent, RelationMeta, RelationRole
from ops.charm import (
CharmBase,
HookEvent,
RelationBrokenEvent,
RelationEvent,
RelationMeta,
RelationRole,
)
from ops.framework import EventBase, EventSource, Object, ObjectEvents
from ops.model import Relation

Expand Down Expand Up @@ -631,7 +638,7 @@ def __init__(
self.framework.observe(on_relation.relation_joined, self._handle_endpoints_changed)
self.framework.observe(on_relation.relation_changed, self._handle_endpoints_changed)
self.framework.observe(on_relation.relation_departed, self._handle_endpoints_changed)
self.framework.observe(on_relation.relation_broken, self._handle_endpoints_changed)
self.framework.observe(on_relation.relation_broken, self._on_relation_broken)
self.framework.observe(on_relation.relation_joined, self._push_alerts_on_relation_joined)
self.framework.observe(
self._charm.on.leader_elected, self._push_alerts_to_all_relation_databags
Expand All @@ -640,6 +647,9 @@ def __init__(
self._charm.on.upgrade_charm, self._push_alerts_to_all_relation_databags
)

def _on_relation_broken(self, event: RelationBrokenEvent) -> None:
self.on.endpoints_changed.emit(relation_id=event.relation.id)

def _handle_endpoints_changed(self, event: RelationEvent) -> None:
if self._charm.unit.is_leader():
ev = json.loads(event.relation.data[event.app].get("event", "{}"))
Expand Down

0 comments on commit db5cdbe

Please sign in to comment.