Skip to content

Commit

Permalink
[DPE-4362] fix: alive, restart and alive handling (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmraul authored Jun 19, 2024
1 parent 996348f commit 7c7e1a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
22 changes: 15 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer
from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider
from charms.rolling_ops.v0.rollingops import RollingOpsManager
from ops import ActiveStatus, InstallEvent, pebble
from ops.charm import SecretChangedEvent, StorageAttachedEvent, StorageDetachingEvent
from ops.framework import EventBase
from ops import (
ActiveStatus,
EventBase,
InstallEvent,
SecretChangedEvent,
StartEvent,
StatusBase,
StorageAttachedEvent,
StorageDetachingEvent,
UpdateStatusEvent,
pebble,
)
from ops.main import main
from ops.model import StatusBase
from ops.pebble import Layer

from core.cluster import ClusterState
Expand Down Expand Up @@ -186,9 +194,9 @@ def _on_kafka_pebble_ready(self, event: EventBase) -> None:
logger.info("Kafka service started")

# service_start might fail silently, confirm with ZK if kafka is actually connected
self._on_update_status(event)
self.on.update_status.emit()

def _on_start(self, event: EventBase) -> None:
def _on_start(self, event: StartEvent) -> None:
"""Wrapper for start event."""
self._on_kafka_pebble_ready(event)

Expand Down Expand Up @@ -257,7 +265,7 @@ def _on_config_changed(self, event: EventBase) -> None:
if self.model.relations.get(REL_NAME, None) and self.unit.is_leader():
self.update_client_data()

def _on_update_status(self, _: EventBase) -> None:
def _on_update_status(self, _: UpdateStatusEvent) -> None:
"""Handler for `update-status` events."""
if not self.upgrade.idle or not self.healthy:
return
Expand Down
13 changes: 5 additions & 8 deletions src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from charms.zookeeper.v0.client import QuorumLeaderNotFoundError, ZooKeeperManager
from kazoo.client import AuthFailedError, NoNodeError
from ops.model import Application, Relation, Unit
from tenacity import retry
from tenacity.retry import retry_if_not_result
from tenacity.stop import stop_after_attempt
from tenacity.wait import wait_fixed
from tenacity import retry, retry_if_result, stop_after_attempt, wait_fixed
from typing_extensions import override

from literals import INTERNAL_USERS, SECRETS_APP, Substrates
Expand Down Expand Up @@ -358,12 +355,12 @@ def zookeeper_version(self) -> str:

return zk.get_version()

# retry to give ZK time to update its broker zNodes before failing
@retry(
# retry to give ZK time to update its broker zNodes before failing
wait=wait_fixed(6),
wait=wait_fixed(5),
stop=stop_after_attempt(10),
retry_error_callback=(lambda state: state.outcome.result()), # type: ignore
retry=retry_if_not_result(lambda result: True if result else False),
retry=retry_if_result(lambda result: result is False),
retry_error_callback=lambda _: False,
)
def broker_active(self) -> bool:
"""Checks if broker id is recognised as active by ZooKeeper."""
Expand Down

0 comments on commit 7c7e1a7

Please sign in to comment.