Skip to content

Commit f8d1d38

Browse files
authored
Merge pull request #36 from canonical/IAM-618-COS-integ
feat(COS): COS integration first implementation
2 parents 2105e38 + db6a097 commit f8d1d38

File tree

8 files changed

+1140
-12
lines changed

8 files changed

+1140
-12
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ juju run openfga-k8s/leader schema-upgrade --wait 30s
2626

2727
#### New `openfga` interface:
2828

29-
Current charm provides a library for the `openfga` relation intefave. Your
29+
Current charm provides a library for the `openfga` relation interface. Your
3030
application should define an interface in `metadata.yaml`:
3131

3232
```yaml
@@ -73,6 +73,16 @@ juju remove-relation openfga-k8s tls-certificates-operator
7373

7474
Note: The TLS settings shown here are for self-signed-certificates, which are not recommended for production clusters. The TLS Certificates Operator offers a variety of configurations. Read more on the TLS Certificates Operator [here](https://charmhub.io/tls-certificates-operator).
7575

76+
## Observability
77+
This OpenFGA operator integrates with [Canonical Observability Stack](https://charmhub.io/topics/canonical-observability-stack) (COS) bundle.
78+
It comes with a Grafana dashboard and Loki and Prometheus alert rules for basic common scenarios.
79+
To integrate with the COS bundle, after you [deploy it](https://charmhub.io/topics/canonical-observability-stack/tutorials/install-microk8s#heading--deploy-the-cos-lite-bundle), you can run:
80+
```bash
81+
juju integrate openfga:grafana-dashboard grafana:grafana-dashboard
82+
juju integrate openfga:metrics-endpoint prometheus:metrics-endpoint
83+
juju integrate loki:logging openfga:log-proxy
84+
```
85+
7686
## Security
7787
Security issues in the Charmed OpenFGA k8s Operator can be reported through [LaunchPad](https://wiki.ubuntu.com/DebuggingSecurity#How%20to%20File). Please do not file GitHub issues about security issues.
7888

metadata.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,3 @@ resources:
5151
type: oci-image
5252
description: OCI image for OpenFGA
5353
upstream-source: ghcr.io/canonical/openfga:1.3.9
54-
# Temporary workaround until pebble can forward logs to Loki directly.
55-
promtail-bin:
56-
type: file
57-
description: Promtail binary for logging
58-
filename: promtail-linux

src/charm.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
DatabaseRequires,
2828
)
2929
from charms.grafana_k8s.v0.grafana_dashboard import GrafanaDashboardProvider
30-
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer
30+
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer, PromtailDigestError
3131
from charms.observability_libs.v1.kubernetes_service_patch import KubernetesServicePatch
3232
from charms.openfga_k8s.v1.openfga import OpenFGAProvider, OpenFGAStoreRequestEvent
3333
from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider
@@ -62,6 +62,7 @@
6262
LOG_FILE,
6363
LOG_PROXY_RELATION_NAME,
6464
METRIC_RELATION_NAME,
65+
OPENFGA_METRICS_HTTP_PORT,
6566
OPENFGA_RELATION_NAME,
6667
OPENFGA_SERVER_GRPC_PORT,
6768
OPENFGA_SERVER_HTTP_PORT,
@@ -111,14 +112,18 @@ def __init__(self, *args: Any) -> None:
111112
self,
112113
log_files=[LOG_FILE],
113114
relation_name=LOG_PROXY_RELATION_NAME,
114-
promtail_resource_name="promtail-bin",
115115
container_name=WORKLOAD_CONTAINER,
116116
)
117117

118118
# Prometheus metrics endpoint relation
119119
self.metrics_endpoint = MetricsEndpointProvider(
120120
self,
121-
jobs=[{"static_configs": [{"targets": [f"*:{OPENFGA_SERVER_HTTP_PORT}"]}]}],
121+
jobs=[
122+
{
123+
"metrics_path": "/metrics",
124+
"static_configs": [{"targets": [f"*:{OPENFGA_METRICS_HTTP_PORT}"]}],
125+
}
126+
],
122127
refresh_event=self.on.config_changed,
123128
relation_name=METRIC_RELATION_NAME,
124129
)
@@ -161,14 +166,20 @@ def __init__(self, *args: Any) -> None:
161166
self._on_database_changed,
162167
)
163168
self.framework.observe(self.on.database_relation_broken, self._on_database_relation_broken)
169+
self.framework.observe(
170+
self.log_proxy.on.promtail_digest_error, self._on_promtail_digest_error
171+
)
164172

165173
port_http = ServicePort(
166174
OPENFGA_SERVER_HTTP_PORT, name=f"{self.app.name}-http", protocol="TCP"
167175
)
168176
port_grpc = ServicePort(
169177
OPENFGA_SERVER_GRPC_PORT, name=f"{self.app.name}-grpc", protocol="TCP"
170178
)
171-
self.service_patcher = KubernetesServicePatch(self, [port_http, port_grpc])
179+
port_metrics = ServicePort(
180+
OPENFGA_METRICS_HTTP_PORT, name=f"{self.app.name}-metrics", protocol="TCP"
181+
)
182+
self.service_patcher = KubernetesServicePatch(self, [port_http, port_grpc, port_metrics])
172183

173184
def _on_openfga_pebble_ready(self, event: PebbleReadyEvent) -> None:
174185
"""Workload pebble ready."""
@@ -212,6 +223,10 @@ def _get_database_relation_info(self) -> Optional[Dict]:
212223
"database_name": DATABASE_NAME,
213224
}
214225

226+
def _on_promtail_digest_error(self, event: PromtailDigestError) -> None:
227+
"""Log PromtailDigestError error."""
228+
logger.error(f'got PromtailDigestError with message: "{event.message}"')
229+
215230
@property
216231
def _log_level(self) -> str:
217232
return self.config["log-level"]

src/constants.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
"OPENFGA_AUTHN_PRESHARED_KEYS",
1212
]
1313

14-
LOG_FILE = "/var/log/openfga-k8s"
14+
LOG_FILE = "/openfga-k8s.log"
1515

1616
OPENFGA_SERVER_HTTP_PORT = 8080
17+
OPENFGA_METRICS_HTTP_PORT = 2112
1718
OPENFGA_SERVER_GRPC_PORT = 8081
1819

1920
PEER_KEY_DB_MIGRATE_VERSION = "db_migrate_version"

0 commit comments

Comments
 (0)