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,21 +136,26 @@ def check_logs(log_handler):
logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True) logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True)
log_content = logs.stdout log_content = logs.stdout
except subprocess.CalledProcessError as e: 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+)' subscription_pattern = r'Ignored subscription creation.*id=(\d+).*err=([^\s]+)'
matches = re.finditer(subscription_pattern, log_content) matches = list(re.finditer(subscription_pattern, log_content))
last_id = None
for match in matches: if not matches:
last_id = match.group(1) log_handler.info("No subscription messages found")
return {"status": "Idle"}
if last_id: last_match = matches[-1]
log_handler.info(f"Found last subscription message, id: {last_id}") last_id = last_match.group(1)
return {"status": f"Subscription {last_id}"} error_type = last_match.group(2)
log_handler.info("No subscription message found") if error_type == "Container-set not supported":
return {"status": "Idle"} 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__": if __name__ == "__main__":
colorama.init(autoreset=True) colorama.init(autoreset=True)