Skip to content

Commit

Permalink
Merge pull request #26 from canonical/update-cluster-roles-config
Browse files Browse the repository at this point in the history
Update TempoRolesConfig for cos-lib coordinator compatibility
  • Loading branch information
mmkay authored Aug 28, 2024
2 parents 0c9226e + de602a9 commit 979e74c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
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__)


@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."""
Expand All @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions src/tempo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_coherence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
MINIMAL_DEPLOYMENT,
RECOMMENDED_DEPLOYMENT,
TempoRole,
TempoRolesConfig,
TEMPO_ROLES_CONFIG,
)


Expand All @@ -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

Expand All @@ -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

0 comments on commit 979e74c

Please sign in to comment.