Skip to content

Commit

Permalink
Merge e068f8d into e7e5384
Browse files Browse the repository at this point in the history
  • Loading branch information
javierdelapuente authored Feb 20, 2025
2 parents e7e5384 + e068f8d commit 0e57c3c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@


import functools
import json
import logging
import pathlib
from typing import Any, Callable, Sequence, TypeVar

import ops
Expand Down Expand Up @@ -295,6 +297,25 @@ def _ensure_reconcile_timer_is_active(self) -> None:
logger.error("Reconciliation event timer is not activated")
self._set_reconcile_timer()

def _log_charm_metrics(self) -> None:
"""Log information as a substitute for metrics."""
juju_charm_path = pathlib.Path(".juju-charm")
juju_charm = None
# .juju-charm is not part of the public interface of Juju,
# and could disappear in a future release.
try:
if juju_charm_path.exists():
juju_charm = juju_charm_path.read_text(encoding="utf-8").strip()
log = {
"log_type": "update_state",
"juju_charm": juju_charm,
"unit_status": self.unit.status.name,
}
logstr = json.dumps(log)
logger.info(logstr)
except (AttributeError, TypeError, ValueError):
logger.exception("Error preparing log metrics")

@staticmethod
def _log_juju_processes() -> None:
"""Log the running Juju processes.
Expand Down Expand Up @@ -471,6 +492,7 @@ def _on_update_status(self, _: UpdateStatusEvent) -> None:
"""Handle the update of charm status."""
self._ensure_reconcile_timer_is_active()
self._log_juju_processes()
self._log_charm_metrics()

@catch_charm_errors
def _on_stop(self, _: StopEvent) -> None:
Expand Down

0 comments on commit 0e57c3c

Please sign in to comment.