Skip to content

ci(sentry): Run 8 sentry shards on API changes - #8772

Draft
sentry-junior[bot] wants to merge 4 commits into
masterfrom
ci/sentry-8-shards
Draft

sentry-junior[bot] wants to merge 4 commits into
masterfrom
ci/sentry-8-shards

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

On API changes the sentry job runs the snuba_ci or snuba tests across 4 shards of 17–19 minutes each. About 6–7 minutes of every shard goes to collecting the whole Sentry suite, which more shards don't shrink.

  • API-change runs get 8 sentry shards instead of 4. Runs without API changes keep 2.
  • The sentry job sets PYTEST_SELECTED_FILTERED_PLAN=1 (from ci(tests): Let filtered pytest-selected runs opt into the per-file plan sentry#133153), so each shard collects only its planned Sentry test files and -m picks the tests in them. This applies to runs without API changes too.
  • A shard may now select no tests, so a new Sentry shards selected tests job, required through Required checks, fails when any shard's report is missing, when the shards together select no tests, or when a test runs in two shards. Each shard uploads its pytest JSON report for it.

Why 8 shards and not 4: with collection gone, 4 shards are still bound by test execution and stay well above the 8-minute target. 8 shards cost more runner time than 4, but less than today's full collection. The comparison has the numbers.

via @joshuarli.

--

View Session [Sentry]

Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
joshuarli added a commit to getsentry/sentry that referenced this pull request Dec 2, 2026
…an (#133153)

Snuba's CI runs Sentry's tests filtered with `-m 'snuba_ci or snuba'`
(or `-m snuba_ci`) and `-k 'not __In'`. When `-m`/`-k` is present,
`pytest-selected.py` skips the per-file plan, so every shard, and every
xdist worker in it, collects the whole Sentry suite before keeping its
hash share. In Snuba's API-change runs that collection takes about 6–7
minutes of every shard, and adding shards doesn't shrink it.

The fallback exists because a filter can leave some shards with no
selected tests. This adds an opt-in, `PYTEST_SELECTED_FILTERED_PLAN=1`,
for callers that accept that:

- Filtered full runs use the same `plan_full_shards` plan as unfiltered
ones. Every candidate file still goes to a shard, including files
missing from the durations, so no file is dropped. Pytest then applies
`-m`/`-k` to the files it collects, so marker inheritance,
parametrization, and hook-added markers behave as before.
- A filtered shard whose files have no selected tests exits 0 instead of
5. Unfiltered shards with no tests still fail.
- Without the variable, filtered runs keep today's behavior.

Snuba turns this on in getsentry/snuba#8772.

**Known limit:** balancing still uses the full backend durations, so a
filtered run's selected tests can spread unevenly across shards.
Snuba-specific weights are a follow-up only if the measured slowest
shard shows it.

<!-- junior-request-attribution:start -->
via @joshuarli.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3ACLTE78L73%3A1796171061.177189 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3ACLTE78L73%3A1796171061.177189)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3ACLTE78L73%3A1796171061.177189/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
@sentry-junior

sentry-junior Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Results from #8773 (8 shards) and #8774 (4 shards). Both force the API-change path (snuba_ci or snuba) and test getsentry/sentry@5799664. The baseline is the earlier 4-shard full-collection run, 46759513604.

Selection equivalence (job): one full collection vs. the union of the planned shards, by node ID, on the same checkout.

Markers Shards Full collection Planned shards Missing Extra or repeated
snuba_ci 2 94 94 0 0
snuba_ci or snuba 8 5497 5497 0 0
snuba_ci or snuba 4 5497 5497 0 0

The real sentry jobs ran the same per-shard counts (sum 5497 in both runs), and Sentry shards selected tests passed in both.

Timings (minutes per sentry job; collection is from the start of make test-python-ci to xdist's workers [N items] line):

Run Slowest job Jobs Setup Collection Execution Runner-minutes
Baseline, 4 shards, full collection 19.2 17.0–19.2 2.5–3.0 5.9–7.1 8.2–9.6 73.0
#8774, 4 shards, per-file plan 14.1 10.5–14.1 2.4–2.8 0.7–0.8 7.2–10.4 49.5
#8773, 8 shards, per-file plan 9.3 6.9–9.3 2.5–3.5 0.4–0.6 3.6–5.3 65.4
  • Collection drops from 6–7 minutes to under a minute on both shard counts.
  • 4 shards: about 5 minutes faster than the baseline and the cheapest option, but nowhere near 8 minutes. Execution is uneven (7.2–10.4).
  • 8 shards: the slowest job is 9.3 minutes, 10 minutes faster than the baseline, and still 7.6 runner-minutes cheaper than it. Setup before pytest (2.5–3.5) is now the largest fixed cost per job, so reaching 8 minutes means cutting setup next, not adding shards.

This PR keeps 8 shards. Each experiment is one run, so expect a minute or so of runner noise.

This branch has not been deployed

No deployments
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.

1 participant