diff --git a/lib/charms/tempo_k8s/v1/charm_tracing.py b/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py similarity index 96% rename from lib/charms/tempo_k8s/v1/charm_tracing.py rename to lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py index 2dbdddd6..2604c39e 100644 --- a/lib/charms/tempo_k8s/v1/charm_tracing.py +++ b/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py @@ -12,15 +12,15 @@ # Quickstart Fetch the following charm libs (and ensure the minimum version/revision numbers are satisfied): - charmcraft fetch-lib charms.tempo_k8s.v2.tracing # >= 1.10 - charmcraft fetch-lib charms.tempo_k8s.v1.charm_tracing # >= 2.7 + charmcraft fetch-lib charms.tempo_coordinator_k8s.v0.tracing # >= 1.10 + charmcraft fetch-lib charms.tempo_coordinator_k8s.v0.charm_tracing # >= 2.7 Then edit your charm code to include: ```python # import the necessary charm libs -from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer, charm_tracing_config -from charms.tempo_k8s.v1.charm_tracing import charm_tracing +from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer, charm_tracing_config +from charms.tempo_coordinator_k8s.v0.charm_tracing import charm_tracing # decorate your charm class with charm_tracing: @charm_tracing( @@ -51,7 +51,7 @@ def __init__(self, ...): 2) add to your charm a "my_tracing_endpoint" (you can name this attribute whatever you like) **property**, **method** or **instance attribute** that returns an otlp http/https endpoint url. -If you are using the ``charms.tempo_k8s.v2.tracing.TracingEndpointRequirer`` as +If you are using the ``charms.tempo_coordinator_k8s.v0.tracing.TracingEndpointRequirer`` as ``self.tracing = TracingEndpointRequirer(self)``, the implementation could be: ``` @@ -80,7 +80,7 @@ def my_tracing_endpoint(self) -> Optional[str]: For example: ``` -from charms.tempo_k8s.v1.charm_tracing import trace_charm +from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm @trace_charm( tracing_endpoint="my_tracing_endpoint", server_cert="_server_cert" @@ -129,7 +129,7 @@ def get_tracer(self) -> opentelemetry.trace.Tracer: For example: ``` - from charms.tempo_k8s.v0.charm_tracing import trace_charm + from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm @trace_charm( tracing_endpoint="my_tracing_endpoint", @@ -150,7 +150,7 @@ def my_tracing_endpoint(self) -> Optional[str]: needs to be replaced with: ``` - from charms.tempo_k8s.v1.charm_tracing import trace_charm + from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm @trace_charm( tracing_endpoint="my_tracing_endpoint", @@ -249,28 +249,27 @@ def _remove_stale_otel_sdk_packages(): from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import Span, TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor +from opentelemetry.trace import INVALID_SPAN, Tracer +from opentelemetry.trace import get_current_span as otlp_get_current_span from opentelemetry.trace import ( - INVALID_SPAN, - Tracer, get_tracer, get_tracer_provider, set_span_in_context, set_tracer_provider, ) -from opentelemetry.trace import get_current_span as otlp_get_current_span from ops.charm import CharmBase from ops.framework import Framework # The unique Charmhub library identifier, never change it -LIBID = "cb1705dcd1a14ca09b2e60187d1215c7" +LIBID = "01780f1e588c42c3976d26780fdf9b89" # Increment this major API version when introducing breaking changes -LIBAPI = 1 +LIBAPI = 0 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 15 +LIBPATCH = 1 PYDEPS = ["opentelemetry-exporter-otlp-proto-http==1.21.0"] @@ -332,7 +331,7 @@ def _get_tracer() -> Optional[Tracer]: return tracer.get() except LookupError: # fallback: this course-corrects for a user error where charm_tracing symbols are imported - # from different paths (typically charms.tempo_k8s... and lib.charms.tempo_k8s...) + # from different paths (typically charms.tempo_coordinator_k8s... and lib.charms.tempo_coordinator_k8s...) try: ctx: Context = copy_context() if context_tracer := _get_tracer_from_context(ctx): @@ -562,8 +561,8 @@ def trace_charm( method calls on instances of this class. Usage: - >>> from charms.tempo_k8s.v1.charm_tracing import trace_charm - >>> from charms.tempo_k8s.v1.tracing import TracingEndpointRequirer + >>> from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm + >>> from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer >>> from ops import CharmBase >>> >>> @trace_charm( @@ -626,7 +625,7 @@ def _autoinstrument( Usage: - >>> from charms.tempo_k8s.v1.charm_tracing import _autoinstrument + >>> from charms.tempo_coordinator_k8s.v0.charm_tracing import _autoinstrument >>> from ops.main import main >>> _autoinstrument( >>> MyCharm, diff --git a/lib/charms/tempo_k8s/v2/tracing.py b/lib/charms/tempo_coordinator_k8s/v0/tracing.py similarity index 98% rename from lib/charms/tempo_k8s/v2/tracing.py rename to lib/charms/tempo_coordinator_k8s/v0/tracing.py index 81bf1f1f..4af379a5 100644 --- a/lib/charms/tempo_k8s/v2/tracing.py +++ b/lib/charms/tempo_coordinator_k8s/v0/tracing.py @@ -16,7 +16,7 @@ This relation must use the `tracing` interface. The `TracingEndpointRequirer` object may be instantiated as follows - from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer + from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer def __init__(self, *args): super().__init__(*args) @@ -58,7 +58,7 @@ def __init__(self, *args): For example a Tempo charm may instantiate the `TracingEndpointProvider` in its constructor as follows - from charms.tempo_k8s.v2.tracing import TracingEndpointProvider + from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointProvider def __init__(self, *args): super().__init__(*args) @@ -100,14 +100,14 @@ def __init__(self, *args): from pydantic import BaseModel, Field # The unique Charmhub library identifier, never change it -LIBID = "12977e9aa0b34367903d8afeb8c3d85d" +LIBID = "d2f02b1f8d1244b5989fd55bc3a28943" # Increment this major API version when introducing breaking changes -LIBAPI = 2 +LIBAPI = 0 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 10 +LIBPATCH = 1 PYDEPS = ["pydantic"] @@ -947,8 +947,8 @@ def charm_tracing_config( Usage: If you are using charm_tracing >= v1.9: - >>> from lib.charms.tempo_k8s.v1.charm_tracing import trace_charm - >>> from lib.charms.tempo_k8s.v2.tracing import charm_tracing_config + >>> from lib.charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm + >>> from lib.charms.tempo_coordinator_k8s.v0.tracing import charm_tracing_config >>> @trace_charm(tracing_endpoint="my_endpoint", cert_path="cert_path") >>> class MyCharm(...): >>> _cert_path = "/path/to/cert/on/charm/container.crt" @@ -958,8 +958,8 @@ def charm_tracing_config( ... self.tracing, self._cert_path) If you are using charm_tracing < v1.9: - >>> from lib.charms.tempo_k8s.v1.charm_tracing import trace_charm - >>> from lib.charms.tempo_k8s.v2.tracing import charm_tracing_config + >>> from lib.charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm + >>> from lib.charms.tempo_coordinator_k8s.v0.tracing import charm_tracing_config >>> @trace_charm(tracing_endpoint="my_endpoint", cert_path="cert_path") >>> class MyCharm(...): >>> _cert_path = "/path/to/cert/on/charm/container.crt" diff --git a/src/charm.py b/src/charm.py index 4f97276b..bf5d2b26 100755 --- a/src/charm.py +++ b/src/charm.py @@ -35,8 +35,8 @@ from charms.observability_libs.v1.cert_handler import CertHandler from charms.observability_libs.v1.kubernetes_service_patch import KubernetesServicePatch from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider -from charms.tempo_k8s.v1.charm_tracing import trace_charm -from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer +from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm +from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer, charm_tracing_config from charms.traefik_k8s.v0.traefik_route import ( TraefikRouteProvider, TraefikRouteRequirerReadyEvent, @@ -194,6 +194,10 @@ def __init__(self, *args): # tracing integration self._tracing = TracingEndpointRequirer(self, protocols=["otlp_http"]) + self.charm_tracing_endpoint, self.server_cert = charm_tracing_config( + self._tracing, SERVER_CERT_PATH + ) + # Provide grafana dashboards over a relation interface # dashboard to use: https://grafana.com/grafana/dashboards/4475-traefik/ # TODO wishlist: I would like for the p60, p70, p80, p90, p99, min, max, and avg for @@ -350,20 +354,6 @@ def _on_recv_ca_cert_removed(self, event: CertificateTransferRemovedEvent): # Assuming only one cert per relation (this is in line with the original lib design). self.traefik.remove_cas([event.relation_id]) - @property - def charm_tracing_endpoint(self) -> Optional[str]: - """Otlp http endpoint for charm instrumentation.""" - if self._tracing.is_ready(): - return self._tracing.get_endpoint("otlp_http") - return None - - @property - def server_cert(self) -> Optional[str]: - """Server certificate path for tls tracing.""" - if self._is_tls_enabled(): - return SERVER_CERT_PATH - return None - def _is_tls_enabled(self) -> bool: """Return True if TLS is enabled.""" if self.cert.enabled: diff --git a/tests/integration/testers/forward-auth/charmcraft.yaml b/tests/integration/testers/forward-auth/charmcraft.yaml index e439b3e7..1fdadc99 100644 --- a/tests/integration/testers/forward-auth/charmcraft.yaml +++ b/tests/integration/testers/forward-auth/charmcraft.yaml @@ -13,6 +13,6 @@ parts: charm-binary-python-packages: - jsonschema - ops - - pydantic-core + - pydantic>=2 build-packages: - git diff --git a/tests/integration/testers/ipa/charmcraft.yaml b/tests/integration/testers/ipa/charmcraft.yaml index c864b362..b4f11527 100644 --- a/tests/integration/testers/ipa/charmcraft.yaml +++ b/tests/integration/testers/ipa/charmcraft.yaml @@ -12,6 +12,6 @@ parts: charm: charm-binary-python-packages: - ops - - pydantic-core + - pydantic>=2 build-packages: - git diff --git a/tests/integration/testers/ipu/charmcraft.yaml b/tests/integration/testers/ipu/charmcraft.yaml index c864b362..b4f11527 100644 --- a/tests/integration/testers/ipu/charmcraft.yaml +++ b/tests/integration/testers/ipu/charmcraft.yaml @@ -12,6 +12,6 @@ parts: charm: charm-binary-python-packages: - ops - - pydantic-core + - pydantic>=2 build-packages: - git diff --git a/tests/integration/testers/route/charmcraft.yaml b/tests/integration/testers/route/charmcraft.yaml index c864b362..b4f11527 100644 --- a/tests/integration/testers/route/charmcraft.yaml +++ b/tests/integration/testers/route/charmcraft.yaml @@ -12,6 +12,6 @@ parts: charm: charm-binary-python-packages: - ops - - pydantic-core + - pydantic>=2 build-packages: - git diff --git a/tests/integration/testers/tcp/charmcraft.yaml b/tests/integration/testers/tcp/charmcraft.yaml index 06980aca..65dafb1c 100644 --- a/tests/integration/testers/tcp/charmcraft.yaml +++ b/tests/integration/testers/tcp/charmcraft.yaml @@ -13,6 +13,6 @@ parts: charm-binary-python-packages: - ops - lightkube - - pydantic-core + - pydantic>=2 build-packages: - git diff --git a/tests/scenario/test_tracing_integration.py b/tests/scenario/test_tracing_integration.py index e37ecbca..7fe038fc 100644 --- a/tests/scenario/test_tracing_integration.py +++ b/tests/scenario/test_tracing_integration.py @@ -3,8 +3,8 @@ import opentelemetry import pytest import yaml -from charms.tempo_k8s.v1.charm_tracing import charm_tracing_disabled -from charms.tempo_k8s.v2.tracing import ProtocolType, Receiver, TracingProviderAppData +from charms.tempo_coordinator_k8s.v0.charm_tracing import charm_tracing_disabled +from charms.tempo_coordinator_k8s.v0.tracing import ProtocolType, Receiver, TracingProviderAppData from scenario import Relation, State from traefik import CA_CERT_PATH, DYNAMIC_TRACING_PATH diff --git a/tox.ini b/tox.ini index 395ea929..1a981ef9 100644 --- a/tox.ini +++ b/tox.ini @@ -96,8 +96,9 @@ commands = description = Run interface tests deps = pytest - ops-scenario>=5.3.1 + ops-scenario~=6.0 pytest-interface-tester > 0.3 -r{toxinidir}/requirements.txt commands = - pytest -v --tb native {[vars]tst_path}/interface --log-cli-level=INFO -s {posargs} + # todo uncomment once scenario v7 migration on interface tester is complete + # pytest -v --tb native {[vars]tst_path}/interface --log-cli-level=INFO -s {posargs}