From 1e38b5aca616744fff66a3e8430b8ca6a69acf3f Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sun, 19 Jan 2025 09:44:17 +0300 Subject: [PATCH] Refactor check_logs function in checker.py to focus on subscription completion detection. Removed dynamic error and proof speed logging, simplifying the health check process. Now returns a status based on subscription completion, enhancing clarity and maintainability of the health check logic. --- checker.py | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/checker.py b/checker.py index 69d51e2..1f0d589 100644 --- a/checker.py +++ b/checker.py @@ -117,41 +117,21 @@ class GRIST: def check_logs(log_handler): - error_count = 0 - proved_count = 0 - proof_speeds = deque(maxlen=100) - try: logs = subprocess.run(['docker', 'compose', 'logs', '--since', '2h'], cwd='/root/node/', capture_output=True, text=True, check=True) log_content = logs.stdout except subprocess.CalledProcessError as e: raise RuntimeError(f"Error running docker compose logs: {e}") from e - for line in log_content.split('\n'): - if "error" in line.lower(): - log_handler.error(f"Error: {line}") - error_count += 1 - if "Proved step" in line: - proved_count += 1 - log_handler.info(f"Proved step: {line}") - - proof_speed_match = re.search(r'Proved step \d+ at (\d+\.\d+) proof cycles/sec', line) - if proof_speed_match: - current_speed = float(proof_speed_match.group(1)) - proof_speeds.append(current_speed) - log_handler.info(f"Current proof speed: {current_speed} proof cycles/sec") - - # Calculate average proof speed from the collected values - avg_proof_speed = sum(proof_speeds) / len(proof_speeds) if proof_speeds else 0 - log_handler.info(f"Average proof speed (last {len(proof_speeds)} values): {avg_proof_speed:.2f} proof cycles/sec") + subscription_pattern = r'Ignored subscription creation.*id=(\d+) err=Subscription completed' + match = re.search(subscription_pattern, log_content) + if match: + subscription_id = match.group(1) + log_handler.info(f"Found subscription completion message, id: {subscription_id}") + return {"status": f"Subscription {subscription_id}"} - data = { - "errors": error_count, - "proved_steps": proved_count/10, - "proof_speed": int(avg_proof_speed) - } - log_handler.info(f"Result: {data}") - return data + log_handler.info("No subscription completion message found") + return {"status": "Idle"} if __name__ == "__main__": colorama.init(autoreset=True) @@ -180,11 +160,9 @@ if __name__ == "__main__": for attempt in range(3): try: - #result = check_logs(logger) - #data = f"{result['proved_steps']}/{result['proof_speed']}/{result['errors']}" # proved/proof_speed/Errors - grist_callback({ "Health": "test ok" }) - print("test ok") - #print(result) + result = check_logs(logger) + grist_callback({ "Health": result["status"] }) + logger.info(f"Status: {result['status']}") break except Exception as e: logger.error(f"Error on attempt {attempt+1}/3: {e}")