Skip to content

Commit

Permalink
[DPE-5712] Add warning logs to Patroni reinitialisation (#753)
Browse files Browse the repository at this point in the history
* Add warning logs to Patroni reinitialisation

* Set status once
  • Loading branch information
dragomirp authored Nov 2, 2024
1 parent bd29058 commit 388c639
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,10 @@ def _on_peer_relation_changed(self, event: HookEvent) -> None: # noqa: C901
or int(self._patroni.member_replication_lag) > 1000
)
):
logger.warning("Workload failure detected. Reinitialising unit.")
self.unit.status = MaintenanceStatus("reinitialising replica")
self._patroni.reinitialize_postgresql()
logger.debug("Deferring on_peer_relation_changed: reinitialising replica")
self.unit.status = MaintenanceStatus("reinitialising replica")
event.defer()
return

Expand Down Expand Up @@ -1543,9 +1544,9 @@ def _handle_processes_failures(self) -> bool:
and not self._patroni.member_streaming
):
try:
self._patroni.reinitialize_postgresql()
logger.info("restarted the replica because it was not streaming from primary")
logger.warning("Degraded member detected: reinitialising unit")
self.unit.status = MaintenanceStatus("reinitialising replica")
self._patroni.reinitialize_postgresql()
except RetryError:
logger.error(
"failed to reinitialise replica after checking that it was not streaming from primary"
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,9 +1578,7 @@ def test_handle_processes_failures(harness):
harness.charm.unit.status = ActiveStatus()
result = harness.charm._handle_processes_failures()
assert result == (values[0] is None)
assert isinstance(
harness.charm.unit.status, MaintenanceStatus if values[0] is None else ActiveStatus
)
assert isinstance(harness.charm.unit.status, MaintenanceStatus)
_restart.assert_not_called()
_reinitialize_postgresql.assert_called_once()

Expand Down

0 comments on commit 388c639

Please sign in to comment.