Skip to content

Commit

Permalink
Improve exceptions handling and add can_connect guards (#433)
Browse files Browse the repository at this point in the history
* improve exceptions handling and add can_connect guards

* always remove certs to avoid they stay on disk forever

* revert changes in charm.py. See #434

* add comment

* move can_connect() guard to `_update_logging`

* Update lib/charms/loki_k8s/v1/loki_push_api.py

Co-authored-by: Leon <[email protected]>

* Use binary pip packages for loki-tester charm

* Update charmcraft.yaml

* Update charmcraft.yaml

* Update charmcraft.yaml

---------

Co-authored-by: Leon <[email protected]>
  • Loading branch information
Abuelodelanada and sed-i authored Jul 26, 2024
1 parent 5dd8dc8 commit 4fdbf25
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
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

0 comments on commit 4fdbf25

Please sign in to comment.