Repository navigation
feat(ci,tools): add unified nightly examples e2e pipeline with simple_job baseline - #897
janzak-dev wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new validation script simple_job_verify.py and comprehensive helper functions in xmc_entities_validator.py to verify simple multi-unit job workloads in XMC, alongside corresponding unit tests. Feedback focuses on improving robustness and logging practices: asserting the expected work unit count during spec validation to prevent silent bypasses, validating that expected_work_units is positive, raising a TypeError for unsupported types in container and spec validations, and replacing direct print statements with the standard logging module in library code.
| req = xmc_entities_validator._make_req("ListWorkUnitsRequest", parent=f"experiments/{xid}") | ||
| raw_work_units = list(getattr(stub.ListWorkUnits(req), "work_units", [])) | ||
| for raw_wu in raw_work_units: | ||
| worker_name = xmc_entities_validator.extract_worker_name(raw_wu) | ||
| _assert_work_unit_spec(raw_wu, worker_name, expected_queue) |
There was a problem hiding this comment.
The expected_work_units parameter is passed to _assert_all_work_unit_specs but is never used. To prevent silent validation bypass if the second ListWorkUnits RPC returns fewer or no work units, we should assert that the number of fetched raw work units matches expected_work_units.
req = xmc_entities_validator._make_req("ListWorkUnitsRequest", parent=f"experiments/{xid}")
raw_work_units = list(getattr(stub.ListWorkUnits(req), "work_units", []))
if len(raw_work_units) != expected_work_units:
raise AssertionError(
f"Expected {expected_work_units} raw WorkUnits for spec validation, but found {len(raw_work_units)}."
)
for raw_wu in raw_work_units:
worker_name = xmc_entities_validator.extract_worker_name(raw_wu)
_assert_work_unit_spec(raw_wu, worker_name, expected_queue)References
- PEP-8 recommends avoiding unused parameters to keep code clean and maintainable. (link)
| common.validate_argv(argv) | ||
| xid = common.parse_xid(getattr(FLAGS, "xid", None)) | ||
| expected_queue = common.get_flag(FLAGS, "expected_queue", DEFAULT_QUEUE) | ||
| expected_work_units = common.get_flag(FLAGS, "expected_work_units", DEFAULT_WORK_UNITS) |
There was a problem hiding this comment.
The expected_work_units flag is not validated to ensure it is positive. If a user passes a value less than 1, it could lead to unexpected behavior or incorrect assertions. We should add a guard check to validate that expected_work_units is at least 1.
| expected_work_units = common.get_flag(FLAGS, "expected_work_units", DEFAULT_WORK_UNITS) | |
| expected_work_units = common.get_flag(FLAGS, "expected_work_units", DEFAULT_WORK_UNITS) | |
| if expected_work_units < 1: | |
| raise ValueError("expected_work_units must be at least 1.") |
| if isinstance(expected_c, str): | ||
| act_name = getattr(actual_c, "name", "") | ||
| if act_name != expected_c: | ||
| raise AssertionError( | ||
| f"Job '{job_name}' {item_type} container name mismatch: " | ||
| f"expected '{expected_c}', found '{act_name}'." | ||
| ) | ||
| elif isinstance(expected_c, dict): | ||
| for k, v in expected_c.items(): | ||
| act_val = getattr(actual_c, k, None) | ||
| if act_val != v: | ||
| raise AssertionError( | ||
| f"Job '{job_name}' {item_type} container property '{k}' mismatch: " | ||
| f"expected '{v}', found '{act_val}'." | ||
| ) |
There was a problem hiding this comment.
If expected_c is neither a str nor a dict, the function silently completes without performing any validation. To prevent silent failures and ensure robust input validation, we should raise a TypeError if an unsupported type is passed.
if isinstance(expected_c, str):
act_name = getattr(actual_c, "name", "")
if act_name != expected_c:
raise AssertionError(
f"Job '{job_name}' {item_type} container name mismatch: "
f"expected '{expected_c}', found '{act_name}'."
)
elif isinstance(expected_c, dict):
for k, v in expected_c.items():
act_val = getattr(actual_c, k, None)
if act_val != v:
raise AssertionError(
f| if isinstance(expected_spec, str): | ||
| act_name = getattr(actual_spec, "name", "") | ||
| if act_name != expected_spec: | ||
| raise AssertionError( | ||
| f"Job '{job_name}' primary container name mismatch: " | ||
| f"expected '{expected_spec}', found '{act_name}'." | ||
| ) | ||
| elif isinstance(expected_spec, dict): | ||
| for k, v in expected_spec.items(): | ||
| act_val = getattr(actual_spec, k, None) | ||
| if act_val != v: | ||
| raise AssertionError( | ||
| f"Job '{job_name}' primary container property '{k}' mismatch: " | ||
| f"expected '{v}', found '{act_val}'." | ||
| ) |
There was a problem hiding this comment.
If expected_spec is neither a str nor a dict, the function silently completes without performing any validation. To prevent silent failures and ensure robust input validation, we should raise a TypeError if an unsupported type is passed.
| if isinstance(expected_spec, str): | |
| act_name = getattr(actual_spec, "name", "") | |
| if act_name != expected_spec: | |
| raise AssertionError( | |
| f"Job '{job_name}' primary container name mismatch: " | |
| f"expected '{expected_spec}', found '{act_name}'." | |
| ) | |
| elif isinstance(expected_spec, dict): | |
| for k, v in expected_spec.items(): | |
| act_val = getattr(actual_spec, k, None) | |
| if act_val != v: | |
| raise AssertionError( | |
| f"Job '{job_name}' primary container property '{k}' mismatch: " | |
| f"expected '{v}', found '{act_val}'." | |
| ) | |
| if isinstance(expected_spec, str): | |
| act_name = getattr(actual_spec, "name", "") | |
| if act_name != expected_spec: | |
| raise AssertionError( | |
| f"Job '{job_name}' primary container name mismatch: " | |
| f"expected '{expected_spec}', found '{act_name}'." | |
| ) | |
| elif isinstance(expected_spec, dict): | |
| for k, v in expected_spec.items(): | |
| act_val = getattr(actual_spec, k, None) | |
| if act_val != v: | |
| raise AssertionError( | |
| f"Job '{job_name}' primary container property '{k}' mismatch: " | |
| f"expected '{v}', found '{act_val}'." | |
| ) | |
| else: | |
| raise TypeError( | |
| f"Unsupported expected spec type: {type(expected_spec)}. Expected str or dict." | |
| ) |
| ) -> tuple[dict[str, str], float]: | ||
| """Logs state transitions or periodic progress if states changed or 30s elapsed.""" | ||
| if current_states != last_states or (elapsed - last_time >= 30.0): | ||
| print(f"[{int(elapsed)}s] WorkUnit States: {current_states}", flush=True) |
There was a problem hiding this comment.
As a generic validator library, it is preferred to use the standard logging module instead of direct print statements. This allows importing applications to configure, redirect, or suppress log output as needed.
| print(f"[{int(elapsed)}s] WorkUnit States: {current_states}", flush=True) | |
| logging.info("[%ds] WorkUnit States: %s", int(elapsed), current_states) |
References
- PEP-8 and general Python best practices recommend using the logging module instead of print statements in library code. (link)
9e1884d to
5dc0335
Compare
TAG=agy CONV=606f1e41-6785-4137-b85b-cd0f56237339
…_job baseline TAG=agy CONV=606f1e41-6785-4137-b85b-cd0f56237339
9eaa2be to
854b0dc
Compare
Summary
Adds the unified nightly examples E2E validation pipeline foundation (
.github/workflows/nightly-examples-e2e.yml) and baseline multi-unit job validator (tools/nightly_tests/simple_job_verify.py).📚 Stack Navigation
feat/nightly-examples-pipeline-base)simple_jobBaseline (This PR)feat/nightly-examples-suite)Motivation & Context
simple_jobkeeps the initial PR small (<300 prod lines) and provides a clean, extensible pattern for subsequent example additions.Key Changes
.github/workflows/nightly-examples-e2e.yml):run-and-verify-examplesconfigured forworkflow_dispatchand nightly cron schedule.simple_jobbaseline executing via virtualenvpython3 -m <verify_module>.tools/nightly_tests/):simple_job_verify.py: 100% Protobuf spec assertions forsimple_job(verifies PriorityHIGH,cpu-queue, worker namingdemo-worker-1..3, replicas 1, CPU 500m, memory 512 MiB, tags, notes, completed status).xmc_entities_validator.py: Decomposed foundational gRPC validator utilities (all functions <= 25 lines).BUILD.bazel: Adds Bazelpy_binaryandpy_testtargets forsimple_job_verifyand common dependencies.examples_verify_test.py&common_test.py: Hermetic unit tests verifying CLI arguments and execution flows.Assumptions
None — requirements were fully specified.
Verification & Testing
bazel test //tools/nightly_tests:all(3/3 targets passed, 83 tests passing)./.githooks/pre-commit check(100% clean)TAG=agy
CONV=606f1e41-6785-4137-b85b-cd0f56237339