Repository navigation
feat(crud): add AKSMachineClient non-batch scale path - #1181
Merged
Merged
Conversation
Unstubs the non-batch ``scale_machine`` dispatch on AKSMachineClient, following the scaffolding PR (#1179). The batch path (``use_batch_api=True``) remains a ``NotImplementedError`` stub and lands in a follow-up PR; this keeps the diff focused. Newly implemented: - ``scale_machine`` (non-batch branch): snapshots baseline ready node count, submits per-machine PUTs via ``_scale_machine_individually``, waits ONCE on the agentpool-level provisioningState, then waits for P50/P70/P90/P99/P100 node readiness. Raises RuntimeError on partial landing, agentpool timeout, or P100 failure. - ``_wait_for_machine_node_readiness``: polls nodes labeled ``agentpool=<pool>`` and computes percentile envelopes against ``baseline_count + expected_count`` so only NEW nodes count toward thresholds. Never raises; returns the empty-state envelope on exhaustion. - ``_get_machine_name_prefix``: ``scale<N>k`` for multiples of 1000 >= 1000, ``scale<N>`` otherwise. Stable for cross-repo Kusto dashboards. - ``_scale_machine_individually``: ThreadPoolExecutor dispatch with ``max(1, machine_workers)`` clamp. - ``_create_single_machine``: single Machine PUT; returns True on any 2xx, never raises. Per-machine ARM polling intentionally omitted (AKS RP reports Succeeded too early). Still stubbed (lands in a follow-up PR): - ``scale_machine`` batch branch (``use_batch_api=True``) - ``_scale_machine_batch``, ``_create_batch_machines``, ``_make_batch_request``, ``_array_split``, and the ``_BATCH_429_*`` constants Other notes: - ``scale_machine`` return type changed from ``-> bool`` to ``-> None`` for consistency with ``create_machine_agentpool`` (only exceptions signal failure; the return value was always dead). - Adds ``_MACHINE_API_VERSION = '2025-06-02-preview'`` constant. - Preserves all PR-1179 fixes (``self._session``, timeout split, 4xx-raises, immediate-Failed on missing provisioningState, ``tempfile.TemporaryDirectory`` in tests). Tests: - 12 unit tests pass (was 5). New tests cover non-batch success, partial-landing-raises, baseline_count propagation, ``_get_machine_name_prefix`` value tests for small/multiple-of-1000/ non-multiple-of-1000 counts, ``_create_single_machine`` for 200/201/202 vs 500, and a regression test for the batch path still raising ``NotImplementedError``. - pylint 10.00/10.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds the non-batch (per-machine PUT) scale path to AKSMachineClient, including Kubernetes node-readiness percentile tracking and expanded unit test coverage, while keeping the batch path explicitly stubbed for a follow-up PR.
Changes:
- Implemented
scale_machinenon-batch flow, including concurrent machine PUTs, a single agentpool provisioning poll, and node readiness percentile reporting. - Implemented
_wait_for_machine_node_readiness,_get_machine_name_prefix,_scale_machine_individually, and_create_single_machine. - Expanded
test_aks_machine_client.pyto cover the non-batch success/failure paths and new helpers, and to assert the batch branch still raisesNotImplementedError.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| modules/python/clients/aks_machine_client.py | Implements non-batch machine scaling, readiness percentile polling, naming scheme, and single-machine PUT behavior. |
| modules/python/tests/test_aks_machine_client.py | Adds unit tests for non-batch scaling, prefix generation, single-machine PUT handling, and batch-path stub assertion. |
Contributor
Author
Code reviewFound 2 issues:
telescope/modules/python/clients/aks_machine_client.py Lines 455 to 473 in e6cae67
telescope/modules/python/clients/aks_machine_client.py Lines 330 to 342 in e6cae67 |
…e path - Use math.ceil for percentile targets so P50/P70/P90 don't floor down to unreachable counts (e.g., target_total=3 now requires P50>=2, not 1); P100 still equals target_total and baseline_count+1 clamp is preserved. - Stop logging "All target nodes became ready" when only some percentiles met within timeout; emit a partial-readiness warning listing the missed percentiles instead. - In scale_machine, fail fast on partial machine landing BEFORE waiting on the agentpool or readiness against a reduced count, so the recorded percentile envelope, node_readiness_time, and cluster_info metadata are not written with a target smaller than the caller requested. - Add focused tests for _wait_for_machine_node_readiness covering ceil rounding, baseline clamping, partial-timeout envelopes, expected_count=0, and k8s_client=None short-circuits; tighten partial-landing test to assert agentpool/readiness waits are skipped on fail-fast.
Pylint flagged the two local 'import itertools' inside test bodies as C0415 (import-outside-toplevel) in CI. Move it to the file-level imports to satisfy python-validation.
Vittoria (vittoriasalim)
approved these changes
May 18, 2026
Karen Chen (karenychen)
added a commit
that referenced
this pull request
May 19, 2026
Adds the use_batch_api=True branch of scale_machine and the four batch helpers it dispatches to: _array_split, _scale_machine_batch, _create_batch_machines, _make_batch_request. Replaces the NotImplementedError stub landed in #1181. The batch path uses the AKS Machine API's BatchPutMachine HEADER pattern (NOT the non-existent ARM /$batch envelope): a single PUT to the first machine name in the chunk carrying a BatchPutMachine header whose JSON value contains vmSkus (wrapped in {value: [...]}) and batchMachines for the *additional* machines in the chunk. The batchMachines entries use the key 'machineName' (NOT 'name') — using the wrong key causes the API to silently ignore the entries and create only the URL-pointed machine. 429 responses are retried with bounded exponential backoff (_BATCH_429_MAX_RETRIES=3, 1s/2s/4s). Non-2xx non-429 responses raise immediately. Per-chunk wall time is captured in op.add_metadata('batch_command_execution_times', {chunk_<idx>: seconds}). Verification: - pylint repo-root on touched files: 10.00/10. - pytest modules/python/tests/test_aks_machine_client.py: 31 passed (13 new tests for the batch helpers + dispatch). - pytest --cov=. --cov-fail-under=80: 724 passed, 83.45% coverage.
Pablo Trivino (PabloTriv)
pushed a commit
that referenced
this pull request
Jun 12, 2026
## Summary Adds the non-batch scale path to `AKSMachineClient`, building on the scaffolding from #1179. The batch path (`use_batch_api=True`) is intentionally still stubbed with `NotImplementedError` and lands in a follow-up PR so this diff stays focused and reviewable. ## What's in this PR **Fully implemented in this PR:** - `scale_machine` (non-batch branch): snapshots baseline ready node count, submits per-machine PUTs via `_scale_machine_individually`, waits once on the agentpool-level `provisioningState`, then waits for P50/P70/P90/P99/P100 node readiness. Raises `RuntimeError` on partial landing, agentpool timeout, or P100 readiness failure. - `_wait_for_machine_node_readiness`: polls nodes labeled `agentpool=<pool>` and computes percentile envelopes against `baseline_count + expected_count` so only NEW nodes count toward thresholds. Never raises; returns an empty-state envelope on exhaustion. - `_get_machine_name_prefix`: `scale<N>k` for multiples of 1000 ≥ 1000, `scale<N>` otherwise. Stable scheme for cross-repo Kusto dashboards. - `_scale_machine_individually`: `ThreadPoolExecutor` dispatch with `max(1, machine_workers)` clamp. - `_create_single_machine`: single Machine PUT, returns `True` on any 2xx, never raises. Per-machine ARM polling intentionally omitted (AKS RP reports `Succeeded` essentially as soon as the agentpool admits the request). **Stubbed in this PR (lands in a follow-up PR):** - `scale_machine` batch branch (`use_batch_api=True`) - `_scale_machine_batch`, `_create_batch_machines`, `_make_batch_request`, `_array_split`, and the `_BATCH_429_*` retry constants ## Other notes - `scale_machine` return type changed from `-> bool` to `-> None` for consistency with `create_machine_agentpool` (only exceptions signal failure; the return value was always dead). - Adds `_MACHINE_API_VERSION = '2025-06-02-preview'` constant. - Preserves every fix from #1179: `self._session` for connection pooling, `_PER_REQUEST_TIMEOUT_CAP=60` timeout split, immediate 4xx raise in `_wait_for_agentpool_provisioning`, immediate-Failed on missing `provisioningState`, `tempfile.TemporaryDirectory()` in test setUp/tearDown. ## Tests - 12 unit tests pass (up from 5 on main). - New tests cover: - Non-batch scale success (metadata enrichment, all required keys present) - Partial-landing raises `RuntimeError` - `baseline_count` snapshot propagation to `_wait_for_machine_node_readiness` - `_get_machine_name_prefix` value tests for small / multiple-of-1000 / non-multiple-of-1000 counts - `_create_single_machine` accepts 200/201/202 and returns `False` (no raise) on 500 - Regression test asserting the batch path still raises `NotImplementedError` - `pylint` rating: 10.00/10 on both files. ## Follow-up PR A subsequent PR will: - Replace the `NotImplementedError` in the `use_batch_api=True` branch with batch dispatch. - Add `_scale_machine_batch`, `_create_batch_machines`, `_make_batch_request`, `_array_split`, and the `_BATCH_429_*` constants. - Add a batch success-path test.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds the non-batch scale path to
AKSMachineClient, building on the scaffolding from #1179. The batch path (use_batch_api=True) is intentionally still stubbed withNotImplementedErrorand lands in a follow-up PR so this diff stays focused and reviewable.What's in this PR
Fully implemented in this PR:
scale_machine(non-batch branch): snapshots baseline ready node count, submits per-machine PUTs via_scale_machine_individually, waits once on the agentpool-levelprovisioningState, then waits for P50/P70/P90/P99/P100 node readiness. RaisesRuntimeErroron partial landing, agentpool timeout, or P100 readiness failure._wait_for_machine_node_readiness: polls nodes labeledagentpool=<pool>and computes percentile envelopes againstbaseline_count + expected_countso only NEW nodes count toward thresholds. Never raises; returns an empty-state envelope on exhaustion._get_machine_name_prefix:scale<N>kfor multiples of 1000 ≥ 1000,scale<N>otherwise. Stable scheme for cross-repo Kusto dashboards._scale_machine_individually:ThreadPoolExecutordispatch withmax(1, machine_workers)clamp._create_single_machine: single Machine PUT, returnsTrueon any 2xx, never raises. Per-machine ARM polling intentionally omitted (AKS RP reportsSucceededessentially as soon as the agentpool admits the request).Stubbed in this PR (lands in a follow-up PR):
scale_machinebatch branch (use_batch_api=True)_scale_machine_batch,_create_batch_machines,_make_batch_request,_array_split, and the_BATCH_429_*retry constantsOther notes
scale_machinereturn type changed from-> boolto-> Nonefor consistency withcreate_machine_agentpool(only exceptions signal failure; the return value was always dead)._MACHINE_API_VERSION = '2025-06-02-preview'constant.self._sessionfor connection pooling,_PER_REQUEST_TIMEOUT_CAP=60timeout split, immediate 4xx raise in_wait_for_agentpool_provisioning, immediate-Failed on missingprovisioningState,tempfile.TemporaryDirectory()in test setUp/tearDown.Tests
RuntimeErrorbaseline_countsnapshot propagation to_wait_for_machine_node_readiness_get_machine_name_prefixvalue tests for small / multiple-of-1000 / non-multiple-of-1000 counts_create_single_machineaccepts 200/201/202 and returnsFalse(no raise) on 500NotImplementedErrorpylintrating: 10.00/10 on both files.Follow-up PR
A subsequent PR will:
NotImplementedErrorin theuse_batch_api=Truebranch with batch dispatch._scale_machine_batch,_create_batch_machines,_make_batch_request,_array_split, and the_BATCH_429_*constants.