Skip to content

Commit

Permalink
[DPE-4619] Add support for tracing through tempo-k8s (#296)
Browse files Browse the repository at this point in the history
* Add support for tracing through tempo-k8s

* Update outdated charm lib

* Update charm tracing lib to v1.7

* Update charm_tracing lib + skip tracing when running unit tests
  • Loading branch information
shayancanonical authored Jun 12, 2024
1 parent 6f5d8da commit eaf0790
Show file tree
Hide file tree
Showing 8 changed files with 1,789 additions and 14 deletions.
569 changes: 569 additions & 0 deletions lib/charms/tempo_k8s/v1/charm_tracing.py

Large diffs are not rendered by default.

923 changes: 923 additions & 0 deletions lib/charms/tempo_k8s/v2/tracing.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ requires:
interface: loki_push_api
limit: 1
optional: true
tracing:
interface: tracing
limit: 1
optional: true

peers:
pgb-peers:
Expand Down
265 changes: 251 additions & 14 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ poetry-core = "*"
pydantic = "^1.10, <2"
# grafana_agent/v0/cos_agent.py
cosl = "*"
# tempo_k8s/v1/charm_tracing.py
opentelemetry-exporter-otlp-proto-http = "1.21.0"

[tool.poetry.group.format]
optional = true
Expand Down
26 changes: 26 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer
from charms.postgresql_k8s.v0.postgresql_tls import PostgreSQLTLS
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 jinja2 import Template
from ops import JujuVersion
from ops.charm import CharmBase, ConfigChangedEvent, PebbleReadyEvent
Expand Down Expand Up @@ -48,6 +50,8 @@
TLS_CA_FILE,
TLS_CERT_FILE,
TLS_KEY_FILE,
TRACING_PROTOCOL,
TRACING_RELATION_NAME,
UNIT_SCOPE,
)
from relations.backend_database import BackendDatabaseRequires
Expand All @@ -61,6 +65,19 @@
Scopes = Literal[APP_SCOPE, UNIT_SCOPE]


@trace_charm(
tracing_endpoint="tracing_endpoint",
extra_types=(
BackendDatabaseRequires,
DbProvides,
GrafanaDashboardProvider,
LogProxyConsumer,
MetricsEndpointProvider,
Peers,
PgBouncerProvider,
PgbouncerUpgrade,
),
)
class PgBouncerK8sCharm(CharmBase):
"""A class implementing charmed PgBouncer."""

Expand Down Expand Up @@ -125,6 +142,15 @@ def __init__(self, *args):
relation_name="upgrade",
substrate="k8s",
)
self.tracing = TracingEndpointRequirer(
self, relation_name=TRACING_RELATION_NAME, protocols=[TRACING_PROTOCOL]
)

@property
def tracing_endpoint(self) -> Optional[str]:
"""Otlp http endpoint for charm instrumentation."""
if self.tracing.is_ready():
return self.tracing.get_endpoint(TRACING_PROTOCOL)

@property
def _node_name(self) -> str:
Expand Down
3 changes: 3 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
"monitoring_password": "monitoring-password",
"auth_file": "auth-file",
}

TRACING_RELATION_NAME = "tracing"
TRACING_PROTOCOL = "otlp_http"
11 changes: 11 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

import pytest
from charms.tempo_k8s.v1.charm_tracing import charm_tracing_disabled


@pytest.fixture(autouse=True)
def disable_charm_tracing():
with charm_tracing_disabled():
yield

0 comments on commit eaf0790

Please sign in to comment.