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

Generate S3 config for mimir workers #15

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Changes from 2 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
59 changes: 39 additions & 20 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -194,30 +196,47 @@ 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()
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")}
}

# Define a list of keys, subkeys, and folders in the Mimir config
# that need to be under the common root data directory
data_mapping = [
IbraAoad marked this conversation as resolved.
Show resolved Hide resolved
("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:
IbraAoad marked this conversation as resolved.
Show resolved Hide resolved
# 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)
IbraAoad marked this conversation as resolved.
Show resolved Hide resolved
# 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]:
Expand Down