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

[wip] Use shell of mimir coordinator charm as tempo #2

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
uses: canonical/observability/.github/workflows/issues.yaml@main
secrets: inherit
with:
component: mimir-coordinator
component: tempo-coordinator
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Mimir Coordinator charm for Kubernetes
# Tempo Coordinator charm for Kubernetes

[![CharmHub Badge](https://charmhub.io/mimir-coordinator-k8s/badge.svg)](https://charmhub.io/mimir-coordinator-k8s)
[![Release](https://github.com/canonical/mimir-coordinator-k8s-operator/actions/workflows/release.yaml/badge.svg)](https://github.com/canonical/mimir-coordinator-k8s-operator/actions/workflows/release.yaml)
[![CharmHub Badge](https://charmhub.io/tempo-coordinator-k8s/badge.svg)](https://charmhub.io/tempo-coordinator-k8s)
[![Release](https://github.com/canonical/tempo-coordinator-k8s-operator/actions/workflows/release.yaml/badge.svg)](https://github.com/canonical/tempo-coordinator-k8s-operator/actions/workflows/release.yaml)
[![Discourse Status](https://img.shields.io/discourse/status?server=https%3A%2F%2Fdiscourse.charmhub.io&style=flat&label=CharmHub%20Discourse)](https://discourse.charmhub.io)

## Description

This charm serves as a coordinator for a Mimir HA deployment, together with the [mimir-worker-k8s](https://github.com/canonical/mimir-worker-k8s-operator) charm.
This charm serves as a coordinator for a Tempo HA deployment, together with the [tempo-worker-k8s](https://github.com/canonical/tempo-worker-k8s-operator) charm.

## Contributing

Expand Down
20 changes: 10 additions & 10 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: mimir-coordinator-k8s
name: tempo-coordinator-k8s
assumes:
- k8s-api

docs: https://discourse.charmhub.io/t/mimir-coordinator-index/10531
docs: # TODO fill with docs

summary: Mimir coordinator
summary: Tempo coordinator

description: |
Mimir coordinator.
Tempo coordinator.

containers:
nginx:
Expand All @@ -34,14 +34,14 @@ requires:
interface: s3
limit: 1
description: |
The coordinator obtains and shares storage details with workers, enabling Mimir's access to an S3 bucket for data storage.
The coordinator obtains and shares storage details with workers, enabling Tempo's access to an S3 bucket for data storage.

logging-consumer:
interface: loki_push_api
description: |
Forward workers' built-in logging rules to the external Loki
(the coordinator, not the worker, owns all rule files).
Obtain rules and Loki's API endpoint to later send them to the mimir ruler over another
Obtain rules and Loki's API endpoint to later send them to the tempo ruler over another
relation.

ingress:
Expand All @@ -54,7 +54,7 @@ requires:
interface: tls-certificates
limit: 1
description: |
Certificate and key files for securing Mimir communications with TLS.
Certificate and key files for securing Tempo communications with TLS.

tracing:
interface: tracing
Expand All @@ -63,10 +63,10 @@ requires:
Enables sending traces to the tracing backend.

provides:
mimir-cluster:
interface: mimir_cluster
tempo-cluster:
interface: tempo_cluster
description: |
The coordinator sends the Mimir configuration to the workers, obtaining
The coordinator sends the Tempo configuration to the workers, obtaining
the roles they are configured to take on and their addressing information.

receive-remote-write:
Expand Down
88 changes: 44 additions & 44 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
from charms.traefik_k8s.v2.ingress import IngressPerAppReadyEvent, IngressPerAppRequirer
from cosl import JujuTopology
from cosl.rules import AlertRules
from mimir_cluster import MimirClusterProvider
from mimir_config import BUCKET_NAME, S3_RELATION_NAME, _S3ConfigData
from mimir_coordinator import MimirCoordinator
from tempo_cluster import TempoClusterProvider
from tempo_config import BUCKET_NAME, S3_RELATION_NAME, _S3ConfigData
from tempo_coordinator import TempoCoordinator
from nginx import CA_CERT_PATH, CERT_PATH, KEY_PATH, Nginx
from nginx_prometheus_exporter import NGINX_PROMETHEUS_EXPORTER_PORT, NginxPrometheusExporter
from ops.charm import CollectStatusEvent
Expand All @@ -48,7 +48,7 @@
logger = logging.getLogger(__name__)

NGINX_ORIGINAL_ALERT_RULES_PATH = "./src/prometheus_alert_rules/nginx"
WORKER_ORIGINAL_ALERT_RULES_PATH = "./src/prometheus_alert_rules/mimir_workers"
WORKER_ORIGINAL_ALERT_RULES_PATH = "./src/prometheus_alert_rules/tempo_workers"
CONSOLIDATED_ALERT_RULES_PATH = "./src/prometheus_alert_rules/consolidated_rules"


Expand All @@ -57,12 +57,12 @@
server_cert="server_cert_path",
extra_types=[
S3Requirer,
MimirClusterProvider,
MimirCoordinator,
TempoClusterProvider,
TempoCoordinator,
Nginx,
],
)
class MimirCoordinatorK8SOperatorCharm(ops.CharmBase):
class TempoCoordinatorK8SOperatorCharm(ops.CharmBase):
"""Charm the service."""

def __init__(self, *args: Any):
Expand All @@ -77,12 +77,12 @@ def __init__(self, *args: Any):
)
self.server_cert = CertHandler(
charm=self,
key="mimir-server-cert",
key="tempo-server-cert",
sans=[self.hostname],
)
self.s3_requirer = S3Requirer(self, S3_RELATION_NAME, BUCKET_NAME)
self.cluster_provider = MimirClusterProvider(self)
self.coordinator = MimirCoordinator(
self.cluster_provider = TempoClusterProvider(self)
self.coordinator = TempoCoordinator(
cluster_provider=self.cluster_provider,
tls_requirer=self.server_cert,
)
Expand All @@ -94,7 +94,7 @@ def __init__(self, *args: Any):
self.nginx_prometheus_exporter = NginxPrometheusExporter(self)
self.remote_write_provider = PrometheusRemoteWriteProvider(
charm=self,
server_url_func=lambda: MimirCoordinatorK8SOperatorCharm.external_url.fget(self), # type: ignore
server_url_func=lambda: TempoCoordinatorK8SOperatorCharm.external_url.fget(self), # type: ignore
endpoint_path="/api/v1/push",
)
self.tracing = TracingEndpointRequirer(self)
Expand All @@ -118,10 +118,10 @@ def __init__(self, *args: Any):
alert_rules_path=CONSOLIDATED_ALERT_RULES_PATH,
jobs=self._scrape_jobs,
refresh_event=[
self.on.mimir_cluster_relation_joined,
self.on.mimir_cluster_relation_changed,
self.on.mimir_cluster_relation_departed,
self.on.mimir_cluster_relation_broken,
self.on.tempo_cluster_relation_joined,
self.on.tempo_cluster_relation_changed,
self.on.tempo_cluster_relation_departed,
self.on.tempo_cluster_relation_broken,
],
)
self.ingress = IngressPerAppRequirer(charm=self, strip_prefix=True)
Expand All @@ -137,18 +137,18 @@ def __init__(self, *args: Any):
self._on_nginx_prometheus_exporter_pebble_ready,
)
self.framework.observe(self.server_cert.on.cert_changed, self._on_server_cert_changed)
# Mimir Cluster
# Tempo Cluster
self.framework.observe(
self.on.mimir_cluster_relation_joined, self._on_mimir_cluster_joined
self.on.tempo_cluster_relation_joined, self._on_tempo_cluster_joined
)
self.framework.observe(
self.on.mimir_cluster_relation_changed, self._on_mimir_cluster_changed
self.on.tempo_cluster_relation_changed, self._on_tempo_cluster_changed
)
self.framework.observe(
self.on.mimir_cluster_relation_departed, self._on_mimir_cluster_changed
self.on.tempo_cluster_relation_departed, self._on_tempo_cluster_changed
)
self.framework.observe(
self.on.mimir_cluster_relation_broken, self._on_mimir_cluster_changed
self.on.tempo_cluster_relation_broken, self._on_tempo_cluster_changed
)
# S3 Requirer
self.framework.observe(self.s3_requirer.on.credentials_changed, self._on_s3_changed)
Expand All @@ -171,46 +171,46 @@ def _on_config_changed(self, _: ops.ConfigChangedEvent):
"""Handle changed configuration."""
self.nginx.configure_pebble_layer(tls=self._is_tls_ready)
self._render_workers_alert_rules()
self._update_mimir_cluster()
self._update_tempo_cluster()

def _on_server_cert_changed(self, _):
self._update_cert()
self.nginx.configure_pebble_layer(tls=self._is_tls_ready)
self._update_mimir_cluster()
self._update_tempo_cluster()

def _on_mimir_cluster_joined(self, _):
def _on_tempo_cluster_joined(self, _):
self.nginx.configure_pebble_layer(tls=self._is_tls_ready)
self._render_workers_alert_rules()
self._update_mimir_cluster()
self._update_tempo_cluster()

def _on_mimir_cluster_changed(self, _):
def _on_tempo_cluster_changed(self, _):
self.nginx.configure_pebble_layer(tls=self._is_tls_ready)
self._render_workers_alert_rules()
self._update_mimir_cluster()
self._update_tempo_cluster()

def _on_mimir_cluster_departed(self, _):
def _on_tempo_cluster_departed(self, _):
self.nginx.configure_pebble_layer(tls=self._is_tls_ready)
self._render_workers_alert_rules()
self._update_mimir_cluster()
self._update_tempo_cluster()

def _on_s3_changed(self, _):
self._update_mimir_cluster()
self._update_tempo_cluster()

def _on_collect_status(self, event: CollectStatusEvent):
"""Handle start event."""
if not self.coordinator.is_coherent():
missing_roles = [role.value for role in self.coordinator.missing_roles()]
event.add_status(
ops.BlockedStatus(
f"Incoherent deployment: you are lacking some required Mimir roles "
f"Incoherent deployment: you are lacking some required Tempo roles "
f"({missing_roles})"
)
)
s3_config_data = self._get_s3_storage_config()
if not s3_config_data and self.has_multiple_workers():
event.add_status(
ops.BlockedStatus(
"When multiple units of Mimir are deployed, you must add a valid S3 relation. S3 relation missing/invalid."
"When multiple units of Tempo are deployed, you must add a valid S3 relation. S3 relation missing/invalid."
)
)

Expand All @@ -221,7 +221,7 @@ def _on_collect_status(self, event: CollectStatusEvent):
event.add_status(ops.ActiveStatus())

def _on_loki_relation_changed(self, _):
self._update_mimir_cluster()
self._update_tempo_cluster()

def _on_nginx_pebble_ready(self, _) -> None:
self.nginx.configure_pebble_layer(tls=self._is_tls_ready)
Expand Down Expand Up @@ -271,9 +271,9 @@ def _is_tls_ready(self) -> bool:
)

@property
def mimir_worker_relations(self) -> List[ops.Relation]:
def tempo_worker_relations(self) -> List[ops.Relation]:
"""Returns the list of worker relations."""
return self.model.relations.get("mimir_worker", [])
return self.model.relations.get("tempo_worker", [])

@property
def _workers_scrape_jobs(self) -> List[Dict[str, Any]]:
Expand All @@ -291,7 +291,7 @@ def _workers_scrape_jobs(self) -> List[Dict[str, Any]]:
# replaced by the coordinator topology
# https://github.com/canonical/prometheus-k8s-operator/issues/571
"relabel_configs": [
{"target_label": "juju_charm", "replacement": "mimir-worker-k8s"},
{"target_label": "juju_charm", "replacement": "tempo-worker-k8s"},
{"target_label": "juju_unit", "replacement": worker["unit"]},
{"target_label": "juju_application", "replacement": worker["app"]},
{"target_label": "juju_model", "replacement": self.model.name},
Expand Down Expand Up @@ -384,7 +384,7 @@ def _render_workers_alert_rules(self):
"model_uuid": self.model.uuid,
"application": worker["app"],
"unit": worker["unit"],
"charm_name": "mimir-worker-k8s",
"charm_name": "tempo-worker-k8s",
}
topology = JujuTopology.from_dict(topology_dict)
alert_rules = AlertRules(query_type="promql", topology=topology)
Expand All @@ -405,7 +405,7 @@ def _consolidate_nginx_rules(self):
for filename in glob.glob(os.path.join(NGINX_ORIGINAL_ALERT_RULES_PATH, "*.*")):
shutil.copy(filename, f"{CONSOLIDATED_ALERT_RULES_PATH}/")

def _update_mimir_cluster(self): # common exit hook
def _update_tempo_cluster(self): # common exit hook
"""Build the config and publish everything to the application databag."""
if not self.coordinator.is_coherent():
return
Expand All @@ -416,7 +416,7 @@ def _update_mimir_cluster(self): # common exit hook
# On every function call, we always publish everything to the databag; however, if there
# are no changes, Juju will safely ignore the updates
self.cluster_provider.publish_data(
mimir_config=self.coordinator.build_config(
tempo_config=self.coordinator.build_config(
s3_config_data=s3_config_data, tls_enabled=tls
),
loki_endpoints=self.loki_endpoints_by_unit,
Expand All @@ -426,23 +426,23 @@ def _update_mimir_cluster(self): # common exit hook
self.publish_grant_secrets()

def has_multiple_workers(self) -> bool:
"""Return True if there are multiple workers forming the Mimir cluster."""
mimir_cluster_relations = self.model.relations.get("mimir-cluster", [])
"""Return True if there are multiple workers forming the Tempo cluster."""
tempo_cluster_relations = self.model.relations.get("tempo-cluster", [])
remote_units_count = sum(
len(relation.units)
for relation in mimir_cluster_relations
for relation in tempo_cluster_relations
if relation.app != self.model.app
)
return remote_units_count > 1

def publish_grant_secrets(self) -> None:
"""Publish and Grant secrets to the mimir-cluster relation."""
"""Publish and Grant secrets to the tempo-cluster relation."""
secrets = {
"private_key_secret_id": self.server_cert.private_key_secret_id,
"ca_server_cert_secret_id": self.server_cert.ca_server_cert_secret_id,
}

relations = self.model.relations["mimir-cluster"]
relations = self.model.relations["tempo-cluster"]
for relation in relations:
relation.data[self.model.app]["secrets"] = json.dumps(secrets)
logger.debug("Secrets published")
Expand Down Expand Up @@ -508,4 +508,4 @@ def _update_cert(self):


if __name__ == "__main__": # pragma: nocover
ops.main.main(MimirCoordinatorK8SOperatorCharm)
ops.main.main(TempoCoordinatorK8SOperatorCharm)
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"includeVars": true,
"keepTime": true,
"tags": [
"mimir"
"tempo"
],
"targetBlank": false,
"title": "Mimir dashboards",
"title": "Tempo dashboards",
"type": "dashboards"
}
],
Expand Down Expand Up @@ -3334,7 +3334,7 @@
"schemaVersion": 37,
"style": "dark",
"tags": [
"mimir"
"tempo"
],
"templating": {
"list": [
Expand Down Expand Up @@ -3462,10 +3462,10 @@
"current": {
"selected": true,
"text": [
"juju_mimir-self_ad905178-0b39-4676-891e-f2d33079ce73_prometheus_0"
"juju_tempo-self_ad905178-0b39-4676-891e-f2d33079ce73_prometheus_0"
],
"value": [
"juju_mimir-self_ad905178-0b39-4676-891e-f2d33079ce73_prometheus_0"
"juju_tempo-self_ad905178-0b39-4676-891e-f2d33079ce73_prometheus_0"
]
},
"hide": 0,
Expand Down Expand Up @@ -3512,7 +3512,7 @@
]
},
"timezone": "utc",
"title": "Mimir / Alertmanager",
"title": "Tempo / Alertmanager",
"uid": "b0d38d318bbddd80476246d4930f9e55",
"version": 1,
"weekStart": ""
Expand Down
Loading
Loading