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

Add logging relation #25

Merged
merged 9 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
apply suggestions
Signed-off-by: Robert Gildein <[email protected]>
rgildein committed Nov 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4111519aeeb0c9392c4386f570bfc33a7e072317
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
@@ -17,4 +17,4 @@
S3_RELATION_NAME = "s3-credentials"
AZURE_RELATION_NAME = "azure-credentials"
PUSHGATEWAY = "cos"
LOGGING = "logging"
LOGGING_RELATION_NAME = "logging"
6 changes: 3 additions & 3 deletions src/core/context.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
from constants import (
AZURE_RELATION_NAME,
INTEGRATION_HUB_REL,
LOGGING,
LOGGING_RELATION_NAME,
PEER,
PUSHGATEWAY,
S3_RELATION_NAME,
@@ -140,8 +140,8 @@ def services_accounts(self) -> List[ServiceAccount]:

@property
def loki_url(self) -> str | None:
"""Retrieve Loki URL form logging relations."""
if relation := self.charm.model.get_relation(LOGGING):
"""Retrieve Loki URL from logging relations."""
if relation := self.charm.model.get_relation(LOGGING_RELATION_NAME):
if units := list(relation.units):
# select the first unit, because we don't care which unit we get the URL from
return LokiURL(relation, units[0])
12 changes: 8 additions & 4 deletions src/events/logging.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
from ops import CharmBase, RelationBrokenEvent, RelationChangedEvent

from common.utils import WithLogging
from constants import LOGGING
from constants import LOGGING_RELATION_NAME
from core.context import Context
from core.workload import IntegrationHubWorkloadBase
from events.base import BaseEventHandler, compute_status, defer_when_not_ready
@@ -26,9 +26,13 @@ def __init__(self, charm: CharmBase, context: Context, workload: IntegrationHubW
self.workload = workload

# Log forwarding to Loki
self.charm._logging = LogForwarder(charm=self.charm, relation_name=LOGGING)
self.framework.observe(self.charm.on[LOGGING].relation_changed, self._on_update_loki_url)
self.framework.observe(self.charm.on[LOGGING].relation_broken, self._on_remove_loki_url)
self.charm._logging = LogForwarder(charm=self.charm, relation_name=LOGGING_RELATION_NAME)
self.framework.observe(
self.charm.on[LOGGING_RELATION_NAME].relation_changed, self._on_update_loki_url
)
self.framework.observe(
self.charm.on[LOGGING_RELATION_NAME].relation_broken, self._on_remove_loki_url
)

# define integration hub manager
self.integration_hub = IntegrationHubManager(self.workload)
4 changes: 2 additions & 2 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
from scenario.state import next_relation_id

from charm import SparkIntegrationHub
from constants import CONTAINER, LOGGING
from constants import CONTAINER, LOGGING_RELATION_NAME
from core.context import AZURE_RELATION_NAME, S3_RELATION_NAME


@@ -137,7 +137,7 @@ def logging_relation():
relation_id = next_relation_id(update=True)

return Relation(
endpoint=LOGGING,
endpoint=LOGGING_RELATION_NAME,
interface="logging",
remote_app_name="grafana-agent-k8s",
relation_id=relation_id,