From 43dbcd0a172f80d38db9862daceefb90bb5174dd Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sun, 19 Jan 2025 11:34:16 +0300 Subject: [PATCH] Refactor check_logs function in checker.py to enhance subscription message handling. Updated regex to capture error types alongside subscription IDs, improving log analysis. Added logging for cases with no matches and refined status messages based on error type, enhancing clarity in health check reporting. --- checker.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/checker.py b/checker.py index 691ce82..9e365f0 100644 --- a/checker.py +++ b/checker.py @@ -136,21 +136,26 @@ def check_logs(log_handler): logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True) log_content = logs.stdout except subprocess.CalledProcessError as e: - raise RuntimeError(f"Error running docker logs: {e}") from e + raise RuntimeError(f"Error running docker logs: {e}") - subscription_pattern = r'Ignored subscription creation.*id=(\d+)' - matches = re.finditer(subscription_pattern, log_content) - last_id = None + subscription_pattern = r'Ignored subscription creation.*id=(\d+).*err=([^\s]+)' + matches = list(re.finditer(subscription_pattern, log_content)) - for match in matches: - last_id = match.group(1) + if not matches: + log_handler.info("No subscription messages found") + return {"status": "Idle"} - if last_id: - log_handler.info(f"Found last subscription message, id: {last_id}") - return {"status": f"Subscription {last_id}"} + last_match = matches[-1] + last_id = last_match.group(1) + error_type = last_match.group(2) - log_handler.info("No subscription message found") - return {"status": "Idle"} + if error_type == "Container-set not supported": + status = f"Container error (id: {last_id})" + else: + status = f"Subscription {last_id}" + + log_handler.info(f"Found subscription message: id={last_id}, error={error_type}") + return {"status": status} if __name__ == "__main__": colorama.init(autoreset=True)