Skip to content

Commit 1a28465

Browse files
Add support for tracing with tempo_k8s (#250)
## Issue We would like to be able to instrument our charm and generate traces to discover inefficiencies in charm code execution. The observability team has developed a charm for [tempo](https://github.com/canonical/tempo-k8s-operator) that we would like to integrate with. ## Solution Integrate with the tempo charm ## Considerations 1. We must use COS lite with edge until it is release to stable with some 2. We are sending traces with HTTP until some rough edges are rounded with HTTPS ![image](https://github.com/canonical/mysql-router-k8s-operator/assets/99665202/7049fee1-2fd2-4df6-911c-059a3d43fd83)
1 parent cd614ba commit 1a28465

File tree

14 files changed

+1934
-27
lines changed

14 files changed

+1934
-27
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
unit-test:
3232
name: Unit test charm
3333
runs-on: ubuntu-latest
34-
timeout-minutes: 15
34+
timeout-minutes: 20
3535
steps:
3636
- name: Checkout
3737
uses: actions/checkout@v4

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/grafana_k8s/v0/grafana_dashboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def __init__(self, *args):
219219
# Increment this PATCH version before using `charmcraft publish-lib` or reset
220220
# to 0 if you are raising the major API version
221221

222-
LIBPATCH = 35
222+
LIBPATCH = 36
223223

224224
logger = logging.getLogger(__name__)
225225

@@ -1050,6 +1050,7 @@ def __init__(
10501050

10511051
self.framework.observe(self._charm.on.leader_elected, self._update_all_dashboards_from_dir)
10521052
self.framework.observe(self._charm.on.upgrade_charm, self._update_all_dashboards_from_dir)
1053+
self.framework.observe(self._charm.on.config_changed, self._update_all_dashboards_from_dir)
10531054

10541055
self.framework.observe(
10551056
self._charm.on[self._relation_name].relation_created,

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)