Skip to content
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
41 changes: 40 additions & 1 deletion lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def _on_subject_requested(self, event: SubjectRequestedEvent):

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

PYDEPS = ["ops>=2.0.0"]

Expand Down Expand Up @@ -842,6 +842,11 @@ def _legacy_compat_find_secret_by_old_label(self) -> None:
self._secret_meta = self._model.get_secret(label=label)
except SecretNotFoundError:
pass
except ModelError as e:
# Permission denied can be raised if the secret exists but is not yet granted to us.
if "permission denied" in str(e):
return
raise
else:
if label != self.label:
self.current_label = label
Expand Down Expand Up @@ -876,6 +881,8 @@ def _legacy_migration_to_new_label_if_needed(self) -> None:
except ModelError as err:
if MODEL_ERRORS["not_leader"] not in str(err):
raise
if "permission denied" not in str(err):
raise
self.current_label = None

##########################################################################
Expand Down Expand Up @@ -4268,6 +4275,14 @@ def _on_secret_changed_event(self, event: SecretChangedEvent):
if relation.app == self.charm.app:
logging.info("Secret changed event ignored for Secret Owner")

if relation.name != self.relation_data.relation_name:
logger.debug(
"Ignoring secret-changed from endpoint %s (expected %s)",
relation.name,
self.relation_data.relation_name,
)
return

remote_unit = None
for unit in relation.units:
if unit.app != self.charm.app:
Expand Down Expand Up @@ -5294,6 +5309,14 @@ def _on_secret_changed_event(self, event: SecretChangedEvent):
)
return

if relation.name != self.relation_data.relation_name:
logger.debug(
"Ignoring secret-changed from endpoint %s (expected %s)",
relation.name,
self.relation_data.relation_name,
)
return

if relation.app == self.charm.app:
logging.info("Secret changed event ignored for Secret Owner")

Expand Down Expand Up @@ -5556,6 +5579,14 @@ def _on_secret_changed_event(self, event: SecretChangedEvent):
)
return

if relation.name != self.relation_data.relation_name:
logger.debug(
"Ignoring secret-changed from endpoint %s (expected %s)",
relation.name,
self.relation_data.relation_name,
)
return

if relation.app == self.charm.app:
logging.info("Secret changed event ignored for Secret Owner")

Expand Down Expand Up @@ -5701,6 +5732,14 @@ def _on_secret_changed_event(self, event: SecretChangedEvent):
if relation.app == self.charm.app:
logging.info("Secret changed event ignored for Secret Owner")

if relation.name != self.relation_data.relation_name:
logger.debug(
"Ignoring secret-changed from endpoint %s (expected %s)",
relation.name,
self.relation_data.relation_name,
)
return

remote_unit = None
for unit in relation.units:
if unit.app != self.charm.app:
Expand Down
14 changes: 12 additions & 2 deletions lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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 = 47
LIBPATCH = 48

PYDEPS = ["cosl >= 0.0.50"]

Expand Down Expand Up @@ -585,9 +585,19 @@ def _convert_dashboard_fields(cls, content: str, inject_dropdowns: bool = True)
datasources[template_value["name"]] = template_value["query"].lower()

# Put our own variables in the template
# We only want to inject our own dropdowns IFF they are NOT
# already in the template coming over relation data.
# We'll store all dropdowns in the template from the provider
# in a set. We'll add our own if they are not in this set.
existing_names = {
item.get("name")
for item in dict_content["templating"]["list"]
}

for d in template_dropdowns: # type: ignore
if d not in dict_content["templating"]["list"]:
if d.get("name") not in existing_names:
dict_content["templating"]["list"].insert(0, d)
existing_names.add(d.get("name"))

dict_content = cls._replace_template_fields(dict_content, datasources, existing_templates)
return json.dumps(dict_content)
Expand Down
32 changes: 26 additions & 6 deletions lib/charms/loki_k8s/v1/loki_push_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(self, *args):
external_url = urlparse(self._external_url)
self.loki_provider = LokiPushApiProvider(
self,
address=external_url.hostname or self.hostname,
port=external_url.port or 80,
scheme=external_url.scheme,
path=f"{external_url.path}/loki/api/v1/push",
Expand All @@ -96,6 +95,7 @@ def __init__(self, *args):

1. Set the URL of the Loki Push API in the relation application data bag; the URL
must be unique to all instances (e.g. using a load balancer).
The default URL is the FQDN, but this can be overridden by calling `update_endpoint()`.

2. Set the Promtail binary URL (`promtail_binary_zip_url`) so clients that use
`LogProxyConsumer` object could download and configure it.
Expand Down Expand Up @@ -508,6 +508,7 @@ def __init__(self, ...):
import subprocess
import tempfile
import typing
import warnings
from copy import deepcopy
from gzip import GzipFile
from hashlib import sha256
Expand Down Expand Up @@ -544,7 +545,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 = 21
LIBPATCH = 22

PYDEPS = ["cosl"]

Expand Down Expand Up @@ -1150,7 +1151,7 @@ def __init__(
*,
port: Union[str, int] = 3100,
scheme: str = "http",
address: str = "localhost",
address: str = "",
path: str = "loki/api/v1/push",
):
"""A Loki service provider.
Expand All @@ -1165,7 +1166,9 @@ def __init__(
other charms that consume metrics endpoints.
port: an optional port of the Loki service (default is "3100").
scheme: an optional scheme of the Loki API URL (default is "http").
address: an optional address of the Loki service (default is "localhost").
address: DEPRECATED. This argument is ignored and will be removed in v2.
It is kept for backward compatibility.
Use `update_endpoint()` instead.
path: an optional path of the Loki API URL (default is "loki/api/v1/push")

Raises:
Expand All @@ -1181,14 +1184,23 @@ def __init__(
_validate_relation_by_interface_and_direction(
charm, relation_name, RELATION_INTERFACE_NAME, RelationRole.provides
)

if address != "":
warnings.warn(
"The 'address' parameter is deprecated and will be removed in v2. "
"Use 'update_endpoint()' instead.",
DeprecationWarning,
stacklevel=2,
)

super().__init__(charm, relation_name)
self._charm = charm
self._relation_name = relation_name
self._tool = CosTool(self)
self.port = int(port)
self.scheme = scheme
self.address = address
self.path = path
self._custom_url = None

events = self._charm.on[relation_name]
self.framework.observe(self._charm.on.upgrade_charm, self._on_lifecycle_event)
Expand Down Expand Up @@ -1326,6 +1338,11 @@ def update_endpoint(self, url: str = "", relation: Optional[Relation] = None) ->
host address change because the charmed operator becomes connected to an
Ingress after the `logging` relation is established.

To make this library reconciler-friendly, the endpoint URL was made sticky i.e., once the
endpoint is updated with a custom URL, using the public method, it cannot be unset. Users
of this method should set the "url" arg to an internal URL if the charms ingress is no
longer available.

Args:
url: An optional url value to update relation data.
relation: An optional instance of `class:ops.model.Relation` to update.
Expand All @@ -1339,7 +1356,10 @@ def update_endpoint(self, url: str = "", relation: Optional[Relation] = None) ->
else:
relations_list = [relation]

endpoint = self._endpoint(url or self._url)
if url:
self._custom_url = url

endpoint = self._endpoint(self._custom_url or self._url)

for relation in relations_list:
relation.data[self._charm.unit].update({"endpoint": json.dumps(endpoint)})
Expand Down
Loading