Commit d09dc3c
Add REFRESH_DURATIONS mode to internal pipeline for pytest-split duration refresh (#22765)
## Summary & Motivation
Stacked on #22715 (pytest-split adoption). That PR introduces splitting
via `pytest-split` but, without `.test_durations*` files, splitting
falls back to count-based balancing. This PR wires up the machinery to
produce and consume per-suite duration data.
Rather than maintain a separate Buildkite pipeline whose suite list
duplicates the split config in `python_packages.py` / OSS `packages.py`,
refresh runs as a **mode** of the existing `internal` pipeline. The same
split config drives both normal sharded CI and the periodic refresh — no
separate list to keep in sync. Refresh is triggered manually (no
schedule); a Buildkite block step gates the final PR-creation step so a
human can inspect the collected artifacts before they're committed.
## How it works
**`REFRESH_DURATIONS=1` flag.** A new `BuildConfig.refresh_durations`
boolean lives in `buildkite-shared/context.py` and is settable via the
`REFRESH_DURATIONS` env var or `[REFRESH_DURATIONS]` magic string in the
build message.
**Step generation diverges in `PackageSpec.build_steps`.** For each tox
factor:
- **`splits > 1` in refresh mode:** collapse the parallel fan-out to a
single un-sharded step with `--store-durations --durations-path
.test_durations-<factor>[-<label_suffix>]`. Soft-fails so one broken
suite doesn't lose the rest. A `command_wrapper` does `set +e; <tox>;
status=$?; cd "$BUILDKITE_BUILD_CHECKOUT_PATH"; buildkite-agent artifact
upload "<dir>/.test_durations-..."; exit $status` — disables `set -e` so
the upload always runs, and `cd`s back to repo root so the artifact is
stored with its full repo-relative path (basenames would collide across
packages).
- **`splits <= 1` in refresh mode:** emit a normal step (which the
top-level filter drops). Not emitting nothing keeps OSS helpers like
`build_helm_steps` (`assert len(pkg_steps) == 1`) working.
- **Normal mode:** unchanged behavior plus `--durations-path
.test_durations-<factor>[-<label_suffix>]` so pytest-split reads exactly
the file refresh writes. Naming includes `label_suffix` to keep OSS
dagster-dbt's four `<deps>-core-main` ToxFactors (rest / test_resource /
test_asset_checks / cli) from clobbering each other's files.
**Top-level transform via `apply_transforms`.**
`InternalBuildkiteContext.apply_transforms` is overridden to run
`refresh_durations.apply` before delegating to the shared transform. The
transform:
1. Drops every step that doesn't carry `--store-durations` (i.e. lint,
kaniko, helm, dogfood, etc. — emitted normally during pipeline
construction, pruned here).
2. Scrubs dangling `depends_on` references on surviving steps (e.g. OSS
k8s-test-suite refresh leaves carry `depends_on: [test-project-3-12]`
pointing at an image-build step that was just filtered out — without
scrubbing, BK rejects the pipeline upload).
3. Appends a `BlockStepBuilder("approve-test-durations-pr")` step
depending on every refresh tox step's key, and a
`create-test-durations-pr` step depending on the block. The PR step runs
only after a reviewer clicks unblock.
In refresh mode the buildevents / AI-assessment steps get stripped too
(they don't carry `--store-durations`); acceptable for a manual refresh.
**`inject_flakes_clones` opt-out.** The quarantine flake-clone injector
early-returns in refresh mode — clones would inherit the
`--store-durations` flag, survive the filter, and race the original on
the same artifact path with `RUN_QUARANTINED=1`'s different test set.
**`get_python_package_step_skip_reason` left unchanged.** Refresh-mode
bypass of change-detection happens inside `_append_steps_for_cell`
(`skip_reason=None` only for the refresh-step emit), so external callers
like `skip_release_pipeline` and `_get_app_cloud_step_skip_reason` keep
their normal semantics.
**Aggregation step.** `scripts/buildkite/create_test_durations_pr.sh`:
- Downloads `**/.test_durations*` artifacts; treats "no artifacts" as a
clean no-op.
- Validates each file is non-empty + parseable JSON; skips invalid files
so a half-written durations file from a crashed tox run never lands in
the repo.
- Uses `find -print0 | xargs -0 git add` so any future
whitespace-in-path doesn't split.
- Pushes via `GIT_ASKPASS` helper with `GIT_TERMINAL_PROMPT=0`, so
`ELEMENTL_DEVTOOLS_PAT` never appears in argv or git's error output.
- Opens the PR via the GitHub REST API (slim image has no `gh` CLI).
Retries on HTTP `000`/`5xx`/`429`; treats `422` (PR already exists for
this branch) as success.
**Internal-pipeline conditional carves out
`auto/refresh-test-durations/*`.** The existing `(build.author.name !=
"elementl-devtools") && ...` filter would otherwise skip CI on the
auto-PR (it's authored by elementl-devtools). The carve-out runs
internal CI on the durations PR so the new files get validated by the
pipeline that consumes them before merge.
## Changes
- `dagster-oss/.buildkite/buildkite-shared/buildkite_shared/context.py`
— `BuildConfig.refresh_durations` field.
- `dagster-oss/.buildkite/buildkite-shared/buildkite_shared/packages.py`
— refresh-mode branch in `_append_steps_for_cell` + extracted
`_append_refresh_step` helper; `--durations-path` added to normal split
mode.
-
`.buildkite/dagster-internal-buildkite/dagster_internal_buildkite/context.py`
— `InternalBuildkiteContext.apply_transforms` override calling
`refresh_durations.apply` before `super`.
-
`.buildkite/dagster-internal-buildkite/dagster_internal_buildkite/steps/refresh_durations.py`
— filter + scrub-deps + block + PR step builder.
-
`.buildkite/dagster-internal-buildkite/dagster_internal_buildkite/steps/quarantine.py`
— early-return in refresh mode.
- `infra/terragrunt/modules/buildkite-pipelines/pipelines.tf` —
`auto/refresh-test-durations/*` carve-out on the internal pipeline's
author conditional.
- `scripts/buildkite/create_test_durations_pr.sh` — REST-API PR creation
+ HTTPS push with PAT via `GIT_ASKPASS` + JSON validation + retries.
### Removed (superseded by this PR's earlier iteration)
- The previously-added dedicated `refresh-test-durations` pipeline:
`pipelines/refresh_test_durations.py`, its `cli.py` entry, the
`pyproject.toml` script, the Terragrunt module, and the steps YAML — all
replaced by the in-pipeline mode above.
## Test Plan
- [ ] Merge #22715 first; this PR is a no-op on its own for normal CI
runs (files don't exist yet, pytest-split falls back to count-based
balancing).
- [ ] After merge, kick off a manual `internal` build with
`REFRESH_DURATIONS=1` in the build env (or include `[REFRESH_DURATIONS]`
in a commit message on a feature branch) and confirm:
- [ ] Only split tox suites run, each as one un-sharded job with
`--store-durations`.
- [ ] After the suites finish, the `approve-test-durations-pr` block
step appears for manual unblock.
- [ ] Clicking unblock runs `create-test-durations-pr`, which downloads
artifacts and opens an `auto/refresh-test-durations-<date>-<build>` PR.
- [ ] That PR's internal-pipeline CI build runs (carve-out works) and
the `.test_durations-*` files balance subsequent normal-mode shard
distributions after merge.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Internal-RevId: 79790d5041821dd5ab3d083fd549eabb6574dce41 parent 841e333 commit d09dc3c
2 files changed
Lines changed: 145 additions & 1 deletion
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
334 | 341 | | |
335 | 342 | | |
336 | 343 | | |
337 | 344 | | |
338 | 345 | | |
339 | 346 | | |
340 | 347 | | |
| 348 | + | |
341 | 349 | | |
342 | 350 | | |
343 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
364 | 415 | | |
365 | 416 | | |
366 | 417 | | |
367 | 418 | | |
368 | 419 | | |
369 | 420 | | |
370 | 421 | | |
371 | | - | |
| 422 | + | |
372 | 423 | | |
373 | 424 | | |
374 | 425 | | |
| |||
409 | 460 | | |
410 | 461 | | |
411 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
412 | 548 | | |
413 | 549 | | |
414 | 550 | | |
| |||
0 commit comments