Skip to content

Commit 41e706f

Browse files
[DPE-4367] Add support for tracing through tempo-k8s (#456)
* WIP: Add tempo tracing support for the charm code * Fix tracing lib import + remove flag accidentally added to tox.ini * Move tracing relation name into a constant * Add missing types to the trace_charm decorator * Add support for TLS when sending traces to tempo * Update outdated charm libs * Revert support for TLS when sending traces to tempo * Add optional to tracing endpoint + alphabetize extra type for tracing * Update charm tracing lib to v1.7 * Update charm_tracing lib + skip tracing when running unit tests
1 parent 547aa59 commit 41e706f

File tree

11 files changed

+1900
-50
lines changed

11 files changed

+1900
-50
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

+9-5
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

+26-3
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/operator_libs_linux/v2/snap.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
# Increment this PATCH version before using `charmcraft publish-lib` or reset
8585
# to 0 if you are raising the major API version
86-
LIBPATCH = 5
86+
LIBPATCH = 7
8787

8888

8989
# Regex to locate 7-bit C1 ANSI sequences
@@ -319,7 +319,10 @@ def get(self, key: Optional[str], *, typed: bool = False) -> Any:
319319
Default is to return a string.
320320
"""
321321
if typed:
322-
config = json.loads(self._snap("get", ["-d", key]))
322+
args = ["-d"]
323+
if key:
324+
args.append(key)
325+
config = json.loads(self._snap("get", args))
323326
if key:
324327
return config.get(key)
325328
return config
@@ -584,13 +587,16 @@ def ensure(
584587
"Installing snap %s, revision %s, tracking %s", self._name, revision, channel
585588
)
586589
self._install(channel, cohort, revision)
587-
else:
590+
logger.info("The snap installation completed successfully")
591+
elif revision is None or revision != self._revision:
588592
# The snap is installed, but we are changing it (e.g., switching channels).
589593
logger.info(
590594
"Refreshing snap %s, revision %s, tracking %s", self._name, revision, channel
591595
)
592596
self._refresh(channel=channel, cohort=cohort, revision=revision, devmode=devmode)
593-
logger.info("The snap installation completed successfully")
597+
logger.info("The snap refresh completed successfully")
598+
else:
599+
logger.info("Refresh of snap %s was unnecessary", self._name)
594600

595601
self._update_snap_apps()
596602
self._state = state

0 commit comments

Comments
 (0)