From b5386682f0f4cd9b2d696c248e4a12ec0ddb4c8f Mon Sep 17 00:00:00 2001 From: IbraAoad Date: Wed, 13 Dec 2023 15:29:18 +0200 Subject: [PATCH 1/4] mimir-s3 --- src/charm.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/charm.py b/src/charm.py index 2f7f09a..f707b24 100755 --- a/src/charm.py +++ b/src/charm.py @@ -201,23 +201,26 @@ def _set_data_dirs(self, config: Dict[str, Any]) -> dict: https://grafana.com/docs/mimir/latest/references/configuration-parameters/ """ config = config.copy() - for key, folder in ( - ("alertmanager", "data-alertmanager"), - ("compactor", "data-compactor"), - ): - if key not in config: - config[key] = {} - config[key]["data_dir"] = str(self._root_data_dir / folder) - - # blocks_storage: - # bucket_store: - # sync_dir: /etc/mimir/tsdb-sync - # data_dir: /data/tsdb-sync - if config.get("blocks_storage"): - config["blocks_storage"] = { - "bucket_store": {"sync_dir": str(self._root_data_dir / "tsdb-sync")} - } - + data_mapping = [ + ("alertmanager", "data_dir", "data-alertmanager"), + ("alertmanager_storage", "filesystem", "data-alertmanager-recovery"), + ("compactor", "data_dir", "data-compactor"), + ("ruler", "rule_path", "data-ruler"), + ("ruler_storage", "filesystem", "ruler"), + ("blocks_storage", "filesystem", "blocks"), + ("blocks_storage", "tsdb", "tsdb"), + ("blocks_storage", "bucket_store", "tsdb-sync"), + ] + + for key, subkey, folder in data_mapping: + config.setdefault(key, {}) + if subkey in config[key]: + if "data_dir" == subkey or subkey == "rule_path": + config[key][subkey] = str(self._root_data_dir / folder) + elif "filesystem" == subkey or subkey == "tsdb": + config[key][subkey] = {"dir": str(self._root_data_dir / folder)} + elif "bucket_store" == subkey: + config[key][subkey] = {"sync_dir": str(self._root_data_dir / folder)} return config def _running_mimir_config(self) -> Optional[dict]: From 609f9f0a66c6a29dd63ec6fa2c0e6a66e4286687 Mon Sep 17 00:00:00 2001 From: IbraAoad Date: Thu, 14 Dec 2023 15:44:42 +0200 Subject: [PATCH 2/4] refactoring _set_data_dirs comments --- src/charm.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/charm.py b/src/charm.py index f707b24..0f82aef 100755 --- a/src/charm.py +++ b/src/charm.py @@ -183,6 +183,8 @@ def _update_mimir_config(self) -> bool: logger.warning("cannot update mimir config: coordinator hasn't published one yet.") return False + # Data published by the coordinator won't have the actual common root data directory used by workers + # Update the configuration with data directory paths using the _set_data_dirs method config = self._set_data_dirs(mimir_config) if self._running_mimir_config() != config: @@ -194,13 +196,16 @@ def _update_mimir_config(self) -> bool: return False def _set_data_dirs(self, config: Dict[str, Any]) -> dict: - """Set the data-dirs in the config we received from the coordinator. + """Set the data directories in the received config from the coordinator. - - Place all data dirs under a common root data dir, so files are persisted across upgrades. - Following the default names from official docs: - https://grafana.com/docs/mimir/latest/references/configuration-parameters/ + - All data directories are placed under a common root data directory to persist + files across upgrades. The naming follows the default conventions from the + official Mimir docs: https://grafana.com/docs/mimir/latest/references/configuration-parameters/ """ config = config.copy() + + # Define a list of keys, subkeys, and folders in the Mimir config + # that need to be under the common root data directory data_mapping = [ ("alertmanager", "data_dir", "data-alertmanager"), ("alertmanager_storage", "filesystem", "data-alertmanager-recovery"), @@ -212,13 +217,24 @@ def _set_data_dirs(self, config: Dict[str, Any]) -> dict: ("blocks_storage", "bucket_store", "tsdb-sync"), ] + # The Mimir coordinator doesn't know the actual location of where the data + # will reside in the workers. The following loop updates the path of each key + # in the data_mapping list to match the actual common root data directory where + # the data will reside. for key, subkey, folder in data_mapping: + # Ensure the key exists in the config dictionary config.setdefault(key, {}) + + # Check if the subkey exists in the corresponding key's configuration if subkey in config[key]: + # Update the subkey based on its type + # Both "data_dir" and "rule_path" in Mimir config don't have subkeys if "data_dir" == subkey or subkey == "rule_path": config[key][subkey] = str(self._root_data_dir / folder) + # Both "filesystem" and "tsdb" in Mimir config have a subkey "dir" elif "filesystem" == subkey or subkey == "tsdb": config[key][subkey] = {"dir": str(self._root_data_dir / folder)} + # "bucket_store" in Mimir config has a subkey "sync_dir" elif "bucket_store" == subkey: config[key][subkey] = {"sync_dir": str(self._root_data_dir / folder)} return config From dc362e6faa4ed86259fafd209729bf20d69a8054 Mon Sep 17 00:00:00 2001 From: IbraAoad Date: Mon, 8 Jan 2024 17:12:52 +0200 Subject: [PATCH 3/4] using hardcoded common root data directory --- src/charm.py | 56 +++------------------------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) diff --git a/src/charm.py b/src/charm.py index 0f82aef..c0e29ce 100755 --- a/src/charm.py +++ b/src/charm.py @@ -15,8 +15,7 @@ import logging import re import socket -from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import List, Optional import yaml from charms.mimir_coordinator_k8s.v0.mimir_cluster import ( @@ -51,7 +50,6 @@ class MimirWorkerK8SOperatorCharm(CharmBase): def __init__(self, *args): super().__init__(*args) self._container = self.unit.get_container(self._name) - self._root_data_dir = Path(self.meta.containers["mimir"].mounts["data"].location) self.topology = JujuTopology.from_charm(self) self.mimir_cluster = MimirClusterRequirer(self) @@ -183,62 +181,14 @@ def _update_mimir_config(self) -> bool: logger.warning("cannot update mimir config: coordinator hasn't published one yet.") return False - # Data published by the coordinator won't have the actual common root data directory used by workers - # Update the configuration with data directory paths using the _set_data_dirs method - config = self._set_data_dirs(mimir_config) - - if self._running_mimir_config() != config: - config_as_yaml = yaml.safe_dump(config) + if self._running_mimir_config() != mimir_config: + config_as_yaml = yaml.safe_dump(mimir_config) self._container.push(MIMIR_CONFIG, config_as_yaml, make_dirs=True) logger.info("Pushed new Mimir configuration") return True return False - def _set_data_dirs(self, config: Dict[str, Any]) -> dict: - """Set the data directories in the received config from the coordinator. - - - All data directories are placed under a common root data directory to persist - files across upgrades. The naming follows the default conventions from the - official Mimir docs: https://grafana.com/docs/mimir/latest/references/configuration-parameters/ - """ - config = config.copy() - - # Define a list of keys, subkeys, and folders in the Mimir config - # that need to be under the common root data directory - data_mapping = [ - ("alertmanager", "data_dir", "data-alertmanager"), - ("alertmanager_storage", "filesystem", "data-alertmanager-recovery"), - ("compactor", "data_dir", "data-compactor"), - ("ruler", "rule_path", "data-ruler"), - ("ruler_storage", "filesystem", "ruler"), - ("blocks_storage", "filesystem", "blocks"), - ("blocks_storage", "tsdb", "tsdb"), - ("blocks_storage", "bucket_store", "tsdb-sync"), - ] - - # The Mimir coordinator doesn't know the actual location of where the data - # will reside in the workers. The following loop updates the path of each key - # in the data_mapping list to match the actual common root data directory where - # the data will reside. - for key, subkey, folder in data_mapping: - # Ensure the key exists in the config dictionary - config.setdefault(key, {}) - - # Check if the subkey exists in the corresponding key's configuration - if subkey in config[key]: - # Update the subkey based on its type - # Both "data_dir" and "rule_path" in Mimir config don't have subkeys - if "data_dir" == subkey or subkey == "rule_path": - config[key][subkey] = str(self._root_data_dir / folder) - # Both "filesystem" and "tsdb" in Mimir config have a subkey "dir" - elif "filesystem" == subkey or subkey == "tsdb": - config[key][subkey] = {"dir": str(self._root_data_dir / folder)} - # "bucket_store" in Mimir config has a subkey "sync_dir" - elif "bucket_store" == subkey: - config[key][subkey] = {"sync_dir": str(self._root_data_dir / folder)} - return config - def _running_mimir_config(self) -> Optional[dict]: """Return the Mimir config as dict, or None if retrieval failed.""" if not self._container.can_connect(): From 673e9bf56c79e126c61911e2ea8497ef6eec1bd7 Mon Sep 17 00:00:00 2001 From: IbraAoad Date: Mon, 8 Jan 2024 18:23:05 +0200 Subject: [PATCH 4/4] Document Coordinator's Path Dependency --- metadata.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/metadata.yaml b/metadata.yaml index cb8edcd..f1e1393 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -21,6 +21,10 @@ storage: type: filesystem description: Common storage point for all components +# The Mimir coordinator has a hardcoded dependency on the mount location, +# and it relies on this path to generate the configuration. +# Any changes to this path may affect the coordinator's functionality. + containers: mimir: resource: mimir-image