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:
parent
c062ad8e66
commit
43dbcd0a17
29
checker.py
29
checker.py
@ -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)
|
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")
|
||||||
|
|
||||||
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")
|
|
||||||
return {"status": "Idle"}
|
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__":
|
if __name__ == "__main__":
|
||||||
colorama.init(autoreset=True)
|
colorama.init(autoreset=True)
|
||||||
logger = logging.getLogger("Checker")
|
logger = logging.getLogger("Checker")
|
||||||
|
Loading…
Reference in New Issue
Block a user