Skip to content

Commit

Permalink
Merge pull request #11 from canonical/fix-memberlist
Browse files Browse the repository at this point in the history
Fix coordination between Tempo's cluster members
  • Loading branch information
michaeldmitry authored Jul 9, 2024
2 parents 17f1c98 + b75788c commit 18334e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 35 additions & 0 deletions tests/scenario/test_config.py
Original file line number Diff line number Diff line change
@@ -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",
]
)

0 comments on commit 18334e6

Please sign in to comment.