-
Notifications
You must be signed in to change notification settings - Fork 30
Dipowell/node readiness timing #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
diamondpowell
wants to merge
12
commits into
main
Choose a base branch
from
dipowell/node-readiness-timing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
16ba109
Add return_timestamp parameter to wait_for_nodes_ready
diamondpowell b00a147
Replace asyncio with ThreadPoolExecutor for concurrent timing
diamondpowell 006c87d
Internalize ARM call and start_time in concurrent method
diamondpowell 8658356
Rename _run_concurrent_arm_and_readiness to _instrument_nodepool_prov…
diamondpowell d2afe5a
Enhance timing logs with bottleneck analysis and total elapsed
diamondpowell 49b64af
Add pipeline test config (to be reverted before merge)
diamondpowell 30a6908
Extract _log_timing_metrics helper and trim _instrument_nodepool_prov…
diamondpowell 0a1b010
Revert "Add pipeline test config (to be reverted before merge)"
diamondpowell 666c1f1
Address review: simplify timing, restore retry, remove return_timestamp
diamondpowell d286aaf
Fix test: add time.time() side_effect values for concurrent timing
diamondpowell 94bf515
Add pipeline test config (to be reverted before merge)
diamondpowell 1b699f2
Revert "Add pipeline test config (to be reverted before merge)"
diamondpowell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| import os | ||
| import subprocess | ||
| import time | ||
| from concurrent.futures import ThreadPoolExecutor | ||
| from typing import Dict, Optional, Any | ||
|
|
||
| # Third party imports | ||
|
|
@@ -61,6 +62,93 @@ 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, | ||
| use_retry: bool = False, | ||
| ) -> list: | ||
| """ | ||
| Run ARM operation and K8s node readiness check concurrently using threads. | ||
|
|
||
| Args: | ||
| node_pool_name: Name of the node pool being provisioned | ||
| cluster_name: Name of the AKS cluster | ||
| parameters: Parameters for begin_create_or_update (dict or node pool object) | ||
| node_count: Expected number of nodes to be ready | ||
| op: Operation context for recording timing metadata | ||
| use_retry: If True, use _begin_update_with_retry for transient error handling | ||
|
|
||
| Returns: | ||
| List of ready nodes | ||
|
|
||
| Raises: | ||
| Exception: If either the ARM operation or K8s readiness check fails. | ||
| """ | ||
| start_time = time.time() | ||
| label_selector = f"agentpool={node_pool_name}" | ||
|
|
||
| with ThreadPoolExecutor(max_workers=2) as executor: | ||
| if use_retry: | ||
| arm_future = executor.submit( | ||
| lambda: ( | ||
| self._begin_update_with_retry(node_pool_name, cluster_name, parameters), | ||
| time.time(), | ||
| ) | ||
| ) | ||
| else: | ||
| 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=parameters, | ||
| ) | ||
| arm_future = executor.submit(lambda: (poller.result(), time.time())) | ||
| k8s_future = executor.submit( | ||
| lambda: ( | ||
| self.k8s_client.wait_for_nodes_ready( | ||
| node_count=node_count, | ||
| operation_timeout_in_minutes=self.operation_timeout_minutes, | ||
| label_selector=label_selector, | ||
| ), | ||
| time.time(), | ||
| ) | ||
| ) | ||
|
|
||
| arm_exc = arm_future.exception() | ||
| k8s_exc = k8s_future.exception() | ||
|
|
||
| if arm_exc or k8s_exc: | ||
| elapsed = time.time() - start_time | ||
| arm_status = f"FAILED: {arm_exc}" if arm_exc else "succeeded" | ||
| k8s_status = f"FAILED: {k8s_exc}" if k8s_exc else "succeeded" | ||
| logger.error( | ||
| "Concurrent operation failed after %.2fs - ARM: %s, K8s readiness: %s", | ||
| elapsed, arm_status, k8s_status | ||
| ) | ||
| if arm_exc: | ||
| raise arm_exc | ||
| raise k8s_exc | ||
|
|
||
| _, arm_timestamp = arm_future.result() | ||
| ready_nodes, ready_timestamp = k8s_future.result() | ||
|
|
||
| node_readiness_time = ready_timestamp - start_time | ||
| command_execution_time = arm_timestamp - start_time | ||
|
|
||
| op.add_metadata("node_readiness_time", node_readiness_time) | ||
| op.add_metadata("command_execution_time", command_execution_time) | ||
| logger.info( | ||
| "[%s] ARM completed in %.2fs, K8s nodes ready in %.2fs | Delta: %.2fs", | ||
| node_pool_name, command_execution_time, node_readiness_time, | ||
| abs(command_execution_time - node_readiness_time) | ||
| ) | ||
|
|
||
| return ready_nodes | ||
|
|
||
| def __init__( | ||
| self, | ||
| subscription_id: Optional[str] = None, | ||
|
|
@@ -519,23 +607,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 | ||
| ) | ||
|
|
||
| logger.info( | ||
| f"All {node_count} nodes in pool {node_pool_name} are ready" | ||
|
|
@@ -688,24 +770,17 @@ 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( | ||
| 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, | ||
| use_retry=True, | ||
| ) | ||
|
|
||
| logger.info( | ||
| f"All {node_count} nodes in pool {node_pool_name} are ready" | ||
| ) | ||
|
|
@@ -882,7 +957,6 @@ def _progressive_scale( | |
|
|
||
| logger.info(f"Planned scaling steps: {list(steps)}") | ||
|
|
||
| result = None | ||
| completed_steps = [] | ||
|
|
||
| # Execute scaling operation for each step | ||
|
|
@@ -924,28 +998,14 @@ 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( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Now the new codes lose the retry support.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this is fixed now. |
||
| node_pool_name=node_pool_name, | ||
| cluster_name=cluster_name, | ||
| node_pool=node_pool, | ||
| 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, | ||
| # 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, | ||
| use_retry=True, | ||
| ) | ||
| 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 | ||
| logger.info(f"All {step} nodes in pool {node_pool_name} are ready") | ||
|
|
||
| op.add_metadata( | ||
| "ready_nodes", len(ready_nodes) if ready_nodes else 0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deletion here is a behavior change. Your
_instrument_nodepool_provisioningcallsbegin_create_or_updatewhich does not do retry. I would suggest using_begin_update_with_retrywithin your instrumentation as it retries on transient errors - but this may skew your metrics.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my initial refactor, I dropped it when I moved the ARM call inside _instrument_nodepool_provisioning. So went ahead and added a use_retry parameter so when True, the method calls _begin_update_with_retry instead of begin_create_or_update. scale_node_pool and _progressive_scale both pass use_retry=True now, so the transient error handling is restored.