Skip to content

Commit

Permalink
split tracing receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldmitry committed Nov 12, 2024
1 parent c7ea5ec commit b726722
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
25 changes: 14 additions & 11 deletions src/cosl/coordinated_workers/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,18 @@ def __init__(
######################

@property
def _tracing_receivers_urls(self) -> Dict[str, str]:
"""Returns the union of charm and workload enabled receivers' protocols with their corresponding endpoints."""
receivers_urls: Dict[str, str] = {}
for tracing_type in ["charm_tracing", "workload_tracing"]:
tracing = getattr(self, tracing_type)
all_endpoints = tracing.get_all_endpoints()
if all_endpoints:
for receiver in all_endpoints.receivers:
receivers_urls[receiver.protocol.name] = receiver.url
return receivers_urls
def _charm_tracing_receivers_urls(self) -> Dict[str, str]:
"""Returns the charm tracing enabled receivers with their corresponding endpoints."""
endpoints = self.charm_tracing.get_all_endpoints()
receivers = endpoints.receivers if endpoints else ()
return {receiver.protocol.name: receiver.url for receiver in receivers}

@property
def _workload_tracing_receivers_urls(self) -> Dict[str, str]:
"""Returns the workload tracing enabled receivers with their corresponding endpoints."""
endpoints = self.workload_tracing.get_all_endpoints()
receivers = endpoints.receivers if endpoints else ()
return {receiver.protocol.name: receiver.url for receiver in receivers}

@property
def is_coherent(self) -> bool:
Expand Down Expand Up @@ -679,7 +681,8 @@ def update_cluster(self):
privkey_secret_id=(
self.cluster.grant_privkey(VAULT_SECRET_LABEL) if self.tls_available else None
),
tracing_receivers=self._tracing_receivers_urls,
charm_tracing_receivers=self._charm_tracing_receivers_urls,
workload_tracing_receivers=self._workload_tracing_receivers_urls,
remote_write_endpoints=(
self.remote_write_endpoints_getter()
if self.remote_write_endpoints_getter
Expand Down
25 changes: 18 additions & 7 deletions src/cosl/coordinated_workers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ class ClusterProviderAppData(DatabagModel):
### self-monitoring stuff
loki_endpoints: Optional[Dict[str, str]] = None
"""Endpoints to which the workload (and the worker charm) can push logs to."""
tracing_receivers: Optional[Dict[str, str]] = None
"""Endpoints to which the workload (and the worker charm) can push traces to."""
charm_tracing_receivers: Optional[Dict[str, str]] = None
"""Endpoints to which the the worker charm can push charm traces to."""
workload_tracing_receivers: Optional[Dict[str, str]] = None
"""Endpoints to which the the worker can push workload traces to."""
remote_write_endpoints: Optional[List[RemoteWriteEndpoint]] = None
"""Endpoints to which the workload (and the worker charm) can push metrics to."""

Expand Down Expand Up @@ -282,7 +284,8 @@ def publish_data(
s3_tls_ca_chain: Optional[str] = None,
privkey_secret_id: Optional[str] = None,
loki_endpoints: Optional[Dict[str, str]] = None,
tracing_receivers: Optional[Dict[str, str]] = None,
charm_tracing_receivers: Optional[Dict[str, str]] = None,
workload_tracing_receivers: Optional[Dict[str, str]] = None,
remote_write_endpoints: Optional[List[RemoteWriteEndpoint]] = None,
) -> None:
"""Publish the config to all related worker clusters."""
Expand All @@ -294,7 +297,8 @@ def publish_data(
ca_cert=ca_cert,
server_cert=server_cert,
privkey_secret_id=privkey_secret_id,
tracing_receivers=tracing_receivers,
charm_tracing_receivers=charm_tracing_receivers,
workload_tracing_receivers=workload_tracing_receivers,
remote_write_endpoints=remote_write_endpoints,
s3_tls_ca_chain=s3_tls_ca_chain,
)
Expand Down Expand Up @@ -573,11 +577,18 @@ def get_tls_data(self, allow_none: bool = False) -> Optional[TLSData]:
s3_tls_ca_chain=data.s3_tls_ca_chain,
)

def get_tracing_receivers(self) -> Dict[str, str]:
"""Fetch the tracing receivers from the coordinator databag."""
def get_charm_tracing_receivers(self) -> Dict[str, str]:
"""Fetch the charm tracing receivers from the coordinator databag."""
data = self._get_data_from_coordinator()
if data:
return data.tracing_receivers or {}
return data.charm_tracing_receivers or {}
return {}

def get_workload_tracing_receivers(self) -> Dict[str, str]:
"""Fetch the workload tracing receivers from the coordinator databag."""
data = self._get_data_from_coordinator()
if data:
return data.workload_tracing_receivers or {}
return {}

def get_remote_write_endpoints(self) -> List[RemoteWriteEndpoint]:
Expand Down
2 changes: 1 addition & 1 deletion src/cosl/coordinated_workers/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def charm_tracing_config(self) -> Tuple[Optional[str], Optional[str]]:
>>> self.worker = Worker(...)
>>> self.my_endpoint, self.cert_path = self.worker.charm_tracing_config()
"""
receivers = self.cluster.get_tracing_receivers()
receivers = self.cluster.get_charm_tracing_receivers()

if not receivers:
return None, None
Expand Down
12 changes: 7 additions & 5 deletions tests/test_coordinated_workers/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def test_tracing_receivers_urls(coordinator_state: State, coordinator_charm: ops
remote_app_data={
"receivers": json.dumps(
[
{"protocol": {"name": "otlp_http", "type": "http"}, "url": "1.2.3.4:4318"},
{"protocol": {"name": "otlp_grpc", "type": "grpc"}, "url": "1.2.3.4:4317"},
{"protocol": {"name": "otlp_http", "type": "http"}, "url": "5.6.7.8:4318"},
{"protocol": {"name": "otlp_grpc", "type": "grpc"}, "url": "5.6.7.8:4317"},
]
)
},
Expand All @@ -272,8 +272,10 @@ def test_tracing_receivers_urls(coordinator_state: State, coordinator_charm: ops
),
) as mgr:
coordinator: Coordinator = mgr.charm.coordinator
expected_result = {
assert coordinator._charm_tracing_receivers_urls == {
"otlp_http": "1.2.3.4:4318",
"otlp_grpc": "1.2.3.4:4317",
}
assert coordinator._tracing_receivers_urls == expected_result
assert coordinator._workload_tracing_receivers_urls == {
"otlp_http": "5.6.7.8:4318",
"otlp_grpc": "5.6.7.8:4317",
}

0 comments on commit b726722

Please sign in to comment.