Skip to content

Commit

Permalink
Merge pull request #12 from canonical/fix-dist-frontend
Browse files Browse the repository at this point in the history
Fix frontend_worker address in distributed mode
  • Loading branch information
michaeldmitry authored Jul 9, 2024
2 parents 18334e6 + 8304761 commit c2cfb3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,10 @@ def _update_tempo_cluster(self):
# 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, self.tempo_cluster.gather_addresses()
self._requested_receivers(),
self._s3_config,
self.tempo_cluster.gather_addresses_by_role(),
self.tempo_cluster.gather_addresses(),
),
loki_endpoints=self.loki_endpoints_by_unit,
# TODO tempo receiver for charm tracing
Expand Down
13 changes: 9 additions & 4 deletions src/tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from charms.traefik_route_k8s.v0.traefik_route import TraefikRouteRequirer

import tempo_config
from tempo_cluster import TempoRole

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -148,6 +149,7 @@ def generate_config(
self,
receivers: Sequence[ReceiverProtocol],
s3_config: dict,
roles_addresses: Dict[str, Set[str]],
peers: Optional[Set[str]] = None,
) -> Dict[str, Any]:
"""Generate the Tempo configuration.
Expand All @@ -161,7 +163,7 @@ def generate_config(
ingester=self._build_ingester_config(),
memberlist=self._build_memberlist_config(peers),
compactor=self._build_compactor_config(),
querier=self._build_querier_config(),
querier=self._build_querier_config(roles_addresses),
storage=self._build_storage_config(s3_config),
)

Expand Down Expand Up @@ -225,12 +227,15 @@ def is_ready(self):
return False
return out == "ready"

def _build_querier_config(self):
def _build_querier_config(self, roles_addresses: Dict[str, Set[str]]):
"""Build querier config"""
# TODO this won't work for distributed coordinator where query frontend will be on a different unit
addr = "localhost"
if TempoRole.query_frontend in roles_addresses.keys():
addr = roles_addresses[TempoRole.query_frontend].pop()

return tempo_config.Querier(
frontend_worker=tempo_config.FrontendWorker(
frontend_address=f"localhost:{self.tempo_grpc_server_port}"
frontend_address=f"{addr}:{self.tempo_grpc_server_port}"
),
)

Expand Down
8 changes: 6 additions & 2 deletions tests/scenario/test_tempo_clustered.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def all_worker_with_initial_config(all_worker: Relation, s3_config):
container.exists = lambda path: (
False if path in [Tempo.tls_cert_path, Tempo.tls_key_path, Tempo.tls_ca_path] else True
)
initial_config = Tempo(container).generate_config(["otlp_http"], s3_config)
initial_config = Tempo(container).generate_config(
["otlp_http"], s3_config, {"all": "localhost"}
)
new_local_app_data = TempoClusterProviderAppData(
tempo_config=initial_config,
loki_endpoints={},
Expand Down Expand Up @@ -111,5 +113,7 @@ def test_tempo_restart_on_ingress_v2_changed(
# THEN
# Tempo pushes a new config to the all_worker
new_config = get_tempo_config(state_out)
expected_config = Tempo().generate_config(["otlp_http", requested_protocol], s3_config)
expected_config = Tempo().generate_config(
["otlp_http", requested_protocol], s3_config, {"all": "localhost"}
)
assert new_config == expected_config

0 comments on commit c2cfb3d

Please sign in to comment.