Skip to content

Commit 348248d

Browse files
committed
fix: update TTR DAG to use logging and active pod state polling
1 parent 62e8841 commit 348248d

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

dags/tpu_observability/jobset_ttr_pod_oom.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import tempfile
2020
import os
2121
import random
22-
import time
22+
import logging
2323
from typing import List
2424

2525
from airflow import models
@@ -66,11 +66,7 @@ def trigger_oom_failure(info, pod_name: str, namespace: str):
6666
the expected connection loss during an OOM event.
6767
"""
6868

69-
wait_time = 60
70-
print(
71-
f"Waiting {wait_time}s for Pod {pod_name} to stabilize before OOM Test..."
72-
)
73-
time.sleep(wait_time)
69+
logging.info(f"Checking status for Pod {pod_name}...")
7470

7571
python_logic = (
7672
"import time\n"
@@ -87,19 +83,26 @@ def trigger_oom_failure(info, pod_name: str, namespace: str):
8783
env["KUBECONFIG"] = temp_config_file.name
8884

8985
credentials_cmd = jobset.Command.get_credentials_command(info)
86+
87+
wait_cmd = (
88+
f"kubectl wait --for=condition=Ready pod/{pod_name} "
89+
f"-n {namespace} --timeout=60s"
90+
)
91+
9092
exec_cmd = (
9193
f'kubectl exec {pod_name} -n {namespace} -- python3 -c "{python_logic}"'
9294
)
9395

94-
full_command = f"{credentials_cmd} && {exec_cmd}"
96+
full_command = f"{credentials_cmd} && {wait_cmd} && {exec_cmd}"
9597

9698
try:
97-
print(f"Blasting {pod_name} memory now...")
99+
logging.info(f"Blasting {pod_name} memory now...")
98100
subprocess.run_exec(full_command, env=env)
99101
except subprocess.ProcessKilledException:
100-
print(f"Success: Pod {pod_name} was OOMKilled.")
102+
logging.info(f"Success: Pod {pod_name} was OOMKilled.")
101103
except Exception as e:
102-
print(f"Connection lost or other error: {e}")
104+
logging.error(f"Connection lost or other error: {e}")
105+
raise e
103106

104107

105108
@task
@@ -120,7 +123,7 @@ def pick_random_pod(active_pods: List[str]) -> str:
120123
if not active_pods:
121124
raise ValueError("No pods found to attack!")
122125
chosen_pod = random.choice(active_pods)
123-
print(f"Randomly selected pod for OOM test: {chosen_pod}")
126+
logging.info(f"Randomly selected pod for OOM test: {chosen_pod}")
124127
return chosen_pod
125128

126129

0 commit comments

Comments
 (0)