Skip to content

Commit a1fcf70

Browse files
[DPE-5312] Integrate with Tempo HA + test relay support of tracing traffic through grafana-agent-k8s (#518)
* Update tracing charm libs to retrieve them from tempo coordinator repo * Add missed new tracing charm libs * Update outdated charm libs
1 parent 62a12fd commit a1fcf70

File tree

7 files changed

+54
-33
lines changed

7 files changed

+54
-33
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
331331

332332
# Increment this PATCH version before using `charmcraft publish-lib` or reset
333333
# to 0 if you are raising the major API version
334-
LIBPATCH = 39
334+
LIBPATCH = 40
335335

336336
PYDEPS = ["ops>=2.0.0"]
337337

@@ -391,6 +391,10 @@ class IllegalOperationError(DataInterfacesError):
391391
"""To be used when an operation is not allowed to be performed."""
392392

393393

394+
class PrematureDataAccessError(DataInterfacesError):
395+
"""To be raised when the Relation Data may be accessed (written) before protocol init complete."""
396+
397+
394398
##############################################################################
395399
# Global helpers / utilities
396400
##############################################################################
@@ -1453,6 +1457,8 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
14531457
class ProviderData(Data):
14541458
"""Base provides-side of the data products relation."""
14551459

1460+
RESOURCE_FIELD = "database"
1461+
14561462
def __init__(
14571463
self,
14581464
model: Model,
@@ -1618,6 +1624,15 @@ def _fetch_my_specific_relation_data(
16181624
def _update_relation_data(self, relation: Relation, data: Dict[str, str]) -> None:
16191625
"""Set values for fields not caring whether it's a secret or not."""
16201626
req_secret_fields = []
1627+
1628+
keys = set(data.keys())
1629+
if self.fetch_relation_field(relation.id, self.RESOURCE_FIELD) is None and (
1630+
keys - {"endpoints", "read-only-endpoints", "replset"}
1631+
):
1632+
raise PrematureDataAccessError(
1633+
"Premature access to relation data, update is forbidden before the connection is initialized."
1634+
)
1635+
16211636
if relation.app:
16221637
req_secret_fields = get_encoded_list(relation, relation.app, REQ_SECRET_FIELDS)
16231638

@@ -3290,6 +3305,8 @@ class KafkaRequiresEvents(CharmEvents):
32903305
class KafkaProviderData(ProviderData):
32913306
"""Provider-side of the Kafka relation."""
32923307

3308+
RESOURCE_FIELD = "topic"
3309+
32933310
def __init__(self, model: Model, relation_name: str) -> None:
32943311
super().__init__(model, relation_name)
32953312

@@ -3539,6 +3556,8 @@ class OpenSearchRequiresEvents(CharmEvents):
35393556
class OpenSearchProvidesData(ProviderData):
35403557
"""Provider-side of the OpenSearch relation."""
35413558

3559+
RESOURCE_FIELD = "index"
3560+
35423561
def __init__(self, model: Model, relation_name: str) -> None:
35433562
super().__init__(model, relation_name)
35443563

lib/charms/mysql/v0/tls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
LIBID = "eb73947deedd4380a3a90d527e0878eb"
5353
LIBAPI = 0
54-
LIBPATCH = 7
54+
LIBPATCH = 8
5555

5656
SCOPE = "unit"
5757

@@ -166,6 +166,9 @@ def _on_certificate_expiring(self, event: CertificateExpiringEvent) -> None:
166166

167167
def _on_tls_relation_broken(self, _) -> None:
168168
"""Disable TLS when TLS relation broken."""
169+
if self.charm.removing_unit:
170+
logger.debug("Unit is being removed, skipping TLS cleanup.")
171+
return
169172
try:
170173
if not ops.jujuversion.JujuVersion.from_environ().has_secrets:
171174
self.charm.set_secret(SCOPE, "certificate-authority", None)

lib/charms/tempo_k8s/v1/charm_tracing.py renamed to lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
# Quickstart
1313
Fetch the following charm libs (and ensure the minimum version/revision numbers are satisfied):
1414
15-
charmcraft fetch-lib charms.tempo_k8s.v2.tracing # >= 1.10
16-
charmcraft fetch-lib charms.tempo_k8s.v1.charm_tracing # >= 2.7
15+
charmcraft fetch-lib charms.tempo_coordinator_k8s.v0.tracing # >= 1.10
16+
charmcraft fetch-lib charms.tempo_coordinator_k8s.v0.charm_tracing # >= 2.7
1717
1818
Then edit your charm code to include:
1919
2020
```python
2121
# import the necessary charm libs
22-
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer, charm_tracing_config
23-
from charms.tempo_k8s.v1.charm_tracing import charm_tracing
22+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer, charm_tracing_config
23+
from charms.tempo_coordinator_k8s.v0.charm_tracing import charm_tracing
2424
2525
# decorate your charm class with charm_tracing:
2626
@charm_tracing(
@@ -51,7 +51,7 @@ def __init__(self, ...):
5151
5252
2) add to your charm a "my_tracing_endpoint" (you can name this attribute whatever you like)
5353
**property**, **method** or **instance attribute** that returns an otlp http/https endpoint url.
54-
If you are using the ``charms.tempo_k8s.v2.tracing.TracingEndpointRequirer`` as
54+
If you are using the ``charms.tempo_coordinator_k8s.v0.tracing.TracingEndpointRequirer`` as
5555
``self.tracing = TracingEndpointRequirer(self)``, the implementation could be:
5656
5757
```
@@ -80,7 +80,7 @@ def my_tracing_endpoint(self) -> Optional[str]:
8080
8181
For example:
8282
```
83-
from charms.tempo_k8s.v1.charm_tracing import trace_charm
83+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
8484
@trace_charm(
8585
tracing_endpoint="my_tracing_endpoint",
8686
server_cert="_server_cert"
@@ -129,7 +129,7 @@ def get_tracer(self) -> opentelemetry.trace.Tracer:
129129
For example:
130130
131131
```
132-
from charms.tempo_k8s.v0.charm_tracing import trace_charm
132+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
133133
134134
@trace_charm(
135135
tracing_endpoint="my_tracing_endpoint",
@@ -150,7 +150,7 @@ def my_tracing_endpoint(self) -> Optional[str]:
150150
needs to be replaced with:
151151
152152
```
153-
from charms.tempo_k8s.v1.charm_tracing import trace_charm
153+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
154154
155155
@trace_charm(
156156
tracing_endpoint="my_tracing_endpoint",
@@ -249,28 +249,27 @@ def _remove_stale_otel_sdk_packages():
249249
from opentelemetry.sdk.resources import Resource
250250
from opentelemetry.sdk.trace import Span, TracerProvider
251251
from opentelemetry.sdk.trace.export import BatchSpanProcessor
252+
from opentelemetry.trace import INVALID_SPAN, Tracer
253+
from opentelemetry.trace import get_current_span as otlp_get_current_span
252254
from opentelemetry.trace import (
253-
INVALID_SPAN,
254-
Tracer,
255255
get_tracer,
256256
get_tracer_provider,
257257
set_span_in_context,
258258
set_tracer_provider,
259259
)
260-
from opentelemetry.trace import get_current_span as otlp_get_current_span
261260
from ops.charm import CharmBase
262261
from ops.framework import Framework
263262

264263
# The unique Charmhub library identifier, never change it
265-
LIBID = "cb1705dcd1a14ca09b2e60187d1215c7"
264+
LIBID = "01780f1e588c42c3976d26780fdf9b89"
266265

267266
# Increment this major API version when introducing breaking changes
268-
LIBAPI = 1
267+
LIBAPI = 0
269268

270269
# Increment this PATCH version before using `charmcraft publish-lib` or reset
271270
# to 0 if you are raising the major API version
272271

273-
LIBPATCH = 15
272+
LIBPATCH = 1
274273

275274
PYDEPS = ["opentelemetry-exporter-otlp-proto-http==1.21.0"]
276275

@@ -332,7 +331,7 @@ def _get_tracer() -> Optional[Tracer]:
332331
return tracer.get()
333332
except LookupError:
334333
# fallback: this course-corrects for a user error where charm_tracing symbols are imported
335-
# from different paths (typically charms.tempo_k8s... and lib.charms.tempo_k8s...)
334+
# from different paths (typically charms.tempo_coordinator_k8s... and lib.charms.tempo_coordinator_k8s...)
336335
try:
337336
ctx: Context = copy_context()
338337
if context_tracer := _get_tracer_from_context(ctx):
@@ -562,8 +561,8 @@ def trace_charm(
562561
method calls on instances of this class.
563562
564563
Usage:
565-
>>> from charms.tempo_k8s.v1.charm_tracing import trace_charm
566-
>>> from charms.tempo_k8s.v1.tracing import TracingEndpointRequirer
564+
>>> from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
565+
>>> from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer
567566
>>> from ops import CharmBase
568567
>>>
569568
>>> @trace_charm(
@@ -626,7 +625,7 @@ def _autoinstrument(
626625
627626
Usage:
628627
629-
>>> from charms.tempo_k8s.v1.charm_tracing import _autoinstrument
628+
>>> from charms.tempo_coordinator_k8s.v0.charm_tracing import _autoinstrument
630629
>>> from ops.main import main
631630
>>> _autoinstrument(
632631
>>> MyCharm,

lib/charms/tempo_k8s/v2/tracing.py renamed to lib/charms/tempo_coordinator_k8s/v0/tracing.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
This relation must use the `tracing` interface.
1717
The `TracingEndpointRequirer` object may be instantiated as follows
1818
19-
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer
19+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer
2020
2121
def __init__(self, *args):
2222
super().__init__(*args)
@@ -58,7 +58,7 @@ def __init__(self, *args):
5858
For example a Tempo charm may instantiate the `TracingEndpointProvider` in its constructor as
5959
follows
6060
61-
from charms.tempo_k8s.v2.tracing import TracingEndpointProvider
61+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointProvider
6262
6363
def __init__(self, *args):
6464
super().__init__(*args)
@@ -100,14 +100,14 @@ def __init__(self, *args):
100100
from pydantic import BaseModel, Field
101101

102102
# The unique Charmhub library identifier, never change it
103-
LIBID = "12977e9aa0b34367903d8afeb8c3d85d"
103+
LIBID = "d2f02b1f8d1244b5989fd55bc3a28943"
104104

105105
# Increment this major API version when introducing breaking changes
106-
LIBAPI = 2
106+
LIBAPI = 0
107107

108108
# Increment this PATCH version before using `charmcraft publish-lib` or reset
109109
# to 0 if you are raising the major API version
110-
LIBPATCH = 10
110+
LIBPATCH = 1
111111

112112
PYDEPS = ["pydantic"]
113113

@@ -947,8 +947,8 @@ def charm_tracing_config(
947947
948948
Usage:
949949
If you are using charm_tracing >= v1.9:
950-
>>> from lib.charms.tempo_k8s.v1.charm_tracing import trace_charm
951-
>>> from lib.charms.tempo_k8s.v2.tracing import charm_tracing_config
950+
>>> from lib.charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
951+
>>> from lib.charms.tempo_coordinator_k8s.v0.tracing import charm_tracing_config
952952
>>> @trace_charm(tracing_endpoint="my_endpoint", cert_path="cert_path")
953953
>>> class MyCharm(...):
954954
>>> _cert_path = "/path/to/cert/on/charm/container.crt"
@@ -958,8 +958,8 @@ def charm_tracing_config(
958958
... self.tracing, self._cert_path)
959959
960960
If you are using charm_tracing < v1.9:
961-
>>> from lib.charms.tempo_k8s.v1.charm_tracing import trace_charm
962-
>>> from lib.charms.tempo_k8s.v2.tracing import charm_tracing_config
961+
>>> from lib.charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
962+
>>> from lib.charms.tempo_coordinator_k8s.v0.tracing import charm_tracing_config
963963
>>> @trace_charm(tracing_endpoint="my_endpoint", cert_path="cert_path")
964964
>>> class MyCharm(...):
965965
>>> _cert_path = "/path/to/cert/on/charm/container.crt"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cryptography = ">=42.0.5"
2525
jsonschema = "*"
2626
# loki_k8s/v0/loki_push_api.py and prometheus_k8s/v0/prometheus_scrape.py
2727
cosl = "*"
28-
# tempo_k8s/v1/charm_tracing.py
28+
# tempo_coordinator_k8s/v0/charm_tracing.py
2929
opentelemetry-exporter-otlp-proto-http = "1.21.0"
3030

3131
[tool.poetry.group.format]

src/charm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
from charms.mysql.v0.tls import MySQLTLS
4141
from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider
4242
from charms.rolling_ops.v0.rollingops import RollingOpsManager
43-
from charms.tempo_k8s.v1.charm_tracing import trace_charm
44-
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer
43+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
44+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer
4545
from ops import EventBase, RelationBrokenEvent, RelationCreatedEvent
4646
from ops.charm import RelationChangedEvent, UpdateStatusEvent
4747
from ops.main import main

tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See LICENSE file for licensing details.
33

44
import pytest
5-
from charms.tempo_k8s.v1.charm_tracing import charm_tracing_disabled
5+
from charms.tempo_coordinator_k8s.v0.charm_tracing import charm_tracing_disabled
66

77

88
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)