From a832643fc238609bb1488988d0df53b22fdfb5d9 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 9 Jul 2024 10:53:04 +0300 Subject: [PATCH 1/2] fix memberlist --- src/charm.py | 4 +++- tests/scenario/test_config.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/scenario/test_config.py diff --git a/src/charm.py b/src/charm.py index 9d24d39..7c52808 100755 --- a/src/charm.py +++ b/src/charm.py @@ -493,7 +493,9 @@ def _update_tempo_cluster(self): # On every function call, we always publish everything to the databag; however, if there # are no changes, Juju will notice there's no delta and do nothing self.tempo_cluster.publish_data( - tempo_config=self.tempo.generate_config(self._requested_receivers(), self._s3_config), + tempo_config=self.tempo.generate_config( + self._requested_receivers(), self._s3_config, self.tempo_cluster.gather_addresses() + ), loki_endpoints=self.loki_endpoints_by_unit, # TODO tempo receiver for charm tracing **kwargs, diff --git a/tests/scenario/test_config.py b/tests/scenario/test_config.py new file mode 100644 index 0000000..e933a15 --- /dev/null +++ b/tests/scenario/test_config.py @@ -0,0 +1,35 @@ +from scenario import State + +from charm import TempoCoordinatorCharm +from tempo_cluster import TempoClusterRequirerUnitData + + +def test_memberlist_multiple_members(context, all_worker, s3): + workers_no = 3 + all_worker = all_worker.replace( + remote_units_data={ + worker_idx: TempoClusterRequirerUnitData( + **{ + "address": f"worker-{worker_idx}.test.svc.cluster.local:7946", + "juju_topology": { + "model": "test", + "unit": f"worker/{worker_idx}", + "model_uuid": "1", + "application": "worker", + "charm_name": "TempoWorker", + }, + } + ).dump() + for worker_idx in range(workers_no) + }, + ) + state = State(leader=True, relations=[all_worker, s3]) + with context.manager(all_worker.changed_event, state) as mgr: + charm: TempoCoordinatorCharm = mgr.charm + assert charm.tempo_cluster.gather_addresses() == set( + [ + "worker-0.test.svc.cluster.local:7946", + "worker-1.test.svc.cluster.local:7946", + "worker-2.test.svc.cluster.local:7946", + ] + ) From b75788c7ab005ac53c29a8c8ddd02eaa063ff153 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 9 Jul 2024 11:07:36 +0300 Subject: [PATCH 2/2] fix static check --- src/tempo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tempo.py b/src/tempo.py index 32f9336..faa4b1c 100644 --- a/src/tempo.py +++ b/src/tempo.py @@ -6,7 +6,7 @@ import logging import socket from subprocess import CalledProcessError, getoutput -from typing import Any, Dict, List, Optional, Sequence, Tuple +from typing import Any, Dict, List, Optional, Sequence, Set, Tuple from charms.tempo_k8s.v2.tracing import ( ReceiverProtocol, @@ -148,7 +148,7 @@ def generate_config( self, receivers: Sequence[ReceiverProtocol], s3_config: dict, - peers: Optional[List[str]] = None, + peers: Optional[Set[str]] = None, ) -> Dict[str, Any]: """Generate the Tempo configuration. @@ -249,7 +249,7 @@ def _build_compactor_config(self): ) ) - def _build_memberlist_config(self, peers: Optional[List[str]]) -> tempo_config.Memberlist: + def _build_memberlist_config(self, peers: Optional[Set[str]]) -> tempo_config.Memberlist: """Build memberlist config""" return tempo_config.Memberlist( abort_if_cluster_join_fails=False,