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

Add traefik_route to serve tracing endpoints through ingress if it exists #94

Merged
merged 19 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mmkay marked this conversation as resolved.
Show resolved Hide resolved
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[str] = "http",
mmkay marked this conversation as resolved.
Show resolved Hide resolved
):
"""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,
PietroPasotti marked this conversation as resolved.
Show resolved Hide resolved
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
Loading