Skip to content

Commit 0c50fdd

Browse files
author
Chris Stockton
committed
feat: add info commands for when health checks fail
1 parent 4fef515 commit 0c50fdd

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

testinfra/test_ami_nix.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,29 +353,43 @@ def gzip_then_base64_encode(s: str) -> str:
353353

354354
def is_healthy(ssh) -> bool:
355355
health_checks = [
356-
("postgres", "sudo -u postgres /usr/bin/pg_isready -U postgres"),
356+
(
357+
"postgres",
358+
"sudo -u postgres /usr/bin/pg_isready -U postgres",
359+
"journalctl -b -u postgres -n 10 -r --no-pager",
360+
),
357361
(
358362
"adminapi",
359363
f"curl -sf -k --connect-timeout 30 --max-time 60 https://localhost:8085/health -H 'apikey: {supabase_admin_key}'",
364+
"journalctl -b -u adminapi -n 10 -r --no-pager",
360365
),
361366
(
362367
"postgrest",
363368
"curl -sf --connect-timeout 30 --max-time 60 http://localhost:3001/ready",
369+
"journalctl -b -u postgrest -n 10 -r --no-pager",
364370
),
365371
(
366372
"gotrue",
367373
"curl -sf --connect-timeout 30 --max-time 60 http://localhost:8081/health",
374+
"journalctl -b -u gotrue -n 10 -r --no-pager",
368375
),
369-
("kong", "sudo kong health"),
370-
("fail2ban", "sudo fail2ban-client status"),
376+
("kong", "sudo kong health", ""),
377+
("fail2ban", "sudo fail2ban-client status", ""),
371378
]
372379

373-
for service, command in health_checks:
380+
for service, command, info_command in health_checks:
374381
try:
375382
result = run_ssh_command(ssh, command)
376-
if not result["succeeded"]:
377-
logger.warning(f"{service} not ready")
378-
return False
383+
if result["succeeded"]:
384+
continue
385+
386+
info_text = ""
387+
if info_command is not "":
388+
info_result = run_ssh_command(ssh, info_command)
389+
if info_result["succeeded"]:
390+
info_text=info_result["stdout"].strip()
391+
logger.warning(f"{service} not ready{info_text}")
392+
return False
379393
except Exception:
380394
logger.warning(f"Connection failed during {service} check")
381395
return False

0 commit comments

Comments
 (0)