Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
16ba109
Add return_timestamp parameter to wait_for_nodes_ready
diamondpowell Jun 4, 2026
b00a147
Replace asyncio with ThreadPoolExecutor for concurrent timing
diamondpowell Jun 24, 2026
006c87d
Internalize ARM call and start_time in concurrent method
diamondpowell Jun 24, 2026
8658356
Rename _run_concurrent_arm_and_readiness to _instrument_nodepool_prov…
diamondpowell Jun 24, 2026
d2afe5a
Enhance timing logs with bottleneck analysis and total elapsed
diamondpowell Jun 24, 2026
49b64af
Add pipeline test config (to be reverted before merge)
diamondpowell Jun 24, 2026
30a6908
Extract _log_timing_metrics helper and trim _instrument_nodepool_prov…
diamondpowell Jun 24, 2026
0a1b010
Revert "Add pipeline test config (to be reverted before merge)"
diamondpowell Jun 24, 2026
666c1f1
Address review: simplify timing, restore retry, remove return_timestamp
diamondpowell Jul 1, 2026
d286aaf
Fix test: add time.time() side_effect values for concurrent timing
diamondpowell Jul 27, 2026
94bf515
Add pipeline test config (to be reverted before merge)
diamondpowell Jul 27, 2026
1b699f2
Revert "Add pipeline test config (to be reverted before merge)"
diamondpowell Jul 28, 2026
b4ca8f8
Pass label kwarg through _instrument_nodepool_provisioning to _begin_…
diamondpowell Jul 30, 2026
6617be5
Merge remote-tracking branch 'origin/main' into dipowell/node-readine…
diamondpowell Jul 30, 2026
f39bf38
Extract provisioning instrumentation, always use retry, add retry_occ…
diamondpowell Aug 5, 2026
8ac94ad
Add pipeline test config (to be reverted before merge)
diamondpowell Aug 5, 2026
92fd8de
Fix pylint errors: lambda assignments, unused args, top-level import,…
diamondpowell Aug 5, 2026
1bb62e2
Merge branch 'main' into dipowell/node-readiness-timing
diamondpowell Aug 5, 2026
c49c0a1
Revert pipeline test config
diamondpowell Aug 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 56 additions & 95 deletions modules/python/clients/aks_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
# Local imports
from utils.logger_config import get_logger, setup_logging
from utils.common import get_env_vars
from utils.provisioning_instrumentation import (
begin_create_or_update_with_retry,
instrument_nodepool_provisioning,
)
from .kubernetes_client import KubernetesClient

# Configure logging
Expand Down Expand Up @@ -61,6 +65,40 @@ def _get_operation_context(self):

return OperationContext

def _instrument_nodepool_provisioning(
self,
node_pool_name: str,
cluster_name: str,
parameters: Any,
node_count: int,
op,
label: str = "",
) -> list:
"""
Run ARM operation and K8s node readiness check concurrently using threads.
Delegates to provisioning_instrumentation.instrument_nodepool_provisioning.
"""
def arm_callable():
return begin_create_or_update_with_retry(
self.aks_client, self.resource_group,
cluster_name, node_pool_name, parameters, label=label,
)

def k8s_wait_callable():
return self.k8s_client.wait_for_nodes_ready(
node_count=node_count,
operation_timeout_in_minutes=self.operation_timeout_minutes,
label_selector=f"agentpool={node_pool_name}",
)

return instrument_nodepool_provisioning(
node_pool_name=node_pool_name,
op=op,
arm_callable=arm_callable,
k8s_wait_callable=k8s_wait_callable,
label=label,
)

def __init__(
self,
subscription_id: Optional[str] = None,
Expand Down Expand Up @@ -259,54 +297,6 @@ def get_node_pool(
logger.error(f"Error getting node pool {node_pool_name}: {str(e)}")
raise

def _begin_update_with_retry(
self,
node_pool_name: str,
cluster_name: str,
node_pool: Any,
label: str = "",
retries: int = 10,
retry_wait: int = 30,
poll_interval: int = 30,
timeout: int = 1800,
) -> None:
"""
Call begin_create_or_update with retry on OperationNotAllowed/EtagMismatch,
polling every poll_interval seconds and raising TimeoutError after timeout seconds.
timeout defaults to 1800s (30 min) for slow GPU node provisioning (A100 MIG).
"""
for attempt in range(retries):
try:
poller = self.aks_client.agent_pools.begin_create_or_update(
resource_group_name=self.resource_group,
resource_name=cluster_name,
agent_pool_name=node_pool_name,
parameters=node_pool,
)
elapsed = 0
while not poller.done():
time.sleep(poll_interval)
elapsed += poll_interval
if elapsed >= timeout:
raise TimeoutError(
f"Node pool {node_pool_name} {label}scale timed out after {timeout}s"
)
logger.info(
f"Waiting for node pool {node_pool_name} {label}scale to complete "
f"({elapsed}s elapsed)..."
)
poller.result()
return
except HttpResponseError as e:
if any(code in str(e) for code in ("OperationNotAllowed", "EtagMismatch")) and attempt < retries - 1:
logger.warning(
f"Cluster has an in-progress operation, retrying in {retry_wait}s "
f"(attempt {attempt + 1}/{retries}): {e.error.code}"
)
time.sleep(retry_wait)
else:
raise

def add_managed_gpu_node_pool(
self,
node_pool_name: str,
Expand Down Expand Up @@ -519,23 +509,17 @@ def create_node_pool(
gpu_instance_profile=gpu_instance_profile,
gpu_mig_strategy=gpu_mig_strategy,
)
label_selector = f"agentpool={node_pool_name}"
ready_nodes = self.k8s_client.wait_for_nodes_ready(
node_count=node_count,
operation_timeout_in_minutes=self.operation_timeout_minutes,
label_selector=label_selector,
)
else:
# Create the node pool via SDK
self.aks_client.agent_pools.begin_create_or_update(
resource_group_name=self.resource_group,
resource_name=cluster_name,
agent_pool_name=node_pool_name,
parameters=parameters,
).result()

label_selector = f"agentpool={node_pool_name}"

# Wait for nodes to be ready
ready_nodes = self.k8s_client.wait_for_nodes_ready(
node_count=node_count,
operation_timeout_in_minutes=self.operation_timeout_minutes,
label_selector=label_selector,
)
# Run ARM and K8s readiness concurrently to capture both timings
ready_nodes = self._instrument_nodepool_provisioning(
node_pool_name, cluster_name, parameters, node_count, op
Comment thread
diamondpowell marked this conversation as resolved.
Resolved
)

logger.info(
f"All {node_count} nodes in pool {node_pool_name} are ready"
Expand Down Expand Up @@ -688,24 +672,16 @@ def scale_node_pool(
node_pool.count = node_count

logger.info(f"Scaling node pool {node_pool_name} to {node_count} nodes")
self._begin_update_with_retry(
Comment thread
diamondpowell marked this conversation as resolved.
Resolved
node_pool_name=node_pool_name,
cluster_name=cluster_name,
node_pool=node_pool,
)

logger.info(
f"Waiting for {node_count} nodes in pool {node_pool_name} to be ready..."
)

# Use agentpool=node_pool_name as default label if not specified
label_selector = f"agentpool={node_pool_name}"

ready_nodes = self.k8s_client.wait_for_nodes_ready(
node_count=node_count,
operation_timeout_in_minutes=self.operation_timeout_minutes,
label_selector=label_selector,
# Run ARM and K8s readiness concurrently to capture both timings
ready_nodes = self._instrument_nodepool_provisioning(
node_pool_name, cluster_name, node_pool, node_count, op,
)

logger.info(
f"All {node_count} nodes in pool {node_pool_name} are ready"
)
Expand Down Expand Up @@ -882,7 +858,6 @@ def _progressive_scale(

logger.info(f"Planned scaling steps: {list(steps)}")

result = None
completed_steps = []

# Execute scaling operation for each step
Expand Down Expand Up @@ -924,29 +899,15 @@ def _progressive_scale(
"cluster_info", self.get_cluster_data(cluster_name)
)
node_pool.count = step # Update node count in the node pool object
self._begin_update_with_retry(
Comment thread
diamondpowell marked this conversation as resolved.
Resolved
node_pool_name=node_pool_name,
cluster_name=cluster_name,
node_pool=node_pool,

# Run ARM and K8s readiness concurrently to capture both timings
ready_nodes = self._instrument_nodepool_provisioning(
node_pool_name, cluster_name, node_pool, step, op,
label=f"step {step} ",
)
result = node_pool

# Use agentpool=node_pool_name as default label if not specified
label_selector = f"agentpool={node_pool_name}"

ready_nodes = self.k8s_client.wait_for_nodes_ready(
node_count=step,
operation_timeout_in_minutes=self.operation_timeout_minutes,
label_selector=label_selector,
)
logger.info(f"All {step} nodes in pool {node_pool_name} are ready")

if result is None:
logger.error(f"Progressive scaling failed at step {step}")
op.add_metadata("error", "Scaling operation returned None")
return None

op.add_metadata(
"ready_nodes", len(ready_nodes) if ready_nodes else 0
)
Expand Down
4 changes: 2 additions & 2 deletions modules/python/clients/kubernetes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ def wait_for_nodes_ready(self, node_count, operation_timeout_in_minutes, label_s
Waits for a specific number of nodes with a given label to be ready within a specified timeout.
Raises an exception if the expected number of nodes are not ready within the timeout.

:param node_label: The label to filter nodes.
:param node_count: The expected number of nodes to be ready.
:param operation_timeout_in_minutes: The timeout in minutes to wait for the nodes to be ready.
:return: None
:param label_selector: The label to filter nodes.
:return: List of ready nodes.
"""
ready_nodes = []
ready_node_count = 0
Expand Down
Loading
Loading