Skip to content

Commit

Permalink
Start the exporter in on peer relation changed
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Sep 12, 2023
1 parent 06667d8 commit e7e2a4e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ def _on_peer_relation_changed(self, event: HookEvent):
event.defer()
return

if "exporter-started" not in self.unit_peer_data:
self._setup_exporter()

self._update_new_unit_status()

def _update_new_unit_status(self) -> None:
Expand Down Expand Up @@ -1391,10 +1394,7 @@ def update_config(self, is_creating_backup: bool = False) -> bool:
"Early exit update_config: Trying to reset metrics service with no configuration set"
)
return True
if (
snap_password != self.get_secret(APP_SCOPE, MONITORING_PASSWORD_KEY)
or "exporter-started" not in self.unit_peer_data
):
if snap_password != self.get_secret(APP_SCOPE, MONITORING_PASSWORD_KEY):
self._setup_exporter()

return True
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,16 @@ def test_is_primary_pgbackrest_service_running(
self.assertFalse(self.charm.backup._is_primary_pgbackrest_service_running)
_execute_command.assert_called_once()

# Test when the endpoint is not generated.
_execute_command.reset_mock()
_primary_endpoint.return_value = None
self.assertFalse(self.charm.backup._is_primary_pgbackrest_service_running)
_execute_command.assert_not_called()

# Test when the pgBackRest succeeds on contacting the primary server.
_execute_command.reset_mock()
_execute_command.return_value = (0, "fake stdout", "")
_primary_endpoint.return_value = "fake_endpoint"
self.assertTrue(self.charm.backup._is_primary_pgbackrest_service_running)
_execute_command.assert_called_once()

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ def test_on_cluster_topology_change_clear_blocked(
self.assertTrue(isinstance(self.harness.model.unit.status, ActiveStatus))

@patch_network_get(private_address="1.1.1.1")
@patch("charm.snap.SnapCache")
@patch("charm.PostgresqlOperatorCharm._update_relation_endpoints")
@patch("charm.PostgresqlOperatorCharm.primary_endpoint", new_callable=PropertyMock)
@patch("charm.Patroni.member_started", new_callable=PropertyMock)
Expand All @@ -1142,6 +1143,7 @@ def test_on_peer_relation_changed(
_member_started,
_primary_endpoint,
_update_relation_endpoints,
_,
):
# Test an uninitialized cluster.
mock_event = Mock()
Expand Down

0 comments on commit e7e2a4e

Please sign in to comment.