55
66from dataclasses import replace
77import datetime
8- import logging
98import os
109import re
11- import subprocess
10+ import tempfile
1211
1312from airflow import models
1413from airflow .decorators import task
1514from airflow .exceptions import AirflowFailException
1615from airflow .utils .task_group import TaskGroup
1716from airflow .utils .trigger_rule import TriggerRule
1817
19- from dags .common .vm_resource import MachineVersion
20- from dags .common .vm_resource import Project
21- from dags .common .vm_resource import Region
22- from dags .common .vm_resource import Zone
23- from dags .tpu_observability .configs .common import MachineConfigMap , TpuConfig
18+ from dags .common .vm_resource import Zone , Region
2419from dags .map_reproducibility .utils import constants
20+ from dags .tpu_observability .configs .common import MachineConfigMap , TpuConfig
2521from dags .tpu_observability .utils import jobset_util as jobset
2622from dags .tpu_observability .utils import node_pool_util as node_pool
23+ from dags .tpu_observability .utils import subprocess_util as subprocess
2724from dags .tpu_observability .utils import tpu_info_util as tpu_info
28- from dags .tpu_observability .utils .jobset_util import JobSet
29- from dags .tpu_observability .utils .jobset_util import Workload
30- from dags .tpu_observability .configs .common import MachineConfigMap , TpuConfig
25+ from dags .tpu_observability .utils .jobset_util import JobSet , Workload
3126
3227
3328@task
34- def get_tpu_info_from_pod (kubeconfig : str , pod_name : str ) -> str :
29+ def get_tpu_info_from_pod (node_pool : node_pool . Info , pod_name : str ) -> str :
3530 """Executes the 'tpu-info' command within a specified pod and returns its output.
3631
3732 This task uses kubectl to run the 'tpu-info' command inside the given pod
@@ -45,26 +40,16 @@ def get_tpu_info_from_pod(kubeconfig: str, pod_name: str) -> str:
4540 Returns:
4641 The standard output from the 'tpu-info' command.
4742 """
48- env = os .environ .copy ()
49- env ["KUBECONFIG" ] = kubeconfig
43+ with tempfile .NamedTemporaryFile () as temp_config_file :
44+ env = os .environ .copy ()
45+ env ["KUBECONFIG" ] = temp_config_file .name
5046
51- result = subprocess .run (
52- (
53- f"kubectl --kubeconfig={ kubeconfig } "
54- f"exec { pod_name } -n default "
55- f"-- tpu-info"
56- ),
57- shell = True ,
58- env = env ,
59- # Since tpu-info feature still has some issues, so the command will
60- # inevitably throw an error. To avoid marking the task as failed,
61- # I set check to False so that the task status does not show as failed.
62- check = True ,
63- capture_output = True ,
64- text = True ,
65- )
66- logging .info ("STDOUT: %s" , result .stdout )
67- return result .stdout
47+ cmd = " && " .join ([
48+ jobset .Command .get_credentials_command (node_pool ),
49+ (f"kubectl exec { pod_name } -n default -- tpu-info" ),
50+ ])
51+
52+ return subprocess .run_exec (cmd , env = env )
6853
6954
7055@task
@@ -91,7 +76,6 @@ def verify_table_amount(tpu_info_output: list[tpu_info.Table]):
9176@task
9277def validate_chips_table (
9378 tpu_info_output : list [tpu_info .Table ],
94- node_pool : node_pool .Info ,
9579 tpu_config : TpuConfig ,
9680):
9781 """Validates the row count and content for the 'TPU Chips' table."""
@@ -343,7 +327,6 @@ def validate_latency_table(tpu_info_output: list[tpu_info.Table]):
343327 ),
344328 )
345329
346- kubeconfig_path = "/tmp/kubeconfig"
347330 jobset_config = JobSet (
348331 jobset_name = "tpu-info-v6e-workload" ,
349332 namespace = "default" ,
@@ -356,7 +339,7 @@ def validate_latency_table(tpu_info_output: list[tpu_info.Table]):
356339 tpu_accelerator_type = "tpu-v6e-slice" ,
357340 tpu_topology = "4x4" ,
358341 container_name = "jax-tpu-worker" ,
359- image = "us- docker.pkg.dev/tpu-prod-env-one-vm /yuna-docker-repo /tpu-info:v0.5.1" ,
342+ image = "asia-northeast1- docker.pkg.dev/cienet-cmcs /yuna-docker/tpu-info:v0.5.1" ,
360343 tpu_cores_per_pod = 4 ,
361344 )
362345
@@ -382,7 +365,6 @@ def validate_latency_table(tpu_info_output: list[tpu_info.Table]):
382365
383366 apply_time = jobset .run_workload (
384367 node_pool = cluster_info ,
385- kubeconfig = kubeconfig_path ,
386368 yaml_config = jobset_config .generate_yaml (
387369 workload_script = workload_script
388370 ),
@@ -391,7 +373,6 @@ def validate_latency_table(tpu_info_output: list[tpu_info.Table]):
391373
392374 active_pods = jobset .get_active_pods .override (task_id = "get_active_pod" )(
393375 node_pool = cluster_info ,
394- kubeconfig = kubeconfig_path ,
395376 namespace = jobset_config .namespace ,
396377 )
397378
@@ -401,7 +382,7 @@ def validate_latency_table(tpu_info_output: list[tpu_info.Table]):
401382
402383 tpu_info_outputs = (
403384 get_tpu_info_from_pod .override (task_id = "get_tpu_info" )
404- .partial (kubeconfig = kubeconfig_path )
385+ .partial (node_pool = cluster_info )
405386 .expand (pod_name = active_pods )
406387 )
407388
@@ -422,7 +403,7 @@ def validate_latency_table(tpu_info_output: list[tpu_info.Table]):
422403
423404 validate_tpu_chips_metric = (
424405 validate_chips_table .override (task_id = "validate_tpu_chips_metric" )
425- .partial (node_pool = cluster_info , tpu_config = config )
406+ .partial (tpu_config = config )
426407 .expand (tpu_info_output = tpu_info_output )
427408 )
428409
@@ -450,7 +431,6 @@ def validate_latency_table(tpu_info_output: list[tpu_info.Table]):
450431 task_id = "clean_up_workload" , trigger_rule = TriggerRule .ALL_DONE
451432 )(
452433 node_pool = cluster_info ,
453- kubeconfig = kubeconfig_path ,
454434 jobset_name = jobset_config .jobset_name ,
455435 namespace = jobset_config .namespace ,
456436 ).as_teardown (
0 commit comments