Skip to content

Commit

Permalink
feat: implement log forwarding (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruyaume authored Mar 1, 2024
1 parent 4ee3b59 commit 4fd11f0
Show file tree
Hide file tree
Showing 8 changed files with 2,740 additions and 10 deletions.
2,696 changes: 2,696 additions & 0 deletions lib/charms/loki_k8s/v1/loki_push_api.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ requires:
interface: fiveg_nrf
certificates:
interface: tls-certificates
logging:
interface: loki_push_api

assumes:
- k8s-api
- juju >= 3.4
5 changes: 3 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
jinja2
juju==3.3.1.1
juju
ops
pydantic<3.0
pydantic
pytest-interface-tester
jsonschema
cryptography
cosl
11 changes: 8 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ attrs==23.2.0
# referencing
bcrypt==4.1.2
# via paramiko
cachetools==5.3.2
cachetools==5.3.3
# via google-auth
certifi==2024.2.2
# via
Expand All @@ -26,6 +26,8 @@ charset-normalizer==3.3.2
# via requests
click==8.1.7
# via typer
cosl==0.0.8
# via -r requirements.in
cryptography==42.0.5
# via
# -r requirements.in
Expand Down Expand Up @@ -61,8 +63,9 @@ oauthlib==3.2.2
ops==2.11.0
# via
# -r requirements.in
# cosl
# ops-scenario
ops-scenario==6.0.1
ops-scenario==6.0.2
# via pytest-interface-tester
packaging==23.2
# via
Expand Down Expand Up @@ -104,12 +107,13 @@ pytest==8.0.2
# via pytest-interface-tester
pytest-interface-tester==2.0.1
# via -r requirements.in
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via kubernetes
pytz==2024.1
# via pyrfc3339
pyyaml==6.0.1
# via
# cosl
# juju
# kubernetes
# ops
Expand Down Expand Up @@ -144,6 +148,7 @@ typer==0.7.0
# via pytest-interface-tester
typing-extensions==4.10.0
# via
# cosl
# pydantic
# pydantic-core
# typing-inspect
Expand Down
3 changes: 3 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Optional

from charms.data_platform_libs.v0.data_interfaces import DatabaseRequires # type: ignore[import]
from charms.loki_k8s.v1.loki_push_api import LogForwarder # type: ignore[import]
from charms.sdcore_nrf_k8s.v0.fiveg_nrf import NRFRequires # type: ignore[import]
from charms.tls_certificates_interface.v3.tls_certificates import ( # type: ignore[import]
CertificateExpiringEvent,
Expand Down Expand Up @@ -38,6 +39,7 @@
CSR_NAME = "pcf.csr"
CERTIFICATE_NAME = "pcf.pem"
CERTIFICATE_COMMON_NAME = "pcf.sdcore"
LOGGING_RELATION_NAME = "logging"


class PCFOperatorCharm(CharmBase):
Expand All @@ -56,6 +58,7 @@ def __init__(self, *args):
self._nrf_requires = NRFRequires(charm=self, relation_name=NRF_RELATION_NAME)
self.unit.set_ports(PCF_SBI_PORT)
self._certificates = TLSCertificatesRequiresV3(self, "certificates")
self._logging = LogForwarder(charm=self, relation_name=LOGGING_RELATION_NAME)
self.framework.observe(self.on.update_status, self._configure_sdcore_pcf)
self.framework.observe(self.on.database_relation_joined, self._configure_sdcore_pcf)
self.framework.observe(self.on.database_relation_broken, self._on_database_relation_broken)
Expand Down
5 changes: 5 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ output "certificates_endpoint" {
description = "Name of the endpoint used to integrate with the TLS certificates provider."
value = "certificates"
}

output "logging_endpoint" {
description = "Name of the endpoint used to integrate with the Logging provider."
value = "logging"
}
4 changes: 2 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bcrypt==4.1.2
# paramiko
black==24.2.0
# via -r test-requirements.in
cachetools==5.3.2
cachetools==5.3.3
# via
# -c requirements.txt
# google-auth
Expand Down Expand Up @@ -203,7 +203,7 @@ pytest-asyncio==0.21.1
# pytest-operator
pytest-operator==0.34.0
# via -r test-requirements.in
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via
# -c requirements.txt
# kubernetes
Expand Down
23 changes: 20 additions & 3 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
NRF_APP_NAME = "sdcore-nrf-k8s"
DATABASE_APP_NAME = "mongodb-k8s"
TLS_PROVIDER_NAME = "self-signed-certificates"
GRAFANA_AGENT_APP_NAME = "grafana-agent-k8s"


async def _deploy_database(ops_test: OpsTest):
"""Deploy a MongoDB."""
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
DATABASE_APP_NAME,
application_name=DATABASE_APP_NAME,
channel="6/beta",
Expand All @@ -31,7 +33,8 @@ async def _deploy_database(ops_test: OpsTest):

async def _deploy_nrf(ops_test: OpsTest):
"""Deploy a NRF."""
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
NRF_APP_NAME,
application_name=NRF_APP_NAME,
channel="edge",
Expand All @@ -40,13 +43,23 @@ async def _deploy_nrf(ops_test: OpsTest):


async def _deploy_tls_provider(ops_test: OpsTest):
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
TLS_PROVIDER_NAME,
application_name=TLS_PROVIDER_NAME,
channel="beta",
)


async def _deploy_grafana_agent(ops_test: OpsTest):
assert ops_test.model
await ops_test.model.deploy(
GRAFANA_AGENT_APP_NAME,
application_name=GRAFANA_AGENT_APP_NAME,
channel="stable",
)


@pytest.fixture(scope="module")
@pytest.mark.abort_on_fail
async def build_and_deploy(ops_test: OpsTest):
Expand All @@ -64,6 +77,7 @@ async def build_and_deploy(ops_test: OpsTest):
await _deploy_database(ops_test)
await _deploy_nrf(ops_test)
await _deploy_tls_provider(ops_test)
await _deploy_grafana_agent(ops_test)


@pytest.mark.abort_on_fail
Expand All @@ -87,6 +101,9 @@ async def test_relate_and_wait_for_active_status(ops_test: OpsTest, build_and_de
relation1=f"{APPLICATION_NAME}:fiveg_nrf", relation2=NRF_APP_NAME
)
await ops_test.model.integrate(relation1=APPLICATION_NAME, relation2=TLS_PROVIDER_NAME)
await ops_test.model.integrate(
relation1=f"{APPLICATION_NAME}:logging", relation2=GRAFANA_AGENT_APP_NAME
)

await ops_test.model.wait_for_idle(
apps=[APPLICATION_NAME],
Expand Down

0 comments on commit 4fd11f0

Please sign in to comment.