Skip to content

feat(crud): add AKSMachineClient scaffolding for AKS Machine API - #1179

Merged
Karen Chen (karenychen) merged 6 commits into
mainfrom
pr/crud-machine-scaffolding
May 15, 2026
Merged

Karen Chen (karenychen) merged 6 commits into
mainfrom
pr/crud-machine-scaffolding

Conversation

@karenychen

@karenychen Karen Chen (karenychen) commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

First of a planned multi-PR series adding an AKS Machine API client (AKSMachineClient) for the CRUD benchmarking framework. This PR delivers the scaffolding: the agentpool half of the workflow is fully implemented, and the scale/readiness path is stubbed so it can land in a follow-up PR.

What's in this PR

Fully implemented (modules/python/clients/aks_machine_client.py):

  • AKSMachineClient subclass of AKSClient with cached ARM token and a shared requests.Session for connection pooling
  • create_machine_agentpool — PUT a manualScale=0 agentpool (accepts 200/201/202 to handle ARM async semantics); per-request HTTP timeout capped at _PER_REQUEST_TIMEOUT_CAP (60s) so a slow PUT can't consume the polling budget
  • _wait_for_agentpool_provisioning — poll the agentpool until Succeeded, surface Failed immediately, tolerate transient absent provisioningState until both the consecutive-poll bound and a half-budget wall-clock grace window have elapsed

Stubbed in this PR (raise NotImplementedError, signatures preserved for forward compatibility):

  • scale_machine
  • _wait_for_machine_node_readiness
  • _get_machine_name_prefix

Not yet introduced:

  • _scale_machine_individually, _scale_machine_batch, _create_single_machine, _create_batch_machines, _make_batch_request, _array_split — these land with scale_machine in PR-2.

Tests

5 unit tests in modules/python/tests/test_aks_machine_client.py:

  • create_machine_agentpool — success, PUT failure surfaces, provisioning timeout raises
  • scale_machine raises NotImplementedError (guard so MachineCRUD wire-up can detect the unimplemented path cleanly)
  • _get_machine_name_prefix raises NotImplementedError

All 5 pass locally; pylint 10.00/10 against the repo .pylintrc.

Follow-up PR

PR-2 (scale_machine + batch/individual scale paths + per-machine readiness polling + _get_machine_name_prefix implementation) is in flight on a separate branch and will be opened once this one merges.

Add the AKSMachineClient subclass with the agentpool half of the
AKS Machine API workflow fully implemented:

  - create_machine_agentpool (PUT manualScale=0 agentpool, 200/201/202)
  - _wait_for_agentpool_provisioning (poll until Succeeded)
  - _get_machine_name_prefix (deterministic 12-char prefix so
    cross-repo Kusto dashboards key on a stable machine name)

scale_machine and the per-machine readiness poll are stubbed to
raise NotImplementedError; the scale/batch/readiness helpers land
in a follow-up PR so this change stays small enough to review.

This is the first of a planned multi-PR series; it supersedes
PR #1178 which grew too large for a single review.

Tests: 6 unit tests covering the implemented surface plus a
guard that scale_machine raises NotImplementedError so the
MachineCRUD wire-up can detect the unimplemented path cleanly.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds scaffolding for a new AKSMachineClient that extends AKSClient to support the AKS Machine API. The scale path is intentionally stubbed in this PR and will be implemented in a follow-up.

Changes:

  • Introduces AKSMachineClient with cached ARM token auth, a raw REST make_request helper, full create_machine_agentpool flow with provisioning poll, and stubs for scale_machine / _wait_for_machine_node_readiness.
  • Adds the static _get_machine_name_prefix helper that collapses multiples of 1000 to a kN form.
  • Adds unit tests covering the agentpool success/failure/timeout paths, the NotImplementedError guard for scale_machine, and prefix generation.

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 New client subclass implementing agentpool conversion via raw ARM REST and stubbing the scale/readiness path.
modules/python/tests/test_aks_machine_client.py New unit tests for create_machine_agentpool, the NotImplementedError stub, and _get_machine_name_prefix.

- Stub _get_machine_name_prefix to raise NotImplementedError; implementation
  lands in PR-2 alongside the scale path that consumes it.
- Reuse a per-instance requests.Session in make_request so TCP/TLS
  handshakes pool across polls and the planned parallel scale path.
- Split the timeout budget in create_machine_agentpool: cap the PUT HTTP
  timeout at _PER_REQUEST_TIMEOUT_CAP (60s) and reserve the remainder for
  _wait_for_agentpool_provisioning's polling deadline.
- Gate the transient-absent provisioningState 'treat as Failed' branch by
  wall-clock: only after _PROVISIONING_NONE_STATE_LIMIT consecutive polls
  AND at least half of timeout have elapsed. Avoids false negatives on
  slower control planes.
- pylint setUp tempfile.TemporaryDirectory: disable consider-using-with
  inline since 'with' doesn't fit the unittest setUp/tearDown lifecycle.
- Tests + module docstrings updated to reflect that
  _get_machine_name_prefix is stubbed; 5 unit tests, all passing.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- _wait_for_agentpool_provisioning: raise on 4xx GET (404/401/403 won't
  recover by polling); only 5xx and other transient failures retry until
  the deadline. (per @liyu-ma)
- _wait_for_agentpool_provisioning: simplify the absent-provisioningState
  branch to a single half-budget wall-clock gate; drop none_count and
  _PROVISIONING_NONE_STATE_LIMIT. (per @liyu-ma)
- create_machine_agentpool: return type -> None (only ever returns or
  raises; the dead True return was misleading). Test updated to drop the
  assertTrue on the discarded return value. (per @liyu-ma)
…iled

By AKS contract, a 200 GET on an agentpool always includes
properties.provisioningState. The previous half-budget grace window
existed to absorb a presumed transient None right after PUT acceptance,
but that case does not actually occur for a successful (200) GET. If we
do see a 200 response without provisioningState, that is a Failed signal
and we should stop polling immediately rather than waiting out half of
the timeout budget.
@karenychen
Karen Chen (karenychen) merged commit 8fe412a into main May 15, 2026
3 checks passed
@karenychen
Karen Chen (karenychen) deleted the pr/crud-machine-scaffolding branch May 15, 2026 02:22
Karen Chen (karenychen) added a commit that referenced this pull request May 19, 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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants