Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Add traefik_route to serve tracing endpoints through ingress if it ex…
Browse files Browse the repository at this point in the history
…ists (#94)

Co-authored-by: PietroPasotti <[email protected]>
  • Loading branch information
mmkay and PietroPasotti authored May 3, 2024
1 parent 36c5b1c commit 228848b
Show file tree
Hide file tree
Showing 10 changed files with 776 additions and 66 deletions.
6 changes: 5 additions & 1 deletion charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ requires:
logging:
interface: loki_push_api
ingress:
interface: ingress
interface: traefik_route
limit: 1
description: |
Ingress integration for Tempo server and Tempo receiver endpoints,
so that cross-model workloads can send their traces to Tempo through the ingress.
Uses `traefik_route` to open ports on Traefik host for tracing ingesters.
storage:
data:
Expand Down
20 changes: 14 additions & 6 deletions lib/charms/tempo_k8s/v2/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, *args):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 3
LIBPATCH = 4

PYDEPS = ["pydantic"]

Expand Down Expand Up @@ -308,6 +308,9 @@ class TracingProviderAppData(DatabagModel): # noqa: D101
external_url: Optional[str] = None
"""Server url. If an ingress is present, it will be the ingress address."""

internal_scheme: Optional[str] = None
"""Scheme for internal communication. If it is present, it will be protocol accepted by the provider."""


class TracingRequirerAppData(DatabagModel): # noqa: D101
"""Application databag model for the tracing requirer."""
Expand Down Expand Up @@ -495,6 +498,7 @@ def __init__(
host: str,
external_url: Optional[str] = None,
relation_name: str = DEFAULT_RELATION_NAME,
internal_scheme: Optional[Literal["http", "https"]] = "http",
):
"""Initialize.
Expand Down Expand Up @@ -525,6 +529,7 @@ def __init__(
self._host = host
self._external_url = external_url
self._relation_name = relation_name
self._internal_scheme = internal_scheme
self.framework.observe(
self._charm.on[relation_name].relation_joined, self._on_relation_event
)
Expand Down Expand Up @@ -590,10 +595,11 @@ def publish_receivers(self, receivers: Sequence[RawReceiver]):
try:
TracingProviderAppData(
host=self._host,
external_url=self._external_url,
external_url=f"http://{self._external_url}" if self._external_url else None,
receivers=[
Receiver(port=port, protocol=protocol) for protocol, port in receivers
],
internal_scheme=self._internal_scheme,
).dump(relation.data[self._charm.app])

except ModelError as e:
Expand Down Expand Up @@ -822,11 +828,13 @@ def _get_endpoint(
receiver = receivers[0]
# if there's an external_url argument (v2.5+), use that. Otherwise, we use the tempo local fqdn
if app_data.external_url:
url = app_data.external_url
url = f"{app_data.external_url}:{receiver.port}"
else:
# FIXME: if we don't get an external url but only a
# hostname, we don't know what scheme we need to be using. ASSUME HTTP
url = f"http://{app_data.host}:{receiver.port}"
if app_data.internal_scheme:
url = f"{app_data.internal_scheme}://{app_data.host}:{receiver.port}"
else:
# if we didn't receive a scheme (old provider), we assume HTTP is used
url = f"http://{app_data.host}:{receiver.port}"

if receiver.protocol.endswith("grpc"):
# TCP protocols don't want an http/https scheme prefix
Expand Down
Loading

0 comments on commit 228848b

Please sign in to comment.