Skip to content
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

Improve exceptions handling and add can_connect guards #433

Merged
merged 10 commits into from
Jul 26, 2024
6 changes: 4 additions & 2 deletions lib/charms/loki_k8s/v1/loki_push_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def _alert_rules_error(self, event):

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

PYDEPS = ["cosl"]

Expand Down Expand Up @@ -2562,7 +2562,9 @@ def _update_logging(self, _):
return

for container in self._charm.unit.containers.values():
self._update_endpoints(container, loki_endpoints)
if container.can_connect():
self._update_endpoints(container, loki_endpoints)
# else: `_update_endpoints` will be called on pebble-ready anyway.

def _retrieve_endpoints_from_relation(self) -> dict:
loki_endpoints = {}
Expand Down
3 changes: 3 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ def _update_config(self, config: dict) -> bool:
return False

def _update_cert(self):
# If Pebble is not ready, we do not proceed.
# This code will end up running anyway when Pebble is ready, because
# it will eventually be called from the `_configure()` method.
if not self._loki_container.can_connect():
return

Expand Down
10 changes: 10 additions & 0 deletions tests/integration/log-forwarder-tester/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ parts:
charm:
build-packages:
- git

charm-binary-python-packages:
# For v2.tls_certificates
- cryptography
- jsonschema

# For v1.alertmanager_dispatch & v1.tracing
- pydantic>=2

- cosl
10 changes: 10 additions & 0 deletions tests/integration/log-proxy-tester/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ parts:
charm:
build-packages:
- git

charm-binary-python-packages:
# For v2.tls_certificates
- cryptography
- jsonschema

# For v1.alertmanager_dispatch & v1.tracing
- pydantic>=2

- cosl
11 changes: 11 additions & 0 deletions tests/integration/loki-tester/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ bases:
run-on:
- name: "ubuntu"
channel: "20.04"
parts:
charm:
charm-binary-python-packages:
# For v2.tls_certificates
- cryptography
- jsonschema

# For v1.alertmanager_dispatch & v1.tracing
- pydantic>=2

- cosl
3 changes: 3 additions & 0 deletions tests/unit/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ def __init__(self, args):

def wait_output(self):
return ("v0.1.0", "")

def wait(self):
return ("v0.1.0", "")
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ deps =
black
ruff
commands =
ruff --fix {[vars]all_path}
ruff check --fix {[vars]all_path}
black {[vars]all_path}

# codespell pinned cause version 2.3.0 mistakenly considers joined words such as "assertIn" invalid
Expand All @@ -46,7 +46,7 @@ deps =
commands =
codespell {[vars]lib_path}
codespell . --skip .git --skip .tox --skip build --skip lib --skip venv --skip .mypy_cache
ruff {[vars]all_path}
ruff check {[vars]all_path}
black --check --diff {[vars]all_path}

[testenv:static-{charm,lib}]
Expand Down
Loading