From 8e6d541c89e85375c651ff2caaa1a1ed9c21170a Mon Sep 17 00:00:00 2001 From: Michael Thamm Date: Fri, 23 Aug 2024 14:31:01 -0400 Subject: [PATCH 1/2] Update TempoRolesConfig to be compatible with ClusterRolesConfig in the cos-lib coordinator --- src/charm.py | 8 ++++---- src/tempo_config.py | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/charm.py b/src/charm.py index 1ebbb56..48f163f 100755 --- a/src/charm.py +++ b/src/charm.py @@ -20,14 +20,14 @@ receiver_protocol_to_transport_protocol, ) from charms.traefik_route_k8s.v0.traefik_route import TraefikRouteRequirer -from cosl.coordinated_workers.coordinator import Coordinator +from cosl.coordinated_workers.coordinator import Coordinator, ClusterRolesConfig from cosl.coordinated_workers.nginx import CA_CERT_PATH, CERT_PATH, KEY_PATH from ops.charm import CharmBase, RelationEvent from ops.main import main from nginx_config import NginxConfig from tempo import Tempo -from tempo_config import TempoRolesConfig +from tempo_config import TEMPO_ROLES_CONFIG logger = logging.getLogger(__name__) @@ -35,7 +35,7 @@ @trace_charm( tracing_endpoint="tempo_otlp_http_endpoint", server_cert="server_ca_cert", - extra_types=(Tempo, TracingEndpointProvider, Coordinator, TempoRolesConfig), + extra_types=(Tempo, TracingEndpointProvider, Coordinator, ClusterRolesConfig), ) class TempoCoordinatorCharm(CharmBase): """Charmed Operator for Tempo; a distributed tracing backend.""" @@ -49,7 +49,7 @@ def __init__(self, *args): self.unit.set_ports(*self.tempo.all_ports.values()) self.coordinator = Coordinator( charm=self, - roles_config=TempoRolesConfig(), + roles_config=TEMPO_ROLES_CONFIG, s3_bucket_name=Tempo.s3_bucket_name, external_url=self._external_url, worker_metrics_port=self.tempo.tempo_http_server_port, diff --git a/src/tempo_config.py b/src/tempo_config.py index 4ac225b..d90be69 100644 --- a/src/tempo_config.py +++ b/src/tempo_config.py @@ -2,14 +2,15 @@ # See LICENSE file for licensing details. """Helper module for interacting with the Tempo configuration.""" + import enum import logging import re from enum import Enum, unique from pathlib import Path -from typing import Any, Dict, Iterable, List, Mapping, Optional +from typing import Any, Dict, List, Optional from urllib.parse import urlparse - +from cosl.coordinated_workers.coordinator import ClusterRolesConfig from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator logger = logging.getLogger(__name__) @@ -80,14 +81,13 @@ def all_nonmeta(): https://github.com/grafana/helm-charts/blob/main/charts/tempo-distributed/ """ - -class TempoRolesConfig: - """Define the configuration for Tempo roles.""" - - roles: Iterable[str] = {role for role in TempoRole} - meta_roles: Mapping[str, Iterable[str]] = META_ROLES - minimal_deployment: Iterable[str] = MINIMAL_DEPLOYMENT - recommended_deployment: Dict[str, int] = RECOMMENDED_DEPLOYMENT +TEMPO_ROLES_CONFIG = ClusterRolesConfig( + roles={role for role in TempoRole}, + meta_roles=META_ROLES, + minimal_deployment=MINIMAL_DEPLOYMENT, + recommended_deployment=RECOMMENDED_DEPLOYMENT, +) +"""Define the configuration for Tempo roles.""" class ClientAuthTypeEnum(str, enum.Enum): From de602a98e149646c7f49a6ffebc736bf8d1e7bd5 Mon Sep 17 00:00:00 2001 From: Michael Thamm Date: Tue, 27 Aug 2024 09:54:14 -0400 Subject: [PATCH 2/2] Updated the TEMPO_ROLES_CONFIG in test_coherence --- tests/unit/test_coherence.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_coherence.py b/tests/unit/test_coherence.py index ad0fca5..274cffe 100644 --- a/tests/unit/test_coherence.py +++ b/tests/unit/test_coherence.py @@ -7,7 +7,7 @@ MINIMAL_DEPLOYMENT, RECOMMENDED_DEPLOYMENT, TempoRole, - TempoRolesConfig, + TEMPO_ROLES_CONFIG, ) @@ -29,7 +29,7 @@ def test_coherent(mock_coordinator, roles, expected): cluster_mock.gather_roles = MagicMock(return_value=roles) mc.cluster = cluster_mock mc._is_coherent = None - mc.roles_config = TempoRolesConfig() + mc.roles_config = TEMPO_ROLES_CONFIG assert mc.is_coherent is expected @@ -51,6 +51,6 @@ def test_recommended(mock_coordinator, roles, expected): cluster_mock.gather_roles = MagicMock(return_value=roles) mc.cluster = cluster_mock mc._is_recommended = None - mc.roles_config = TempoRolesConfig() + mc.roles_config = TEMPO_ROLES_CONFIG assert mc.is_recommended is expected