Skip to content

Commit 74dab13

Browse files
print stopped docker logs when we can't get the container
1 parent 3ba41ff commit 74dab13

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

integration/scripts/utils.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def die(message: str) -> None:
1414
sys.exit(1)
1515

1616

17+
def print_remote_result(result: Result) -> None:
18+
print(str(result))
19+
20+
1721
def mask_credentials(env_vars: Dict[str, Any]) -> Dict[str, Any]:
1822
masked_env_vars = env_vars.copy()
1923
# Only mask if vars exist
@@ -249,12 +253,7 @@ def get_docker_image(remote_host: Host) -> str:
249253
)
250254
images = [line.strip() for line in result.stdout.splitlines() if "SNAPSHOT" in line]
251255
if len(images) != 1:
252-
die(
253-
"❌ Error in finding observe-agent image, command output:\n{}\ncommand error:\n{}".format(
254-
result.stdout or "<empty>",
255-
result.stderr or "<empty>",
256-
)
257-
)
256+
die("❌ Error in finding observe-agent image\n" + str(result))
258257

259258
return images[0]
260259

@@ -288,6 +287,22 @@ def get_docker_container(remote_host: Host, retries: int = 3) -> str:
288287
)
289288
time.sleep(1)
290289
return get_docker_container(remote_host, retries - 1)
290+
elif retries == 0:
291+
# No retries left, see if we can get logs from stopped containers to help debug.
292+
result = remote_host.run_command('sudo docker ps --format "{{.ID}}"')
293+
if result.stdout != "":
294+
container_ids = result.stdout.splitlines()
295+
for container_id in container_ids:
296+
print(
297+
"Logs for container {}:".format(container_id),
298+
file=sys.stderr,
299+
)
300+
result = remote_host.run_command(
301+
"sudo docker logs {}".format(container_id)
302+
)
303+
print_remote_result(result)
304+
else:
305+
print_remote_result(result)
291306
die(
292307
"❌ Error in finding observe-agent container; command output:\n{}\ncommand error:\n{}".format(
293308
result.stdout or "<empty>",

0 commit comments

Comments
 (0)