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.

This commit is contained in:
vvzvlad 2025-01-19 11:34:16 +03:00
parent c062ad8e66
commit 43dbcd0a17

View File

@ -136,22 +136,27 @@ 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 last_id:
log_handler.info(f"Found last subscription message, id: {last_id}")
return {"status": f"Subscription {last_id}"}
log_handler.info("No subscription message found")
if not matches:
log_handler.info("No subscription messages found")
return {"status": "Idle"}
last_match = matches[-1]
last_id = last_match.group(1)
error_type = last_match.group(2)
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)
logger = logging.getLogger("Checker")