Skip to content

Commit

Permalink
chore: update charm libraries (#283)
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 authored Aug 20, 2024
1 parent e2be9bf commit 618fefe
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 23 deletions.
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
3 changes: 2 additions & 1 deletion src/alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
from typing import Callable, Dict, List, Optional, Tuple

from alertmanager_client import Alertmanager, AlertmanagerBadResponse
from ops.framework import Object
from ops.model import Container
from ops.pebble import ( # type: ignore
Expand All @@ -18,6 +17,8 @@
Layer,
)

from alertmanager_client import Alertmanager, AlertmanagerBadResponse

logger = logging.getLogger(__name__)


Expand Down
15 changes: 8 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
from urllib.parse import urlparse

import yaml
from alertmanager import (
ConfigFileSystemState,
ConfigUpdateFailure,
WorkloadManager,
WorkloadManagerError,
)
from charms.alertmanager_k8s.v0.alertmanager_remote_configuration import (
RemoteConfigurationRequirer,
)
Expand All @@ -38,7 +32,6 @@
from charms.tempo_k8s.v1.charm_tracing import trace_charm
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer
from charms.traefik_k8s.v2.ingress import IngressPerAppRequirer
from config_builder import ConfigBuilder, ConfigError
from ops.charm import ActionEvent, CharmBase
from ops.main import main
from ops.model import (
Expand All @@ -51,6 +44,14 @@
)
from ops.pebble import PathError, ProtocolError # type: ignore

from alertmanager import (
ConfigFileSystemState,
ConfigUpdateFailure,
WorkloadManager,
WorkloadManagerError,
)
from config_builder import ConfigBuilder, ConfigError

logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import pytest
import yaml
from alertmanager_client import Alertmanager
from helpers import get_unit_address, is_alertmanager_up, uk8s_group
from pytest_operator.plugin import OpsTest

from alertmanager_client import Alertmanager

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
Expand Down
3 changes: 2 additions & 1 deletion tests/scenario/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from unittest.mock import patch

import pytest
from scenario import Context

from alertmanager import WorkloadManager
from charm import AlertmanagerCharm
from scenario import Context


def tautology(*_, **__) -> bool:
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

import ops
import yaml
from alertmanager import WorkloadManager
from charm import AlertmanagerCharm
from helpers import k8s_resource_multipatch
from ops import pebble
from ops.model import ActiveStatus, BlockedStatus
from ops.testing import Harness

from alertmanager import WorkloadManager
from charm import AlertmanagerCharm

ops.testing.SIMULATE_CAN_CONNECT = True


Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_external_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import ops
import yaml
from alertmanager import WorkloadManager
from charm import AlertmanagerCharm
from helpers import cli_arg, k8s_resource_multipatch
from ops.testing import Harness

from alertmanager import WorkloadManager
from charm import AlertmanagerCharm

logger = logging.getLogger(__name__)

ops.testing.SIMULATE_CAN_CONNECT = True
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_push_config_to_workload_on_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import ops
import validators
import yaml
from alertmanager import WorkloadManager
from charm import AlertmanagerCharm
from helpers import k8s_resource_multipatch
from hypothesis import given
from ops.model import ActiveStatus, BlockedStatus
from ops.testing import Harness

from alertmanager import WorkloadManager
from charm import AlertmanagerCharm

logger = logging.getLogger(__name__)
ops.testing.SIMULATE_CAN_CONNECT = True
CONTAINER_NAME = "alertmanager"
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_remote_configuration_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from unittest.mock import Mock, patch

import yaml
from alertmanager import WorkloadManager
from charm import AlertmanagerCharm
from charms.alertmanager_k8s.v0.alertmanager_remote_configuration import (
DEFAULT_RELATION_NAME,
)
Expand All @@ -18,6 +16,9 @@
from ops import testing
from ops.model import BlockedStatus

from alertmanager import WorkloadManager
from charm import AlertmanagerCharm

logger = logging.getLogger(__name__)

testing.SIMULATE_CAN_CONNECT = True
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_self_scrape_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import unittest
from unittest.mock import PropertyMock, patch

from alertmanager import WorkloadManager
from charm import AlertmanagerCharm
from helpers import k8s_resource_multipatch
from ops.testing import Harness

from alertmanager import WorkloadManager
from charm import AlertmanagerCharm


class TestWithInitialHooks(unittest.TestCase):
container_name: str = "alertmanager"
Expand Down

0 comments on commit 618fefe

Please sign in to comment.