Skip to content

Commit

Permalink
add extra receivers config options
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldmitry committed Jun 26, 2024
1 parent e4f3683 commit 97e040d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
14 changes: 14 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,17 @@ parts:
- "jsonschema"
- "opentelemetry-exporter-otlp-proto-http==1.21.0"

config:
options:
always_enable_zipkin:
description: force enable a receiver for Tempo's 'zipkin' protocol.
type: boolean
default: false
always_enable_otlp_grpc:
description: force enable a receiver for Tempo's 'otlp_grpc' protocol.
type: boolean
default: false
always_enable_otlp_http:
description: force enable a receiver for Tempo's 'otlp_http' protocol.
type: boolean
default: false
28 changes: 22 additions & 6 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import socket
from pathlib import Path
from typing import Dict, List, Optional, Set, Tuple
from typing import Dict, List, Optional, Set, Tuple, get_args

import ops
from charms.data_platform_libs.v0.s3 import S3Requirer
Expand Down Expand Up @@ -61,9 +61,6 @@ def __init__(self, *args):

self.tempo = tempo = Tempo(
external_host=self.hostname,
# we need otlp_http receiver for charm_tracing
# TODO add any extra receivers enabled manually via config
enable_receivers=["otlp_http"],
use_tls=self.tls_available,
)

Expand Down Expand Up @@ -250,6 +247,21 @@ def _local_ip(self) -> Optional[str]:
)
return None

@property
def enabled_receivers(self) -> Set[str]:
"""Extra receivers enabled through config"""
enabled_receivers = set()
# otlp_http is needed by charm_tracing
enabled_receivers.add("otlp_http")
enabled_receivers.update(
[
receiver
for receiver in get_args(ReceiverProtocol)
if self.config.get(f"always_enable_{receiver}") is True
]
)
return enabled_receivers

##################
# EVENT HANDLERS #
##################
Expand Down Expand Up @@ -392,13 +404,14 @@ def _update_tracing_relations(self):
self._update_tempo_cluster()

def _requested_receivers(self) -> Tuple[ReceiverProtocol, ...]:
"""List what receivers we should activate, based on the active tracing relations."""
"""List what receivers we should activate, based on the active tracing relations and config-enabled extra receivers."""
# we start with the sum of the requested endpoints from the requirers
requested_protocols = set(self.tracing.requested_protocols())

# update with enabled extra receivers
requested_protocols.update(self.enabled_receivers)
# and publish only those we support
requested_receivers = requested_protocols.intersection(set(self.tempo.receiver_ports))
requested_receivers.update(self.tempo.enabled_receivers)
return tuple(requested_receivers)

def server_cert(self):
Expand Down Expand Up @@ -466,6 +479,9 @@ def _update_tempo_cluster(self):
logger.error("skipped tempo cluster update: inconsistent state")
return

if not self.unit.is_leader():
return

kwargs = {}

if self.tls_available:
Expand Down
2 changes: 0 additions & 2 deletions src/tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ class Tempo:
def __init__(
self,
external_host: Optional[str] = None,
enable_receivers: Optional[Sequence[ReceiverProtocol]] = None,
use_tls: bool = False,
):
# ports source: https://github.com/grafana/tempo/blob/main/example/docker-compose/local/docker-compose.yaml

# fqdn, if an ingress is not available, else the ingress address.
self._external_hostname = external_host or socket.getfqdn()
self.enabled_receivers = enable_receivers or []
self.use_tls = use_tls

@property
Expand Down

0 comments on commit 97e040d

Please sign in to comment.