:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(ci): scope the json leg to the product on cascade runs (#106911)
Raúl Negrón-Otero6eb59b9d3315
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex dde4efc53f8e..aa23210d0cd9 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -2851,8 +2851,14 @@ jobs:elseecho "::warning::Django shard auto-sizing unavailable, using defaults: Core=$CORE_SHARDS, CorePOE=$CORE_POE_SHARDS, Temporal=$TEMPORAL_SHARDS, JsonTargets=$JSON_TARGETS_FULL_SHARDS"fi- # A full run takes every listed events_json path.+ # A full run takes every listed events_json path, unless discovery+ # shortened the list: a skipped product, or a product-only diff whose+ # legacy paths the merge queue runs. An empty list gives 0 rows.json_targets_count="$JSON_TARGETS_FULL_SHARDS"+ if [[ -n "$JSON_TARGETS_SHARDS" ]] && (( JSON_TARGETS_SHARDS < json_targets_count )); then+ json_targets_count="$JSON_TARGETS_SHARDS"+ echo "::notice::Discovery shortened the events_json list to $json_targets_count shard(s)"+ fi# The legacy-mode safeguard leg runs only where a regression must not# land: merge queue and master. Ordinary PR lanes run thediff --git a/.github/scripts/turbo-discover-selection.test.js b/.github/scripts/turbo-discover-selection.test.jsindex d284791940cc..8c052ad6baf1 100644--- a/.github/scripts/turbo-discover-selection.test.js+++ b/.github/scripts/turbo-discover-selection.test.js@@ -213,7 +213,26 @@ test('the events_json leg runs the whole list, a narrowed list, or nothing', ()[{ selectedTests: ['posthog/api/test/test_team.py'], products: ['logs'] }, []],[{ mode: '', runLegacy: false, products: ['surveys', 'web-analytics'] }, ['products/web_analytics/backend/hogql_queries']],[{ mode: '', runLegacy: false, products: ['surveys'] }, []],+ [+ { mode: 'full', skipReason: 'untrusted', runLegacyReason: 'non_isolated_product', diffProducts: ['web-analytics'] },+ ['products/web_analytics/backend/hogql_queries'],+ ],+ [{ mode: 'full', skipReason: 'untrusted', runLegacyReason: 'contract_cascade', diffProducts: ['tasks'] }, []],+ [{ mode: 'full', skipReason: 'untrusted', runLegacyReason: 'schema', diffProducts: ['tasks'] }, null],+ [{ mode: 'full', skipReason: 'disabled', runLegacyReason: 'non_isolated_product', diffProducts: ['tasks'] }, null],+ [{ mode: 'full', skipReason: 'untrusted', runLegacyReason: 'non_isolated_product', diffProducts: null }, null],[{ mode: 'full', doubled: true, products: ['batch-exports', 'web-analytics'] }, ['posthog/dags/tests/test_deletes.py']],+ [+ {+ mode: 'full',+ doubled: true,+ skipReason: 'untrusted',+ runLegacyReason: 'non_isolated_product',+ diffProducts: ['tasks'],+ products: ['batch-exports', 'web-analytics'],+ },+ ['posthog/dags/tests/test_deletes.py'],+ ],[{ mode: 'skip', doubled: true }, []],[{ mode: '', runLegacy: false, products: ['web-analytics'], doubled: true }, []],[{ doubled: true, selectedTests: ['posthog/hogql/test/test_query.py'], products: ['web-analytics'] }, []],diff --git a/.github/scripts/turbo-discover-sizing.test.js b/.github/scripts/turbo-discover-sizing.test.jsindex 028a25baf2ec..b80e9f42f1c9 100644--- a/.github/scripts/turbo-discover-sizing.test.js+++ b/.github/scripts/turbo-discover-sizing.test.js@@ -7,7 +7,7 @@const test = require('node:test')const assert = require('node:assert/strict')-const { pruneDeadDurations, getSegmentDuration, calculateShards, resolveProductSizing, buildMatrix, productSplitShards, PRODUCT_JOB_OVERHEAD_SECONDS, TARGET_WALL_SECONDS } = require('./turbo-discover.js')+const { pruneDeadDurations, getSegmentDuration, calculateShards, resolveProductSizing, buildMatrix, productSplitShards, narrowedJsonTargetsShards, DJANGO_FALLBACK_SHARDS, PRODUCT_JOB_OVERHEAD_SECONDS, TARGET_WALL_SECONDS } = require('./turbo-discover.js')// A path that exists in every checkout, so the existence check is deterministic.const LIVE_FILE = '.github/scripts/turbo-discover.js'@@ -51,6 +51,11 @@ test('getSegmentDuration still applies the segment exclude rules under an allowl// Sizing to the shared flat wall target: every shard carries// (target - overhead) of work, so walls land near the target in every lane.+test('a narrowed events_json list without durations takes the fallback shard count, not one shard', () => {+ assert.equal(narrowedJsonTargetsShards(['posthog/hogql'], null), DJANGO_FALLBACK_SHARDS.JsonTargets)+ assert.equal(narrowedJsonTargetsShards([], null), 0)+})+test('calculateShards sizes shards to the flat wall target', () => {// 105 min of work, 5 min overhead: each shard gets 7 min of tests,// walls land at the 12 min target.diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.jsindex 7ed695ad6f80..8ae0d7f25210 100644--- a/.github/scripts/turbo-discover.js+++ b/.github/scripts/turbo-discover.js@@ -1282,6 +1282,10 @@ function fullRunJsonTargets(targets, skippedProducts) {return targets.filter((target) => !isUnderProduct(target, skippedProducts))}+// The runLegacyReason values of a diff that edited products only. A schema or lib change+// reaches core directly, so the events_json leg keeps the whole list for those.+const PRODUCT_CASCADE_REASONS = new Set(['non_isolated_product', 'contract_cascade'])+// Which events_json paths this run executes. The leg follows the legacy tests. Null means// the whole list at the full-run shard count. An array is the list to run, and an empty// one means the leg does not run.@@ -1296,10 +1300,25 @@ function fullRunJsonTargets(targets, skippedProducts) {// draft the PR is a draft. Only read in selected mode, the one mode that the// merge queue's draft trunk-merge/** PR never reaches.// doubled retain only paths the schema copies do not cover+// skipReason why the selection fell back, from decideSelection+// runLegacyReason why the Django suite runs+// diffProducts the products the diff reached before a cascade widened the matrix to+// all products, or null when that set is unknownfunction decideJsonTargets({- targets, mode, runLegacy, selectedTests, products, skippedProducts = [], draft = false, doubled = false,+ targets,+ mode,+ runLegacy,+ selectedTests,+ products,+ skippedProducts = [],+ draft = false,+ doubled = false,+ skipReason = '',+ runLegacyReason = '',+ diffProducts = null,}) {if (doubled) {+ // The label asks for the widest events_json coverage, so a product cascade does not narrow it.const paths = decideJsonTargets({ targets, mode, runLegacy, selectedTests, products, skippedProducts, draft })// Dagster tests are excluded from the doubled Django suites and have no product job.return (paths ?? targets).filter(@@ -1321,6 +1340,13 @@ function decideJsonTargets({}if (mode !== 'selected') {const kept = fullRunJsonTargets(targets, skippedProducts)+ if (mode === 'full' && skipReason === 'untrusted' && diffProducts !== null && PRODUCT_CASCADE_REASONS.has(runLegacyReason)) {+ // A product-only diff runs the whole Django suite because core can import the+ // product's internals, and no selector can see that edge. The events_json leg+ // then keeps the paths of the products the diff reached and leaves the legacy+ // paths to the merge queue, which runs the whole list before anything lands.+ return kept.filter((target) => isUnderProduct(target, diffProducts))+ }return kept.length === targets.length ? null : kept}// Product test files come in through productPaths instead, so that the leg tests the@@ -1337,6 +1363,10 @@ function narrowedJsonTargetsShards(paths, durations) {if (paths.length === 0) {return 0}+ // Without durations the work reads as zero, which would size the list to one shard.+ if (!durations) {+ return DJANGO_FALLBACK_SHARDS.JsonTargets+ }return calculateShards(pathsDuration(paths, durations), DJANGO_OVERHEAD_SECONDS_BY_SEGMENT.JsonTargets, 1)}@@ -1495,6 +1525,8 @@ module.exports = {PRODUCTS_SCALED_MARKER,TARGET_WALL_SECONDS,DJANGO_OVERHEAD_SECONDS_BY_SEGMENT,+ DJANGO_FALLBACK_SHARDS,+ narrowedJsonTargetsShards,DJANGO_SEGMENTS,getIsolatedProducts,collectTestFiles,@@ -1559,6 +1591,9 @@ let runLegacyReason = ''// selection, the matrix narrows to these products plus the ones the selector reached// through the import graph. Null when that narrowing is not safe.let mustRunProducts = null+// The products a product-only diff reached, kept apart from a matrix that a cascade widened+// to all products. Null when a change reaches core directly or the reach is unknown.+let diffProducts = nullif (legacyChanged) {console.error('Legacy code changed — testing all products')@@ -1585,6 +1620,9 @@ if (legacyChanged) {products = allProductsrunLegacy = truerunLegacyReason = 'non_isolated_product'+ // Products that import the changed product's internals keep their events_json paths too.+ const dependents = tachDependentProducts(nonIsolatedAffectedProducts, allProductSet)+ diffProducts = dependents === null ? null : [...new Set([...affectedProducts, ...dependents])].sort()} else if (affectedProducts.length > 0) {// Only isolated products changed — check whether their contract surface was affectedconst affectedProductSet = new Set(affectedProducts)@@ -1609,6 +1647,7 @@ if (legacyChanged) {)}products = [...new Set([...affectedProducts, ...dependents])].sort()+ diffProducts = products}} else {console.error('Only isolated product internals changed — Django can be skipped')@@ -1638,6 +1677,7 @@ if (legacyChanged) {console.error(`${libModule} is imported by core (${coreImporters.join(', ')}) — Django will run`)runLegacy = truerunLegacyReason = runLegacyReason || 'lib_cascade'+ diffProducts = null}}if (directConsumers.size === 0) {@@ -1651,12 +1691,16 @@ if (legacyChanged) {products = allProductsrunLegacy = truerunLegacyReason = runLegacyReason || 'lib_cascade'+ diffProducts = null} else {if (cascaded.length > 0) {console.error(`Products depending on those importers via the tach map: ${JSON.stringify(cascaded)}`)}const reached = [...new Set([...directConsumers, ...cascaded])].sort()products = [...new Set([...products, ...reached])].sort()+ if (diffProducts !== null) {+ diffProducts = [...new Set([...diffProducts, ...reached])].sort()+ }const nonIsolatedReached = reached.filter((p) => !isolatedProducts.has(p))if (nonIsolatedReached.length > 0) {console.error(@@ -1763,6 +1807,9 @@ const jsonTargetFiles = decideJsonTargets({skippedProducts,draft: process.env.PR_DRAFT === 'true',doubled: process.env.RUN_NEW_EVENTS_SCHEMA === 'true',+ skipReason: selectionDecision.skip_reason,+ runLegacyReason,+ diffProducts,})console.error('\nDjango shard calculation:')@@ -1789,8 +1836,8 @@ const result = {run_poe,run_temporal,segment_shards: segment_shards ? JSON.stringify(segment_shards) : '',- // Empty on a run that takes the whole list. A full run sizes from django_shards.JsonTargets- // even when a skipped product shortens its list here.+ // Empty on a run that takes the whole list. A full run sizes from django_shards.JsonTargets,+ // and build_django_matrix lowers that to json_targets_shards when this list is shorter.json_targets_files: jsonTargetFiles === null ? '' : jsonTargetFiles.join(' '),json_targets_shards: jsonTargetFiles === null ? '' : narrowedJsonTargetsShards(jsonTargetFiles, durations),},diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 8d1dcfd49f60..200376c3d5e8 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -39,7 +39,9 @@ on:# The events_json leg runs wherever the legacy tests run, the hourly master run# included: the paths in .github/new-events-schema-targets.txt rerun against the# native-JSON events table, all of them on full runs and the reached ones on- # narrowed runs. The `test-new-events-schema` label opts a PR into the doubled+ # narrowed runs. A PR whose product-only change forced the full run reruns only+ # that product's paths, because the merge queue runs the whole list before merge.+ # The `test-new-events-schema` label opts a PR into the doubled# matrices that run the whole suite in both events schemas, in place of that leg.# Apply it before a push or ready_for_review because label events do not start# this workflow. Manual dispatches also run both modes.@@ -2843,8 +2845,14 @@ jobs:elseecho "::warning::Django shard auto-sizing unavailable, using defaults: Core=$CORE_SHARDS, CorePOE=$CORE_POE_SHARDS, Temporal=$TEMPORAL_SHARDS, JsonTargets=$JSON_TARGETS_FULL_SHARDS"fi- # A full run takes every listed events_json path.+ # A full run takes every listed events_json path, unless discovery+ # shortened the list: a skipped product, or a product-only diff whose+ # legacy paths the merge queue runs. An empty list gives 0 rows.json_targets_count="$JSON_TARGETS_FULL_SHARDS"+ if [[ -n "$JSON_TARGETS_SHARDS" ]] && (( JSON_TARGETS_SHARDS < json_targets_count )); then+ json_targets_count="$JSON_TARGETS_SHARDS"+ echo "::notice::Discovery shortened the events_json list to $json_targets_count shard(s)"+ fi# The legacy-mode safeguard leg runs only where a regression must not# land: merge queue and master. Ordinary PR lanes run the