From 18b306a53d629870948a764f506cafd2619b1ed3 Mon Sep 17 00:00:00 2001 From: Rafael te Boekhorst Date: Wed, 27 Mar 2024 13:50:07 +0100 Subject: [PATCH] fix: adapt example to have corret config path, add typing, add rudimentary makefile command to download config from testbed Signed-off-by: Rafael te Boekhorst --- Makefile | 5 +++ src/config.example.yaml | 2 +- src/rookify/logger.py | 41 ++++++++++++++++-------- src/rookify/modules/analyze_ceph/main.py | 2 ++ src/rookify/modules/migrate_osds/main.py | 4 ++- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index a99da0d..c589b7d 100644 --- a/Makefile +++ b/Makefile @@ -50,3 +50,8 @@ run-local-rookify: ## Runs rookify in the local development environment (require $(eval PYTHONPATH="${PYTHONPATH}:$(pwd)/src") source ./.venv/bin/activate && \ cd src && python3 -m rookify + +download-ceph-folder-from-testbed: + ssh testbed-node-0 'sudo cp -r /etc/ceph ~/ceph_configs && sudo chown -R $$USER:$$USER ~/ceph_configs' + scp -r testbed-node-0:ceph_configs ./.ceph + ssh testbed-node-0 'rm -rf ~/ceph_configs' diff --git a/src/config.example.yaml b/src/config.example.yaml index a99064f..d382e8e 100644 --- a/src/config.example.yaml +++ b/src/config.example.yaml @@ -8,7 +8,7 @@ logging: renderer: console # or: json ceph: - conf_file: ../.ceph/ceph.conf + config: ../.ceph/ceph.conf keyring: ../.ceph/ceph.client.admin.keyring ssh: diff --git a/src/rookify/logger.py b/src/rookify/logger.py index e3eb21d..6c2ea96 100644 --- a/src/rookify/logger.py +++ b/src/rookify/logger.py @@ -1,22 +1,35 @@ import structlog import logging -def configure_logging(config): - LOG_LEVEL = getattr(logging, config['logging']['level']) - LOG_TIME_FORMAT = config['logging']['format']['time'] - LOG_RENDERER = config['logging']['format']['renderer'] +from typing import Any, Dict + + +def configure_logging(config: Dict[str, Any]) -> None: + LOG_LEVEL = getattr(logging, config["logging"]["level"]) + LOG_TIME_FORMAT = config["logging"]["format"]["time"] + LOG_RENDERER = config["logging"]["format"]["renderer"] + structlog.configure( + wrapper_class=structlog.make_filtering_bound_logger(LOG_LEVEL), + processors=[ + structlog.processors.TimeStamper(fmt=LOG_TIME_FORMAT), + structlog.processors.add_log_level, + ], + ) + if LOG_RENDERER == "console": + structlog.configure( + processors=[ + *structlog.get_config()["processors"], + structlog.dev.ConsoleRenderer(), + ] + ) + else: structlog.configure( - wrapper_class=structlog.make_filtering_bound_logger(LOG_LEVEL), processors=[ - structlog.processors.TimeStamper(fmt=LOG_TIME_FORMAT), - structlog.processors.add_log_level + *structlog.get_config()["processors"], + structlog.processors.JSONRenderer(), ] ) - if LOG_RENDERER == "console": - structlog.configure(processors=[*structlog.get_config()["processors"], structlog.dev.ConsoleRenderer()]) - else: - structlog.configure(processors=[*structlog.get_config()["processors"], structlog.processors.JSONRenderer()]) - -def getLogger(): + + +def getLogger() -> structlog.getLogger: return structlog.get_logger() - \ No newline at end of file diff --git a/src/rookify/modules/analyze_ceph/main.py b/src/rookify/modules/analyze_ceph/main.py index 7c166e0..f462a2b 100644 --- a/src/rookify/modules/analyze_ceph/main.py +++ b/src/rookify/modules/analyze_ceph/main.py @@ -6,6 +6,7 @@ from rookify.logger import getLogger + class AnalyzeCephHandler(ModuleHandler): def run(self) -> Any: commands = ["mon dump", "osd dump", "device ls", "fs dump", "node ls"] @@ -22,6 +23,7 @@ def run(self) -> Any: leaf[part] = self.ceph.mon_command(command) leaf = leaf[part] + log.info("Dictionary created") results["ssh"] = dict() results["ssh"]["osd"] = dict() for node, values in results["node"]["ls"]["osd"].items(): diff --git a/src/rookify/modules/migrate_osds/main.py b/src/rookify/modules/migrate_osds/main.py index 6e7c973..b8da732 100644 --- a/src/rookify/modules/migrate_osds/main.py +++ b/src/rookify/modules/migrate_osds/main.py @@ -6,6 +6,7 @@ from rookify.logger import getLogger + class MigrateOSDsHandler(ModuleHandler): def preflight(self) -> None: pass @@ -13,6 +14,7 @@ def preflight(self) -> None: # raise ModuleException('test error') def run(self) -> Any: + log = getLogger() osd_config: Dict[str, Any] = dict() for node, osds in self._data["analyze_ceph"]["node"]["ls"]["osd"].items(): osd_config[node] = {"osds": {}} @@ -35,5 +37,5 @@ def run(self) -> Any: osd["device"] = device break - print(osd_config) + log.info(osd_config) return {}