Skip to content

Commit 800971c

Browse files
[DPE-4368] Add support for tracing with tempo-k8s (#424)
* Add support for tracing with tempo-k8s * Fix failing unit tests + update outdated charm libs * Update charm tracing lib to v1.7 * Update charm_tracing lib + skip tracing when running unit tests * Update loki_push_api charmlib to v0.30
1 parent 59ccbb4 commit 800971c

File tree

12 files changed

+1861
-16
lines changed

12 files changed

+1861
-16
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

Lines changed: 9 additions & 5 deletions
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 = 35
334+
LIBPATCH = 37
335335

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

@@ -642,22 +642,26 @@ def _move_to_new_label_if_needed(self):
642642
return
643643

644644
# Create a new secret with the new label
645-
old_meta = self._secret_meta
646645
content = self._secret_meta.get_content()
646+
self._secret_uri = None
647647

648648
# I wish we could just check if we are the owners of the secret...
649649
try:
650650
self._secret_meta = self.add_secret(content, label=self.label)
651651
except ModelError as err:
652652
if "this unit is not the leader" not in str(err):
653653
raise
654-
old_meta.remove_all_revisions()
654+
self.current_label = None
655655

656656
def set_content(self, content: Dict[str, str]) -> None:
657657
"""Setting cached secret content."""
658658
if not self.meta:
659659
return
660660

661+
# DPE-4182: do not create new revision if the content stay the same
662+
if content == self.get_content():
663+
return
664+
661665
if content:
662666
self._move_to_new_label_if_needed()
663667
self.meta.set_content(content)
@@ -1586,7 +1590,7 @@ def _register_secret_to_relation(
15861590
"""
15871591
label = self._generate_secret_label(relation_name, relation_id, group)
15881592

1589-
# Fetchin the Secret's meta information ensuring that it's locally getting registered with
1593+
# Fetching the Secret's meta information ensuring that it's locally getting registered with
15901594
CachedSecret(self._model, self.component, label, secret_id).meta
15911595

15921596
def _register_secrets_to_relation(self, relation: Relation, params_name_list: List[str]):
@@ -2309,7 +2313,7 @@ def _secrets(self) -> dict:
23092313
return self._cached_secrets
23102314

23112315
def _get_secret(self, group) -> Optional[Dict[str, str]]:
2312-
"""Retrieveing secrets."""
2316+
"""Retrieving secrets."""
23132317
if not self.app:
23142318
return
23152319
if not self._secrets.get(group):

lib/charms/data_platform_libs/v0/s3.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _on_credential_gone(self, event: CredentialsGoneEvent):
137137

138138
# Increment this PATCH version before using `charmcraft publish-lib` or reset
139139
# to 0 if you are raising the major API version
140-
LIBPATCH = 4
140+
LIBPATCH = 5
141141

142142
logger = logging.getLogger(__name__)
143143

@@ -212,7 +212,7 @@ class S3CredentialEvents(CharmEvents):
212212
class S3Provider(Object):
213213
"""A provider handler for communicating S3 credentials to consumers."""
214214

215-
on = S3CredentialEvents() # pyright: ignore [reportGeneralTypeIssues]
215+
on = S3CredentialEvents() # pyright: ignore [reportAssignmentType]
216216

217217
def __init__(
218218
self,
@@ -481,6 +481,18 @@ def set_s3_api_version(self, relation_id: int, s3_api_version: str) -> None:
481481
"""
482482
self.update_connection_info(relation_id, {"s3-api-version": s3_api_version})
483483

484+
def set_delete_older_than_days(self, relation_id: int, days: int) -> None:
485+
"""Sets the retention days for full backups in application databag.
486+
487+
This function writes in the application data bag, therefore,
488+
only the leader unit can call it.
489+
490+
Args:
491+
relation_id: the identifier for a particular relation.
492+
days: the value.
493+
"""
494+
self.update_connection_info(relation_id, {"delete-older-than-days": str(days)})
495+
484496
def set_attributes(self, relation_id: int, attributes: List[str]) -> None:
485497
"""Sets the connection attributes in application databag.
486498
@@ -580,6 +592,17 @@ def s3_api_version(self) -> Optional[str]:
580592

581593
return self.relation.data[self.relation.app].get("s3-api-version")
582594

595+
@property
596+
def delete_older_than_days(self) -> Optional[int]:
597+
"""Returns the retention days for full backups."""
598+
if not self.relation.app:
599+
return None
600+
601+
days = self.relation.data[self.relation.app].get("delete-older-than-days")
602+
if days is None:
603+
return None
604+
return int(days)
605+
583606
@property
584607
def attributes(self) -> Optional[List[str]]:
585608
"""Returns the attributes."""
@@ -613,7 +636,7 @@ class S3CredentialRequiresEvents(ObjectEvents):
613636
class S3Requirer(Object):
614637
"""Requires-side of the s3 relation."""
615638

616-
on = S3CredentialRequiresEvents() # pyright: ignore[reportGeneralTypeIssues]
639+
on = S3CredentialRequiresEvents() # pyright: ignore[reportAssignmentType]
617640

618641
def __init__(
619642
self, charm: ops.charm.CharmBase, relation_name: str, bucket_name: Optional[str] = None

lib/charms/loki_k8s/v0/loki_push_api.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
applications such as pebble, or charmed operators of workloads such as grafana-agent or promtail,
1717
that can communicate with loki directly.
1818
19-
- `LogProxyConsumer`: This object can be used by any Charmed Operator which needs to
20-
send telemetry, such as logs, to Loki through a Log Proxy by implementing the consumer side of the
21-
`loki_push_api` relation interface.
19+
- `LogProxyConsumer`: DEPRECATED.
20+
This object can be used by any Charmed Operator which needs to send telemetry, such as logs, to
21+
Loki through a Log Proxy by implementing the consumer side of the `loki_push_api` relation
22+
interface.
2223
2324
Filtering logs in Loki is largely performed on the basis of labels. In the Juju ecosystem, Juju
2425
topology labels are used to uniquely identify the workload which generates telemetry like logs.
@@ -38,13 +39,14 @@
3839
- `charm`: A reference to the parent (Loki) charm.
3940
4041
- `relation_name`: The name of the relation that the charm uses to interact
41-
with its clients, which implement `LokiPushApiConsumer` or `LogProxyConsumer`.
42+
with its clients, which implement `LokiPushApiConsumer` or `LogProxyConsumer`
43+
(note that LogProxyConsumer is deprecated).
4244
4345
If provided, this relation name must match a provided relation in metadata.yaml with the
4446
`loki_push_api` interface.
4547
4648
The default relation name is "logging" for `LokiPushApiConsumer` and "log-proxy" for
47-
`LogProxyConsumer`.
49+
`LogProxyConsumer` (note that LogProxyConsumer is deprecated).
4850
4951
For example, a provider's `metadata.yaml` file may look as follows:
5052
@@ -219,6 +221,9 @@ def __init__(self, *args):
219221
220222
## LogProxyConsumer Library Usage
221223
224+
> Note: This object is deprecated. Consider migrating to LogForwarder (see v1/loki_push_api) with
225+
> the release of Juju 3.6 LTS.
226+
222227
Let's say that we have a workload charm that produces logs, and we need to send those logs to a
223228
workload implementing the `loki_push_api` interface, such as `Loki` or `Grafana Agent`.
224229
@@ -480,7 +485,7 @@ def _alert_rules_error(self, event):
480485

481486
# Increment this PATCH version before using `charmcraft publish-lib` or reset
482487
# to 0 if you are raising the major API version
483-
LIBPATCH = 29
488+
LIBPATCH = 30
484489

485490
PYDEPS = ["cosl"]
486491

@@ -1539,7 +1544,8 @@ def __init__(
15391544
the Loki API endpoint to push logs. It is intended for workloads that can speak
15401545
loki_push_api (https://grafana.com/docs/loki/latest/api/#push-log-entries-to-loki), such
15411546
as grafana-agent.
1542-
(If you only need to forward a few workload log files, then use LogProxyConsumer.)
1547+
(If you need to forward workload stdout logs, then use v1/loki_push_api.LogForwarder; if
1548+
you need to forward log files, then use LogProxyConsumer.)
15431549
15441550
`LokiPushApiConsumer` can be instantiated as follows:
15451551
@@ -1728,6 +1734,9 @@ class LogProxyEvents(ObjectEvents):
17281734
class LogProxyConsumer(ConsumerBase):
17291735
"""LogProxyConsumer class.
17301736
1737+
> Note: This object is deprecated. Consider migrating to v1/loki_push_api.LogForwarder with the
1738+
> release of Juju 3.6 LTS.
1739+
17311740
The `LogProxyConsumer` object provides a method for attaching `promtail` to
17321741
a workload in order to generate structured logging data from applications
17331742
which traditionally log to syslog or do not have native Loki integration.

0 commit comments

Comments
 (0)