Skip to content

Commit

Permalink
fix: Check exporter installed before healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
dashmage committed Mar 21, 2024
1 parent 7523866 commit 8f934bb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _on_install_or_upgrade(self, event: ops.InstallEvent) -> None:
logger.error(msg)
self.model.unit.status = BlockedStatus(msg)
return
logger.info("Successfully installed exporter")
self._on_update_status(event)

def _on_remove(self, _: EventBase) -> None:
Expand All @@ -124,6 +125,11 @@ def _on_update_status(self, _: EventBase) -> None: # noqa: C901
# The charm should be in BlockedStatus with install failed msg
return # type: ignore[unreachable]

config_valid, config_valid_message = self.validate_exporter_configs()
if not config_valid:
self.model.unit.status = BlockedStatus(config_valid_message)
return

if not self.exporter_enabled:
self.model.unit.status = BlockedStatus("Missing relation: [cos-agent]")
return
Expand All @@ -132,20 +138,16 @@ def _on_update_status(self, _: EventBase) -> None: # noqa: C901
self.model.unit.status = BlockedStatus("Cannot relate to more than one grafana-agent")
return

config_valied, confg_valid_message = self.validate_exporter_configs()
if not config_valied:
self.model.unit.status = BlockedStatus(confg_valid_message)
return

hw_tool_ok, error_msg = self.hw_tool_helper.check_installed()
if not hw_tool_ok:
self.model.unit.status = BlockedStatus(error_msg)
return

if not self.exporter.check_health():
logger.warning("Exporter health check - failed.")
# if restart isn't successful, an ExporterError exception will be raised here
self.restart_exporter()
if self._stored.exporter_installed: # type: ignore[truthy-function]
if not self.exporter.check_active():
logger.warning("Exporter health check - failed.")
# if restart isn't successful, an ExporterError exception will be raised here
self.restart_exporter()

self.model.unit.status = ActiveStatus("Unit is ready")

Expand Down

0 comments on commit 8f934bb

Please sign in to comment.