|
12 | 12 | from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider
|
13 | 13 | from charms.rolling_ops.v0.rollingops import RollingOpsManager
|
14 | 14 | from ops import (
|
| 15 | + ActiveStatus, |
| 16 | + CollectStatusEvent, |
15 | 17 | EventBase,
|
16 | 18 | StatusBase,
|
17 | 19 | )
|
@@ -60,6 +62,7 @@ def __init__(self, *args):
|
60 | 62 | self.restart = RollingOpsManager(self, relation="restart", callback=self._restart_broker)
|
61 | 63 |
|
62 | 64 | self.framework.observe(getattr(self.on, "config_changed"), self._on_roles_changed)
|
| 65 | + self.framework.observe(self.on.collect_app_status, self._on_collect_status) |
63 | 66 |
|
64 | 67 | # peer-cluster events are shared between all roles, so necessary to init here to avoid instantiating multiple times
|
65 | 68 | self.peer_cluster = PeerClusterEventsHandler(self)
|
@@ -127,6 +130,23 @@ def _set_status(self, key: Status) -> None:
|
127 | 130 | getattr(logger, log_level.lower())(status.message)
|
128 | 131 | self.unit.status = status
|
129 | 132 |
|
| 133 | + def _on_collect_status(self, event: CollectStatusEvent): |
| 134 | + ready_to_start = self.state.ready_to_start.value.status |
| 135 | + event.add_status(ready_to_start) |
| 136 | + |
| 137 | + if not isinstance(ready_to_start, ActiveStatus): |
| 138 | + return |
| 139 | + |
| 140 | + if not self.state.runs_broker: |
| 141 | + # early return, the next checks only concern the broker |
| 142 | + return |
| 143 | + |
| 144 | + if not self.broker.workload.active(): |
| 145 | + event.add_status(Status.BROKER_NOT_RUNNING.value.status) |
| 146 | + |
| 147 | + if not self.state.zookeeper.broker_active(): |
| 148 | + event.add_status(Status.ZK_NOT_CONNECTED.value.status) |
| 149 | + |
130 | 150 |
|
131 | 151 | if __name__ == "__main__":
|
132 | 152 | main(KafkaCharm)
|
0 commit comments