Skip to content

Commit

Permalink
Move Stats to Synapse Pebble Ready handler
Browse files Browse the repository at this point in the history
  • Loading branch information
amandahla committed Jan 23, 2024
1 parent 8d71436 commit f229210
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def __init__(self, *args: typing.Any) -> None:
self.on.promote_user_admin_action, self._on_promote_user_admin_action
)
self.framework.observe(self.on.anonymize_user_action, self._on_anonymize_user_action)
self.framework.observe(self.on.start, self._on_start)

def change_config(self) -> None:
"""Change configuration."""
Expand Down Expand Up @@ -170,19 +169,6 @@ def _on_config_changed(self, _: ops.HookEvent) -> None:
self.change_config()
self._set_workload_version()

def _on_synapse_pebble_ready(self, _: ops.HookEvent) -> None:
"""Handle synapse pebble ready event."""
self.change_config()

def _on_synapse_nginx_pebble_ready(self, _: ops.HookEvent) -> None:
"""Handle synapse nginx pebble ready event."""
container = self.unit.get_container(synapse.SYNAPSE_NGINX_CONTAINER_NAME)
if not container.can_connect():
self.unit.status = ops.MaintenanceStatus("Waiting for Synapse NGINX pebble")
return
self.pebble_service.replan_nginx(container)
self._set_unit_status()

def _get_peer_relation(self) -> typing.Optional[ops.Relation]:
"""Get peer relation.
Expand Down Expand Up @@ -251,8 +237,9 @@ def _set_admin_access_token(self, access_token: str) -> None:
logger.debug("Adding peer data")
peer_relation.data[self.app].update({SECRET_KEY: access_token})

def _on_start(self, _: ops.HookEvent) -> None:
"""Handle start event."""
def _on_synapse_pebble_ready(self, _: ops.HookEvent) -> None:
"""Handle synapse pebble ready event."""
self.change_config()
if self.get_admin_access_token():
self._start_synapse_stats_exporter()
return
Expand All @@ -270,6 +257,15 @@ def _on_start(self, _: ops.HookEvent) -> None:
# Stats exporter needs access token so the charm will start it here
self._start_synapse_stats_exporter()

def _on_synapse_nginx_pebble_ready(self, _: ops.HookEvent) -> None:
"""Handle synapse nginx pebble ready event."""
container = self.unit.get_container(synapse.SYNAPSE_NGINX_CONTAINER_NAME)
if not container.can_connect():
self.unit.status = ops.MaintenanceStatus("Waiting for Synapse NGINX pebble")
return
self.pebble_service.replan_nginx(container)
self._set_unit_status()

def _on_reset_instance_action(self, event: ActionEvent) -> None:
"""Reset instance and report action result.
Expand Down

0 comments on commit f229210

Please sign in to comment.