From 1eb2278c09bda8073d6819fc20068de13e01ff8f Mon Sep 17 00:00:00 2001 From: Marek Czernek Date: Tue, 18 Feb 2025 09:45:37 +0100 Subject: [PATCH 1/2] Rename and move health check to python --- {health-check => python/health-check}/.gitignore | 0 .../health-check}/MANIFEST.in | 0 {health-check => python/health-check}/README.md | 0 .../health-check}/pyproject.toml | 0 .../health-check/src/health_check}/__init__.py | 0 .../health-check/src/health_check}/config.py | 0 .../health-check/src/health_check}/config.toml | 0 .../src/health_check}/config/grafana/alerts.yaml | 0 .../health_check}/config/grafana/dashboard.yaml | 0 .../grafana/dashboards/dashboard_with_logs.json | 0 .../config/grafana/datasources.yaml | 7 ------- .../src/health_check}/config/loki/config.yaml | 0 .../config/prometheus/prometheus.yml | 0 .../config/templates/exporter/exporter.yaml.j2 | 0 .../supportconfig_with_logs.template.json | 0 .../config/templates/promtail/promtail.yaml.j2 | 0 .../health_check}/containers/exporter/Dockerfile | 0 .../containers/exporter/requirements.txt | 0 .../containers/grafana/Containerfile | 0 .../src/health_check}/containers/loki/Dockerfile | 0 .../src/health_check}/containers/manager.py | 8 ++++---- .../health_check}/containers/promtail/Dockerfile | 0 .../src/health_check}/exporters/exporter.py | 8 ++++---- .../health_check}/exporters/static_metrics.py | 0 .../exporters/supportconfig_exporter.py | 0 .../src/health_check}/grafana/grafana_manager.py | 6 +++--- .../src/health_check}/loki/loki_manager.py | 8 +++----- .../health-check/src/health_check}/main.py | 16 ++++++++-------- .../health-check/src/health_check}/utils.py | 0 29 files changed, 22 insertions(+), 31 deletions(-) rename {health-check => python/health-check}/.gitignore (100%) rename {health-check => python/health-check}/MANIFEST.in (100%) rename {health-check => python/health-check}/README.md (100%) rename {health-check => python/health-check}/pyproject.toml (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/__init__.py (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config.py (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config.toml (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/grafana/alerts.yaml (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/grafana/dashboard.yaml (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/grafana/dashboards/dashboard_with_logs.json (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/grafana/datasources.yaml (73%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/loki/config.yaml (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/prometheus/prometheus.yml (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/templates/exporter/exporter.yaml.j2 (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/templates/grafana_dashboard/supportconfig_with_logs.template.json (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/config/templates/promtail/promtail.yaml.j2 (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/containers/exporter/Dockerfile (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/containers/exporter/requirements.txt (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/containers/grafana/Containerfile (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/containers/loki/Dockerfile (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/containers/manager.py (93%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/containers/promtail/Dockerfile (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/exporters/exporter.py (90%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/exporters/static_metrics.py (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/exporters/supportconfig_exporter.py (100%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/grafana/grafana_manager.py (94%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/loki/loki_manager.py (95%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/main.py (86%) rename {health-check/src/uyuni_health_check => python/health-check/src/health_check}/utils.py (100%) diff --git a/health-check/.gitignore b/python/health-check/.gitignore similarity index 100% rename from health-check/.gitignore rename to python/health-check/.gitignore diff --git a/health-check/MANIFEST.in b/python/health-check/MANIFEST.in similarity index 100% rename from health-check/MANIFEST.in rename to python/health-check/MANIFEST.in diff --git a/health-check/README.md b/python/health-check/README.md similarity index 100% rename from health-check/README.md rename to python/health-check/README.md diff --git a/health-check/pyproject.toml b/python/health-check/pyproject.toml similarity index 100% rename from health-check/pyproject.toml rename to python/health-check/pyproject.toml diff --git a/health-check/src/uyuni_health_check/__init__.py b/python/health-check/src/health_check/__init__.py similarity index 100% rename from health-check/src/uyuni_health_check/__init__.py rename to python/health-check/src/health_check/__init__.py diff --git a/health-check/src/uyuni_health_check/config.py b/python/health-check/src/health_check/config.py similarity index 100% rename from health-check/src/uyuni_health_check/config.py rename to python/health-check/src/health_check/config.py diff --git a/health-check/src/uyuni_health_check/config.toml b/python/health-check/src/health_check/config.toml similarity index 100% rename from health-check/src/uyuni_health_check/config.toml rename to python/health-check/src/health_check/config.toml diff --git a/health-check/src/uyuni_health_check/config/grafana/alerts.yaml b/python/health-check/src/health_check/config/grafana/alerts.yaml similarity index 100% rename from health-check/src/uyuni_health_check/config/grafana/alerts.yaml rename to python/health-check/src/health_check/config/grafana/alerts.yaml diff --git a/health-check/src/uyuni_health_check/config/grafana/dashboard.yaml b/python/health-check/src/health_check/config/grafana/dashboard.yaml similarity index 100% rename from health-check/src/uyuni_health_check/config/grafana/dashboard.yaml rename to python/health-check/src/health_check/config/grafana/dashboard.yaml diff --git a/health-check/src/uyuni_health_check/config/grafana/dashboards/dashboard_with_logs.json b/python/health-check/src/health_check/config/grafana/dashboards/dashboard_with_logs.json similarity index 100% rename from health-check/src/uyuni_health_check/config/grafana/dashboards/dashboard_with_logs.json rename to python/health-check/src/health_check/config/grafana/dashboards/dashboard_with_logs.json diff --git a/health-check/src/uyuni_health_check/config/grafana/datasources.yaml b/python/health-check/src/health_check/config/grafana/datasources.yaml similarity index 73% rename from health-check/src/uyuni_health_check/config/grafana/datasources.yaml rename to python/health-check/src/health_check/config/grafana/datasources.yaml index 9b383a2f9046..14724ac41cbe 100644 --- a/health-check/src/uyuni_health_check/config/grafana/datasources.yaml +++ b/python/health-check/src/health_check/config/grafana/datasources.yaml @@ -15,13 +15,6 @@ datasources: timeout: '120' editable: true -- name: Prometheus - type: prometheus - access: proxy - orgId: 1 - url: http://uyuni-health-check-prometheus:9090 - editable: false - - name: infinity-ds type: yesoreyeram-infinity-datasource orgId: 1 diff --git a/health-check/src/uyuni_health_check/config/loki/config.yaml b/python/health-check/src/health_check/config/loki/config.yaml similarity index 100% rename from health-check/src/uyuni_health_check/config/loki/config.yaml rename to python/health-check/src/health_check/config/loki/config.yaml diff --git a/health-check/src/uyuni_health_check/config/prometheus/prometheus.yml b/python/health-check/src/health_check/config/prometheus/prometheus.yml similarity index 100% rename from health-check/src/uyuni_health_check/config/prometheus/prometheus.yml rename to python/health-check/src/health_check/config/prometheus/prometheus.yml diff --git a/health-check/src/uyuni_health_check/config/templates/exporter/exporter.yaml.j2 b/python/health-check/src/health_check/config/templates/exporter/exporter.yaml.j2 similarity index 100% rename from health-check/src/uyuni_health_check/config/templates/exporter/exporter.yaml.j2 rename to python/health-check/src/health_check/config/templates/exporter/exporter.yaml.j2 diff --git a/health-check/src/uyuni_health_check/config/templates/grafana_dashboard/supportconfig_with_logs.template.json b/python/health-check/src/health_check/config/templates/grafana_dashboard/supportconfig_with_logs.template.json similarity index 100% rename from health-check/src/uyuni_health_check/config/templates/grafana_dashboard/supportconfig_with_logs.template.json rename to python/health-check/src/health_check/config/templates/grafana_dashboard/supportconfig_with_logs.template.json diff --git a/health-check/src/uyuni_health_check/config/templates/promtail/promtail.yaml.j2 b/python/health-check/src/health_check/config/templates/promtail/promtail.yaml.j2 similarity index 100% rename from health-check/src/uyuni_health_check/config/templates/promtail/promtail.yaml.j2 rename to python/health-check/src/health_check/config/templates/promtail/promtail.yaml.j2 diff --git a/health-check/src/uyuni_health_check/containers/exporter/Dockerfile b/python/health-check/src/health_check/containers/exporter/Dockerfile similarity index 100% rename from health-check/src/uyuni_health_check/containers/exporter/Dockerfile rename to python/health-check/src/health_check/containers/exporter/Dockerfile diff --git a/health-check/src/uyuni_health_check/containers/exporter/requirements.txt b/python/health-check/src/health_check/containers/exporter/requirements.txt similarity index 100% rename from health-check/src/uyuni_health_check/containers/exporter/requirements.txt rename to python/health-check/src/health_check/containers/exporter/requirements.txt diff --git a/health-check/src/uyuni_health_check/containers/grafana/Containerfile b/python/health-check/src/health_check/containers/grafana/Containerfile similarity index 100% rename from health-check/src/uyuni_health_check/containers/grafana/Containerfile rename to python/health-check/src/health_check/containers/grafana/Containerfile diff --git a/health-check/src/uyuni_health_check/containers/loki/Dockerfile b/python/health-check/src/health_check/containers/loki/Dockerfile similarity index 100% rename from health-check/src/uyuni_health_check/containers/loki/Dockerfile rename to python/health-check/src/health_check/containers/loki/Dockerfile diff --git a/health-check/src/uyuni_health_check/containers/manager.py b/python/health-check/src/health_check/containers/manager.py similarity index 93% rename from health-check/src/uyuni_health_check/containers/manager.py rename to python/health-check/src/health_check/containers/manager.py index 8cc9ab0e7a25..97731b76f8c0 100644 --- a/health-check/src/uyuni_health_check/containers/manager.py +++ b/python/health-check/src/health_check/containers/manager.py @@ -1,8 +1,8 @@ """Module that contains podman-related functionality""" from typing import List -from uyuni_health_check import config -from uyuni_health_check.utils import run_command, console +from health_check import config +from health_check.utils import run_command, console def podman(cmd: List[str], verbose=False, raise_exc=True) -> List: @@ -95,9 +95,9 @@ def clean_containers(verbose=False): def create_podman_network(verbose=False): """ - Create uyuni-health-check pod where we run the containers + Create health-check pod where we run the containers - :param server: the Uyuni server to create the pod on or localhost + :param server: the server to create the pod on or localhost """ console.log("[bold]Creating podman network") diff --git a/health-check/src/uyuni_health_check/containers/promtail/Dockerfile b/python/health-check/src/health_check/containers/promtail/Dockerfile similarity index 100% rename from health-check/src/uyuni_health_check/containers/promtail/Dockerfile rename to python/health-check/src/health_check/containers/promtail/Dockerfile diff --git a/health-check/src/uyuni_health_check/exporters/exporter.py b/python/health-check/src/health_check/exporters/exporter.py similarity index 90% rename from health-check/src/uyuni_health_check/exporters/exporter.py rename to python/health-check/src/health_check/exporters/exporter.py index 0c93542504b9..0aa74772f774 100644 --- a/health-check/src/uyuni_health_check/exporters/exporter.py +++ b/python/health-check/src/health_check/exporters/exporter.py @@ -1,8 +1,8 @@ """Module that manages the supportconfig exporter container""" -from uyuni_health_check import config -from uyuni_health_check.utils import console -from uyuni_health_check.containers.manager import ( +from health_check import config +from health_check.utils import console +from health_check.containers.manager import ( image_exists, build_image, podman, @@ -14,7 +14,7 @@ def prepare_exporter(supportconfig_path: str, verbose: bool): """ Build the exporter image and deploy it on the server - :param server: the Uyuni server to deploy the exporter on + :param server: the server to deploy the exporter on """ exporter_name = config.load_prop("exporter.container_name") image = config.load_prop("exporter.image") diff --git a/health-check/src/uyuni_health_check/exporters/static_metrics.py b/python/health-check/src/health_check/exporters/static_metrics.py similarity index 100% rename from health-check/src/uyuni_health_check/exporters/static_metrics.py rename to python/health-check/src/health_check/exporters/static_metrics.py diff --git a/health-check/src/uyuni_health_check/exporters/supportconfig_exporter.py b/python/health-check/src/health_check/exporters/supportconfig_exporter.py similarity index 100% rename from health-check/src/uyuni_health_check/exporters/supportconfig_exporter.py rename to python/health-check/src/health_check/exporters/supportconfig_exporter.py diff --git a/health-check/src/uyuni_health_check/grafana/grafana_manager.py b/python/health-check/src/health_check/grafana/grafana_manager.py similarity index 94% rename from health-check/src/uyuni_health_check/grafana/grafana_manager.py rename to python/health-check/src/health_check/grafana/grafana_manager.py index 4ed4db0d2d8e..1d1bf9edd870 100644 --- a/health-check/src/uyuni_health_check/grafana/grafana_manager.py +++ b/python/health-check/src/health_check/grafana/grafana_manager.py @@ -1,9 +1,9 @@ """A module that manages the Grafana container""" import json -from uyuni_health_check import config -from uyuni_health_check.utils import console -from uyuni_health_check.containers.manager import ( +from health_check import config +from health_check.utils import console +from health_check.containers.manager import ( build_image, image_exists, container_is_running, diff --git a/health-check/src/uyuni_health_check/loki/loki_manager.py b/python/health-check/src/health_check/loki/loki_manager.py similarity index 95% rename from health-check/src/uyuni_health_check/loki/loki_manager.py rename to python/health-check/src/health_check/loki/loki_manager.py index e4efcf5384d4..2c7e12ebb47a 100644 --- a/health-check/src/uyuni_health_check/loki/loki_manager.py +++ b/python/health-check/src/health_check/loki/loki_manager.py @@ -4,11 +4,9 @@ import os import requests import zipfile -import re -import time -from uyuni_health_check import config -from uyuni_health_check.utils import HealthException, console -from uyuni_health_check.containers.manager import ( +from health_check import config +from health_check.utils import console +from health_check.containers.manager import ( build_image, image_exists, container_is_running, diff --git a/health-check/src/uyuni_health_check/main.py b/python/health-check/src/health_check/main.py similarity index 86% rename from health-check/src/uyuni_health_check/main.py rename to python/health-check/src/health_check/main.py index 4de87ee6f2e4..f75872b131e4 100644 --- a/health-check/src/uyuni_health_check/main.py +++ b/python/health-check/src/health_check/main.py @@ -4,12 +4,12 @@ import os from rich.markdown import Markdown -from uyuni_health_check.grafana.grafana_manager import prepare_grafana -import uyuni_health_check.utils as utils -from uyuni_health_check.utils import console, HealthException -from uyuni_health_check.loki.loki_manager import run_loki -from uyuni_health_check.exporters import exporter -from uyuni_health_check.containers.manager import ( +from health_check.grafana.grafana_manager import prepare_grafana +import health_check.utils as utils +from health_check.utils import console, HealthException +from health_check.loki.loki_manager import run_loki +from health_check.exporters import exporter +from health_check.containers.manager import ( create_podman_network, clean_containers, ) @@ -62,7 +62,7 @@ def cli(ctx: click.Context, supportconfig_path: str, verbose: bool): @click.pass_context def run(ctx: click.Context, from_datetime: str, to_datetime: str, since: int): """ - Start execution of Uyuni Health Check + Start execution of Health Check Build the necessary containers, deploy them, get the metrics and display them @@ -101,7 +101,7 @@ def clean(ctx: click.Context): def main(): - console.print(Markdown("# Uyuni Health Check")) + console.print(Markdown("# Health Check")) cli() # pylint: disable=no-value-for-parameter diff --git a/health-check/src/uyuni_health_check/utils.py b/python/health-check/src/health_check/utils.py similarity index 100% rename from health-check/src/uyuni_health_check/utils.py rename to python/health-check/src/health_check/utils.py From 650cfee6ef88306f99c3edf54de4fe2b2925e295 Mon Sep 17 00:00:00 2001 From: Marek Czernek Date: Tue, 18 Feb 2025 09:52:19 +0100 Subject: [PATCH 2/2] Remove python 3.6 incompatible pattern matching --- .../exporters/supportconfig_exporter.py | 48 ++++++++++--------- python/health-check/src/health_check/utils.py | 13 +++-- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/python/health-check/src/health_check/exporters/supportconfig_exporter.py b/python/health-check/src/health_check/exporters/supportconfig_exporter.py index 45d1ec462abe..f7f9922f571b 100644 --- a/python/health-check/src/health_check/exporters/supportconfig_exporter.py +++ b/python/health-check/src/health_check/exporters/supportconfig_exporter.py @@ -114,16 +114,18 @@ def parse_shared_buffers_to_mem_ratio(self, memory: int): return shared_buffers = int(shared_buffers) - match buffer_unit.lower(): - case "kb": - ... # conversion done - case "mb": - shared_buffers *= 1024 - case "gb": - shared_buffers *= 1024 * 1024 - case _: - print(f"Error when parsing shared buffer unit: {buffer_unit}") - return + + buffer_unit = buffer_unit.lower() + if buffer_unit == "kb": + ... # conversion done + elif buffer_unit == "mb": + shared_buffers *= 1024 + elif buffer_unit == "gb": + shared_buffers *= 1024 * 1024 + else: + print(f"Error when parsing shared buffer unit: {buffer_unit}") + return + self.shared_buffers_to_mem_ratio = round(shared_buffers / memory, 2) def parse_prefork_c_params(self): @@ -229,19 +231,19 @@ def _check_vol_params(self, mount: str, min_size_gb: int, fs: Dict) -> Dict: else: size, unit = float(size[:-1]), size[-1:] - match unit.lower(): - case "k": - size /= 1024 * 1024 - case "m": - size /= 1024 - case "g": - ... # already in GB - case "t": - size *= 1024 - case "n/a": - ... # no unit - case _: - print(f"Error when parsing shared buffer unit: {unit}") + unit = unit.lower() + if unit == "k": + size /= 1024 * 1024 + elif unit == "m": + size /= 1024 + elif unit == "g": + ... # already in GB + elif unit == "t": + size *= 1024 + elif unit == "n/a": + ... # no unit + else: + print(f"Error when parsing shared buffer unit: {unit}") res["too_small"] = 1 if min_size_gb > size else 0 return res diff --git a/python/health-check/src/health_check/utils.py b/python/health-check/src/health_check/utils.py index c2f51bcc582f..9e875c995d15 100644 --- a/python/health-check/src/health_check/utils.py +++ b/python/health-check/src/health_check/utils.py @@ -61,13 +61,12 @@ def _handle_text_from_process(verbose: bool, *objs: str): def _check_retcode(retcode: int): - match retcode: - case 0: - ... # success - case 127: - raise OSError("Command not found; podman is required") - case _: - raise HealthException("An error happened while running Podman") + if retcode == 0: + ... # success + elif retcode == 127: + raise OSError("Command not found; podman is required") + else: + raise HealthException("An error happened while running Podman") class HealthException(Exception):