Skip to content

Commit

Permalink
chore: update charm libraries (#313)
Browse files Browse the repository at this point in the history
* chore: update charm libraries

* tox fmt

---------

Co-authored-by: Luca Bello <[email protected]>
  • Loading branch information
observability-noctua-bot and lucabello committed Aug 19, 2024
1 parent b9819ce commit ff9722b
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 22 deletions.
12 changes: 3 additions & 9 deletions lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

LIBID = "e6f580481c1b4388aa4d2cdf412a47fa"
LIBAPI = 0
LIBPATCH = 5
LIBPATCH = 6

DEFAULT_RELATION_NAME = "grafana-cloud-config"

Expand Down Expand Up @@ -53,15 +53,9 @@ def __init__(self, charm, relation_name = DEFAULT_RELATION_NAME):
self.framework.observe(event, self._on_relation_broken)

def _on_relation_changed(self, event):
if not self._charm.unit.is_leader():
return

self.on.cloud_config_available.emit() # pyright: ignore

def _on_relation_broken(self, event):
if not self._charm.unit.is_leader():
return

self.on.cloud_config_revoked.emit() # pyright: ignore

def _is_not_empty(self, s):
Expand Down Expand Up @@ -130,7 +124,7 @@ def prometheus_endpoint(self) -> dict:
"""Return the prometheus endpoint dict."""
if not self.prometheus_ready:
return {}

endpoint = {}
endpoint["url"] = self.prometheus_url
if self.credentials:
Expand All @@ -154,4 +148,4 @@ def _data(self):
for relation in self._charm.model.relations[self._relation_name]:
logger.info("%s %s %s", relation, self._relation_name, relation.data[relation.app])
return relation.data[relation.app]
return {}
return {}
17 changes: 14 additions & 3 deletions lib/charms/tempo_k8s/v1/charm_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ def _remove_stale_otel_sdk_packages():

_remove_stale_otel_sdk_packages()


import functools
import inspect
import logging
Expand Down Expand Up @@ -271,7 +270,7 @@ def _remove_stale_otel_sdk_packages():
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 14
LIBPATCH = 15

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

Expand All @@ -281,7 +280,6 @@ def _remove_stale_otel_sdk_packages():
# set this to 0 if you are debugging/developing this library source
dev_logger.setLevel(logging.CRITICAL)


_CharmType = Type[CharmBase] # the type CharmBase and any subclass thereof
_C = TypeVar("_C", bound=_CharmType)
_T = TypeVar("_T", bound=type)
Expand Down Expand Up @@ -333,9 +331,22 @@ def _get_tracer() -> Optional[Tracer]:
try:
return tracer.get()
except LookupError:
# fallback: this course-corrects for a user error where charm_tracing symbols are imported
# from different paths (typically charms.tempo_k8s... and lib.charms.tempo_k8s...)
try:
ctx: Context = copy_context()
if context_tracer := _get_tracer_from_context(ctx):
logger.warning(
"Tracer not found in `tracer` context var. "
"Verify that you're importing all `charm_tracing` symbols from the same module path. \n"
"For example, DO"
": `from charms.lib...charm_tracing import foo, bar`. \n"
"DONT: \n"
" \t - `from charms.lib...charm_tracing import foo` \n"
" \t - `from lib...charm_tracing import bar` \n"
"For more info: https://python-notes.curiousefficiency.org/en/latest/python"
"_concepts/import_traps.html#the-double-import-trap"
)
return context_tracer.get()
else:
return None
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ ignore-words-list = "assertIn"
[tool.ruff]
line-length = 99
exclude = ["__pycache__", "*.egg_info"]

[tool.ruff.lint]
select = ["E", "W", "F", "C", "N", "R", "D", "I001"]
# Ignore E501 because using black creates errors with this
# Ignore D107 Missing docstring in __init__
ignore = ["C901", "E501", "D107", "RET504"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# D100, D101, D102, D103: Ignore missing docstrings in tests
"tests/*" = ["D100","D101","D102","D103"]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

# Static analysis tools configuration
Expand Down
3 changes: 2 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointConsumer
from charms.tempo_k8s.v1.charm_tracing import trace_charm
from cosl import GrafanaDashboard
from grafana_agent import CONFIG_PATH, GrafanaAgentCharm
from ops.main import main
from ops.pebble import Layer

from grafana_agent import CONFIG_PATH, GrafanaAgentCharm

logger = logging.getLogger(__name__)

SCRAPE_RELATION_NAME = "metrics-endpoint"
Expand Down
3 changes: 2 additions & 1 deletion tests/scenario/test_dashboard_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# See LICENSE file for licensing details.
import json

from charm import GrafanaAgentK8sCharm
from cosl import GrafanaDashboard
from scenario import Container, Context, Relation, State

from charm import GrafanaAgentK8sCharm


def encode_as_dashboard(dct: dict):
return GrafanaDashboard._serialize(json.dumps(dct).encode("utf-8"))
Expand Down
3 changes: 2 additions & 1 deletion tests/scenario/test_setup_statuses.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

import charm
from ops import BlockedStatus, UnknownStatus, pebble
from scenario import Container, Context, ExecOutput, State

import charm


def test_install(vroot):
context = Context(
Expand Down
3 changes: 2 additions & 1 deletion tests/scenario/test_start_statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import dataclasses
from pathlib import Path

from charm import GrafanaAgentK8sCharm
from ops import pebble
from scenario import Container, Context, ExecOutput, State

from charm import GrafanaAgentK8sCharm

CHARM_ROOT = Path(__file__).parent.parent.parent


Expand Down
5 changes: 3 additions & 2 deletions tests/scenario/test_tracing_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import pytest
import scenario
import yaml
from charm import GrafanaAgentK8sCharm
from charms.tempo_k8s.v1.charm_tracing import charm_tracing_disabled
from charms.tempo_k8s.v2.tracing import Receiver, TracingProviderAppData, TracingRequirerAppData
from grafana_agent import CONFIG_PATH
from ops import pebble

from charm import GrafanaAgentK8sCharm
from grafana_agent import CONFIG_PATH


@pytest.fixture
def ctx(vroot):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_relation_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import unittest
from unittest.mock import patch

from charm import GrafanaAgentK8sCharm as GrafanaAgentCharm
from ops.model import ActiveStatus, BlockedStatus
from ops.testing import Harness

from charm import GrafanaAgentK8sCharm as GrafanaAgentCharm


class TestRelationStatus(unittest.TestCase):
def setUp(self, *unused):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_update_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import unittest
from unittest.mock import patch

from charm import GrafanaAgentK8sCharm as GrafanaAgentCharm
from ops.testing import Harness

from charm import GrafanaAgentK8sCharm as GrafanaAgentCharm


class TestUpdateStatus(unittest.TestCase):
def setUp(self, *unused):
Expand Down

0 comments on commit ff9722b

Please sign in to comment.