Skip to content

feat(crud-machine): add machine data classes and result handler - #1175

Closed
Karen Chen (karenychen) wants to merge 1 commit into
mainfrom
pr/crud-machine-1-data-classes-result-handler
Closed

Karen Chen (karenychen) wants to merge 1 commit into
mainfrom
pr/crud-machine-1-data-classes-result-handler

Conversation

@karenychen

Copy link
Copy Markdown
Contributor

Why

First slice of the k8s-cluster-crud-machine Machine API perf-test port from ado-telescope to gh-telescope (tracking issue / project plan: feat/k8s-cluster-crud-machine).

The full feature is being shipped in 11 small, reviewable PRs. This PR is the foundation: it adds the python data records and the result-persistence decorator that every subsequent slice will depend on.

What

New modules/python/machine/ package containing:

  • data_classes.py — MachineConfig, ScaleMachineRequest, MachineOperationResponse, OperationNames enum.
  • result_handler.py — @save_test_result decorator that writes each op's response to disk as JSON.

Differences from ado-telescope's reference k8s/ package

  • OperationNames is a str Enum (was a frozen @dataclass).
  • MachineOperationResponse.percentile_node_readiness_times is a nested envelope (Dict[str, Dict[str, Any]]) so each percentile carries its target_nodes / elapsed_time_seconds / percentage / success metadata (matches the ado-golden blob schema at perf-eval/k8s-cluster-crud-machine/main/<id>.json).
  • save_test_result writes a nested {config, response} payload instead of a flat **-spread that could silently overwrite overlapping keys.
  • Persistence failures are caught and logged rather than propagated, so test orchestration stays insulated from disk errors.

Verification

  • pylint modules/python/machine/* modules/python/tests/test_machine_*.py → 10.00/10.
  • pytest tests/test_machine_data_classes.py tests/test_machine_result_handler.py → 7 passed.
  • Coverage: machine/data_classes.py 100%, machine/result_handler.py 97%.
  • pytest --cov=. --cov-fail-under=80 (full module suite) → 700 passed, 1 skipped, 83.67% total.

Subsequent PRs in this series

  1. AKSMachineClient skeleton with NotImplementedError stubs
  2. Port create_machine_agentpool
  3. Port machine readiness percentile wait
  4. Port scale_machine non-batch path
  5. Port scale_machine batch (BatchPutMachine)
  6. MachineManager orchestrator
  7. Machine CLI entrypoint
  8. Result aggregator with golden-file parity
  9. Scenario terraform inputs
  10. Pipeline templates + production pipeline

First slice of the k8s-cluster-crud-machine perf-test port from
ado-telescope. Introduces a new `machine/` python package with the
data records and result-persistence decorator that subsequent slices
will build on.

Differences from ado-telescope's reference k8s package:
- OperationNames is a str Enum (was a frozen @DataClass).
- MachineOperationResponse.percentile_node_readiness_times is a nested
  envelope (Dict[str, Dict[str, Any]]) so each percentile carries its
  target_nodes / elapsed_time_seconds / percentage / success metadata.
- save_test_result writes a nested {config, response} payload instead
  of a flat **-spread that could overwrite overlapping keys.
- Persistence failures are swallowed and logged rather than propagated,
  so test orchestration stays insulated from disk errors.

Verification:
- pylint 10.00/10 on all touched files.
- pytest: 7/7 new tests pass; machine/data_classes.py 100%, machine/result_handler.py 97%.
- Full module pytest --cov-fail-under=80 still green (83.67% total).

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

Introduces the foundational modules/python/machine/ package for the upcoming k8s-cluster-crud-machine perf-test port, including typed data records and a reusable result-persistence decorator, plus initial unit tests.

Changes:

  • Added MachineConfig, ScaleMachineRequest, MachineOperationResponse, and OperationNames to formalize the Machine perf-test schema.
  • Added @save_test_result decorator to persist per-operation results as nested {config, response} JSON blobs.
  • Added pytest coverage for the new data classes and result handler behavior (including error swallowing).

Reviewed changes

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

Show a summary per file
File Description
modules/python/machine/data_classes.py Adds core dataclasses and operation-name enum for machine CRUD perf-test schema.
modules/python/machine/result_handler.py Adds decorator to persist per-operation results to JSON files under result_dir.
modules/python/machine/init.py Declares the new machine package.
modules/python/tests/test_machine_data_classes.py Unit tests for defaults/types and enum values in the new dataclasses.
modules/python/tests/test_machine_result_handler.py Unit tests for nested payload persistence, filename suffix selection, and write-error swallowing.

Comment on lines +40 to +44
op_name = response.operation_name
suffix = config.machine_name or config.agentpool_name
timestamp = int(datetime.now(timezone.utc).timestamp())
filename = f"{op_name}-{config.cloud}-{config.cluster_name}-{suffix}-{timestamp}.json"
path = os.path.join(config.result_dir, filename)
Comment on lines +41 to +45
suffix = config.machine_name or config.agentpool_name
timestamp = int(datetime.now(timezone.utc).timestamp())
filename = f"{op_name}-{config.cloud}-{config.cluster_name}-{suffix}-{timestamp}.json"
path = os.path.join(config.result_dir, filename)
os.makedirs(config.result_dir, exist_ok=True)
Comment on lines +50 to +53
save_info_to_file(payload, path)
logger.info("Wrote result to %s", path)
except Exception as exc: # pylint: disable=broad-except
logger.warning("Failed to save result: %s", exc)
@karenychen

Copy link
Copy Markdown
Contributor Author

Closing per restructure decision.

After reviewing gh-telescope's existing CRUD framework (modules/python/crud/), the right approach is to align with it instead of porting ado-telescope's machine/ package shape 1:1:

  • crud/operation.py already provides Operation + OperationContext (context manager that auto-saves {operation_info: {...}} to {result_dir}/{cloud}_{op_name}_{ts}.json) — replaces machine/result_handler.py decorator and MachineOperationResponse dataclass.
  • clients/aks_client.py (AKSClient) is where AKS SDK calls live — Machine API methods belong there, not in a separate aks_machine_client.py.
  • crud/azure/node_pool_crud.py shows the orchestrator pattern — Machine work will mirror it as crud/azure/machine_crud.py.
  • crud/main.py is the single CLI with subcommands — Machine will extend it instead of adding a parallel machine/main.py.
  • crud/main.py::collect_benchmark_results() already aggregates results — drops the standalone machine/collect.py and golden-file fixtures.

Will reopen as a new PR series of ~5 PRs once the feature branch has been refactored and validated end-to-end against the staging pipeline.

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.

2 participants