From 97e040dc0dc83179aab7ae4d9ae8ddd72dab1ed6 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 26 Jun 2024 13:51:55 +0300 Subject: [PATCH] add extra receivers config options --- charmcraft.yaml | 14 ++++++++++++++ src/charm.py | 28 ++++++++++++++++++++++------ src/tempo.py | 2 -- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/charmcraft.yaml b/charmcraft.yaml index 8da12a6..ad9c796 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -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 diff --git a/src/charm.py b/src/charm.py index b739d59..9d24d39 100755 --- a/src/charm.py +++ b/src/charm.py @@ -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 @@ -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, ) @@ -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 # ################## @@ -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): @@ -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: diff --git a/src/tempo.py b/src/tempo.py index 9ebb9d9..5c346f6 100644 --- a/src/tempo.py +++ b/src/tempo.py @@ -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