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.
This commit is contained in:
parent
3abc4e0a81
commit
1e38b5aca6
44
checker.py
44
checker.py
@ -117,41 +117,21 @@ class GRIST:
|
|||||||
|
|
||||||
|
|
||||||
def check_logs(log_handler):
|
def check_logs(log_handler):
|
||||||
error_count = 0
|
|
||||||
proved_count = 0
|
|
||||||
proof_speeds = deque(maxlen=100)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logs = subprocess.run(['docker', 'compose', 'logs', '--since', '2h'], cwd='/root/node/', capture_output=True, text=True, check=True)
|
logs = subprocess.run(['docker', 'compose', 'logs', '--since', '2h'], cwd='/root/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 compose logs: {e}") from e
|
raise RuntimeError(f"Error running docker compose logs: {e}") from e
|
||||||
|
|
||||||
for line in log_content.split('\n'):
|
subscription_pattern = r'Ignored subscription creation.*id=(\d+) err=Subscription completed'
|
||||||
if "error" in line.lower():
|
match = re.search(subscription_pattern, log_content)
|
||||||
log_handler.error(f"Error: {line}")
|
if match:
|
||||||
error_count += 1
|
subscription_id = match.group(1)
|
||||||
if "Proved step" in line:
|
log_handler.info(f"Found subscription completion message, id: {subscription_id}")
|
||||||
proved_count += 1
|
return {"status": f"Subscription {subscription_id}"}
|
||||||
log_handler.info(f"Proved step: {line}")
|
|
||||||
|
|
||||||
proof_speed_match = re.search(r'Proved step \d+ at (\d+\.\d+) proof cycles/sec', line)
|
log_handler.info("No subscription completion message found")
|
||||||
if proof_speed_match:
|
return {"status": "Idle"}
|
||||||
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")
|
|
||||||
|
|
||||||
data = {
|
|
||||||
"errors": error_count,
|
|
||||||
"proved_steps": proved_count/10,
|
|
||||||
"proof_speed": int(avg_proof_speed)
|
|
||||||
}
|
|
||||||
log_handler.info(f"Result: {data}")
|
|
||||||
return data
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
colorama.init(autoreset=True)
|
colorama.init(autoreset=True)
|
||||||
@ -180,11 +160,9 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
for attempt in range(3):
|
for attempt in range(3):
|
||||||
try:
|
try:
|
||||||
#result = check_logs(logger)
|
result = check_logs(logger)
|
||||||
#data = f"{result['proved_steps']}/{result['proof_speed']}/{result['errors']}" # proved/proof_speed/Errors
|
grist_callback({ "Health": result["status"] })
|
||||||
grist_callback({ "Health": "test ok" })
|
logger.info(f"Status: {result['status']}")
|
||||||
print("test ok")
|
|
||||||
#print(result)
|
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error on attempt {attempt+1}/3: {e}")
|
logger.error(f"Error on attempt {attempt+1}/3: {e}")
|
||||||
|
Loading…
Reference in New Issue
Block a user