|
18 | 18 |
|
19 | 19 | from airflow import models |
20 | 20 | from airflow.decorators import task |
| 21 | +from airflow.models.baseoperator import chain |
21 | 22 | from airflow.utils.trigger_rule import TriggerRule |
22 | 23 | from airflow.utils.task_group import TaskGroup |
23 | 24 |
|
24 | 25 | from dags import composer_env |
25 | 26 | from dags.tpu_observability.utils import jobset_util as jobset |
26 | 27 | from dags.tpu_observability.utils import node_pool_util as node_pool |
27 | 28 | from dags.tpu_observability.utils.jobset_util import JobSet, Workload |
28 | | -from dags.tpu_observability.configs.common import MachineConfigMap, GCS_CONFIG_PATH |
| 29 | +from dags.tpu_observability.configs.common import ( |
| 30 | + MachineConfigMap, |
| 31 | + GCS_CONFIG_PATH, |
| 32 | + GCS_JOBSET_CONFIG_PATH, |
| 33 | +) |
| 34 | +from dags.common.scheduling_helper.scheduling_helper import SchedulingHelper, get_dag_timeout |
29 | 35 |
|
30 | 36 |
|
| 37 | +DAG_ID = "jobset_healthiness_ready" |
| 38 | +DAGRUN_TIMEOUT = get_dag_timeout(DAG_ID) |
| 39 | +SCHEDULE = SchedulingHelper.arrange_schedule_time(DAG_ID) |
| 40 | + |
31 | 41 | # Keyword arguments are generated dynamically at runtime (pylint does not |
32 | 42 | # know this signature). |
33 | 43 | with models.DAG( # pylint: disable=unexpected-keyword-arg |
34 | | - dag_id="jobset_healthiness_ready", |
| 44 | + dag_id=DAG_ID, |
35 | 45 | start_date=datetime.datetime(2025, 8, 10), |
36 | | - schedule="30 19 * * *" if composer_env.is_prod_env() else None, |
| 46 | + schedule=SCHEDULE if composer_env.is_prod_env() else None, |
| 47 | + dagrun_timeout=DAGRUN_TIMEOUT, |
37 | 48 | catchup=False, |
38 | 49 | tags=[ |
39 | 50 | "cloud-ml-auto-solutions", |
@@ -78,35 +89,28 @@ def generate_second_node_pool_name( |
78 | 89 | """Generates a second node pool name.""" |
79 | 90 | return f"{node_pool_info.node_pool_name}-2" |
80 | 91 |
|
81 | | - jobset_config = JobSet( |
82 | | - jobset_name="jobset-healthiness-ready", |
83 | | - namespace="default", |
84 | | - max_restarts=0, |
85 | | - replicated_job_name="tpu-job-slice", |
86 | | - replicas=2, |
87 | | - backoff_limit=0, |
88 | | - completions=4, |
89 | | - parallelism=4, |
90 | | - tpu_accelerator_type="tpu-v6e-slice", |
91 | | - tpu_topology="4x4", |
92 | | - container_name="jax-tpu-worker", |
93 | | - image="python:3.11", |
94 | | - tpu_cores_per_pod=4, |
95 | | - ) |
96 | | - |
97 | 92 | # Keyword arguments are generated dynamically at runtime (pylint does not |
98 | 93 | # know this signature). |
99 | 94 | with TaskGroup( # pylint: disable=unexpected-keyword-arg |
100 | 95 | group_id=f"v{config.tpu_version.value}" |
101 | 96 | ): |
| 97 | + selector = jobset.generate_node_pool_selector("jobset_healthiness_ready") |
| 98 | + |
| 99 | + jobset_config = jobset.build_jobset_from_gcs_yaml( |
| 100 | + gcs_path=GCS_JOBSET_CONFIG_PATH, |
| 101 | + dag_name=DAG_ID, |
| 102 | + node_pool_selector=selector, |
| 103 | + ) |
| 104 | + |
102 | 105 | cluster_info = node_pool.build_node_pool_info_from_gcs_yaml.override( |
103 | 106 | task_id="build_node_pool_info_from_gcs_yaml" |
104 | 107 | )( |
105 | 108 | gcs_path=GCS_CONFIG_PATH, |
106 | | - dag_name="jobset_healthiness_ready", |
| 109 | + dag_name=DAG_ID, |
107 | 110 | is_prod=composer_env.is_prod_env(), |
108 | 111 | machine_type=config.machine_version.value, |
109 | 112 | tpu_topology=config.tpu_topology, |
| 113 | + node_pool_selector=selector, |
110 | 114 | ) |
111 | 115 |
|
112 | 116 | cluster_info_2 = node_pool.copy_node_pool_info_with_override( |
@@ -182,16 +186,15 @@ def generate_second_node_pool_name( |
182 | 186 | setups=create_node_pool, |
183 | 187 | ) |
184 | 188 |
|
185 | | - # Airflow uses >> for task chaining, which is pointless for pylint. |
186 | | - # pylint: disable=pointless-statement |
187 | | - ( |
188 | | - cluster_info |
189 | | - >> cluster_info_2 |
190 | | - >> create_node_pool |
191 | | - >> validate_zero_replicas |
192 | | - >> start_workload |
193 | | - >> validate_ready_replicas |
194 | | - >> cleanup_workload |
195 | | - >> cleanup_node_pool |
| 189 | + chain( |
| 190 | + selector, |
| 191 | + jobset_config, |
| 192 | + cluster_info, |
| 193 | + cluster_info_2, |
| 194 | + create_node_pool, |
| 195 | + validate_zero_replicas, |
| 196 | + start_workload, |
| 197 | + validate_ready_replicas, |
| 198 | + cleanup_workload, |
| 199 | + cleanup_node_pool, |
196 | 200 | ) |
197 | | - # pylint: enable=pointless-statement |
|
0 commit comments