Skip to content

[MISC] Update charm libs and sync up the postgresql lib #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 45
LIBPATCH = 46

PYDEPS = ["ops>=2.0.0"]

Expand Down Expand Up @@ -989,11 +989,7 @@ def __init__(
@property
def relations(self) -> List[Relation]:
"""The list of Relation instances associated with this relation_name."""
return [
relation
for relation in self._model.relations[self.relation_name]
if self._is_relation_active(relation)
]
return self._model.relations[self.relation_name]

@property
def secrets_enabled(self):
Expand Down Expand Up @@ -1271,15 +1267,6 @@ def _legacy_apply_on_delete(self, fields: List[str]) -> None:

# Internal helper methods

@staticmethod
def _is_relation_active(relation: Relation):
"""Whether the relation is active based on contained data."""
try:
_ = repr(relation.data)
return True
except (RuntimeError, ModelError):
return False

@staticmethod
def _is_secret_field(field: str) -> bool:
"""Is the field in question a secret reference (URI) field or not?"""
Expand Down
4 changes: 2 additions & 2 deletions lib/charms/loki_k8s/v1/loki_push_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def __init__(self, ...):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 16
LIBPATCH = 17

PYDEPS = ["cosl"]

Expand Down Expand Up @@ -1354,7 +1354,7 @@ def _url(self) -> str:

Return url to loki, including port number, but without the endpoint subpath.
"""
return "http://{}:{}".format(socket.getfqdn(), self.port)
return f"{self.scheme}://{socket.getfqdn()}:{self.port}"

def _endpoint(self, url) -> dict:
"""Get Loki push API endpoint for a given url.
Expand Down
7 changes: 5 additions & 2 deletions lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 54
LIBPATCH = 53

# Groups to distinguish HBA access
ACCESS_GROUP_IDENTITY = "identity_access"
Expand Down Expand Up @@ -777,9 +777,10 @@ def list_valid_privileges_and_roles(self) -> Tuple[Set[str], Set[str]]:
"superuser",
}, {role[0] for role in cursor.fetchall() if role[0]}

def set_up_database(self) -> None:
def set_up_database(self, temp_location: Optional[str] = None) -> None:
"""Set up postgres database with the right permissions."""
connection = None
cursor = None
try:
with self._connect_to_database(
database="template1"
Expand Down Expand Up @@ -879,6 +880,8 @@ def set_up_database(self) -> None:
logger.error(f"Failed to set up databases: {e}")
raise PostgreSQLDatabasesSetupError() from e
finally:
if cursor is not None:
cursor.close()
if connection is not None:
connection.close()

Expand Down
13 changes: 10 additions & 3 deletions lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _remove_stale_otel_sdk_packages():
import opentelemetry
import ops
from opentelemetry.exporter.otlp.proto.common._internal.trace_encoder import (
encode_spans,
encode_spans # type: ignore
)
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
Expand Down Expand Up @@ -348,7 +348,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 = 7
LIBPATCH = 8

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

Expand Down Expand Up @@ -704,7 +704,14 @@ def _get_server_cert(
f"{charm_type}.{server_cert_attr} is None; sending traces over INSECURE connection."
)
return
elif not Path(server_cert).is_absolute():
if not isinstance(server_cert, (str, Path)):
logger.warning(
f"{charm_type}.{server_cert_attr} has unexpected type {type(server_cert)}; "
f"sending traces over INSECURE connection."
)
return
path = Path(server_cert)
if not path.is_absolute() or not path.exists():
raise ValueError(
f"{charm_type}.{server_cert_attr} should resolve to a valid tls cert absolute path (string | Path)); "
f"got {server_cert} instead."
Expand Down
20 changes: 17 additions & 3 deletions lib/charms/tempo_coordinator_k8s/v0/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, *args):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 7
LIBPATCH = 8

PYDEPS = ["pydantic"]

Expand Down Expand Up @@ -169,6 +169,10 @@ class DataValidationError(TracingError):
"""Raised when data validation fails on IPU relation data."""


class DataAccessPermissionError(TracingError):
"""Raised when follower units attempt leader-only operations."""


class AmbiguousRelationUsageError(TracingError):
"""Raised when one wrongly assumes that there can only be one relation on an endpoint."""

Expand Down Expand Up @@ -779,7 +783,7 @@ def __init__(
self.framework.observe(events.relation_changed, self._on_tracing_relation_changed)
self.framework.observe(events.relation_broken, self._on_tracing_relation_broken)

if protocols:
if protocols and self._charm.unit.is_leader():
# we can't be sure that the current event context supports read/writing relation data for this relation,
# so we catch ModelErrors. This is because we're doing this in init.
try:
Expand Down Expand Up @@ -809,6 +813,8 @@ def request_protocols(
TracingRequirerAppData(
receivers=list(protocols),
).dump(relation.data[self._charm.app])
else:
raise DataAccessPermissionError("only leaders can request_protocols")

@property
def relations(self) -> List[Relation]:
Expand Down Expand Up @@ -957,7 +963,15 @@ def charm_tracing_config(
if not endpoint_requirer.is_ready():
return None, None

endpoint = endpoint_requirer.get_endpoint("otlp_http")
try:
endpoint = endpoint_requirer.get_endpoint("otlp_http")
except ModelError as e:
if e.args[0] == "ERROR permission denied\n":
# this can happen the app databag doesn't have data,
# or we're breaking the relation.
return None, None
raise

if not endpoint:
return None, None

Expand Down
4 changes: 2 additions & 2 deletions lib/charms/tls_certificates_interface/v2/tls_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ def _on_all_certificates_invalidated(self, event: AllCertificatesInvalidatedEven
from typing import Any, Dict, List, Literal, Optional, Union

from cryptography import x509
from cryptography.hazmat._oid import ExtensionOID
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.serialization import pkcs12
from cryptography.x509.oid import ExtensionOID
from jsonschema import exceptions, validate
from ops.charm import (
CharmBase,
Expand All @@ -307,7 +307,7 @@ def _on_all_certificates_invalidated(self, event: AllCertificatesInvalidatedEven

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 29
LIBPATCH = 30

PYDEPS = ["cryptography", "jsonschema"]

Expand Down
Loading