: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
feat(web-analytics): percentage-of-teams rollout for no-join fast paths (#70906)
Lucas Ricoyfdf04958927b
diff --git a/posthog/settings/web.py b/posthog/settings/web.pyindex 3dae32bb17b6..1bf8a72a9b81 100644--- a/posthog/settings/web.py+++ b/posthog/settings/web.py@@ -1162,3 +1162,14 @@ WEB_ANALYTICS_NO_JOIN_TEAM_IDS: list[int] = [int(team_id)for team_id in get_list(get_from_env("WEB_ANALYTICS_NO_JOIN_TEAM_IDS", _LAZY_PRECOMPUTE_DEFAULT_TEAM_IDS))]++# Percentage-of-teams rollout for the no-join fast paths, on top of the explicit+# allowlist above. Bucketing is deterministic per team (team_id % 100) so everyone+# on a team sees numbers from the same code path. 0 disables (allowlist only),+# 100 enrolls every team. Defaults to 50 on US Cloud (verified region); EU stays 0+# until its ClickHouse upgrade converges and the fast paths are verified there.+# Env var overrides in either direction and is the kill switch.+_NO_JOIN_DEFAULT_ROLLOUT_PERCENT = 50 if (CLOUD_DEPLOYMENT or "").upper() == "US" and not TEST else 0+WEB_ANALYTICS_NO_JOIN_ROLLOUT_PERCENT: int = get_from_env(+ "WEB_ANALYTICS_NO_JOIN_ROLLOUT_PERCENT", _NO_JOIN_DEFAULT_ROLLOUT_PERCENT, type_cast=int+)diff --git a/products/web_analytics/backend/hogql_queries/test/test_web_overview.py b/products/web_analytics/backend/hogql_queries/test/test_web_overview.pyindex 33595c7265db..40dbab2aeb39 100644--- a/products/web_analytics/backend/hogql_queries/test/test_web_overview.py+++ b/products/web_analytics/backend/hogql_queries/test/test_web_overview.py@@ -1130,3 +1130,25 @@ class TestWebOverviewNoJoinFastPath(ClickhouseTestMixin, APIBaseTest):with override_settings(WEB_ANALYTICS_NO_JOIN_TEAM_IDS=[self.team.pk]):runner = self._make_runner(filterTestAccounts=True)assert not runner.should_skip_session_join+++class TestWebOverviewNoJoinRolloutPercent(ClickhouseTestMixin, APIBaseTest):+ def _runner(self) -> WebOverviewQueryRunner:+ query = WebOverviewQuery(dateRange=DateRange(date_from="-7d"), properties=[])+ return WebOverviewQueryRunner(team=self.team, query=query)++ def test_percent_rollout_buckets_deterministically_by_team(self):+ bucket = self.team.pk % 100+ cases = [+ (0, False),+ (bucket, False),+ (bucket + 1, True),+ (100, True),+ ]+ for percent, expected in cases:+ with override_settings(WEB_ANALYTICS_NO_JOIN_TEAM_IDS=[], WEB_ANALYTICS_NO_JOIN_ROLLOUT_PERCENT=percent):+ assert self._runner().should_skip_session_join == expected, f"percent={percent}"++ def test_allowlist_wins_regardless_of_percent(self):+ with override_settings(WEB_ANALYTICS_NO_JOIN_TEAM_IDS=[self.team.pk], WEB_ANALYTICS_NO_JOIN_ROLLOUT_PERCENT=0):+ assert self._runner().should_skip_session_joindiff --git a/products/web_analytics/backend/hogql_queries/web_analytics_query_runner.py b/products/web_analytics/backend/hogql_queries/web_analytics_query_runner.pyindex 93d422b50aff..923e6ba3903d 100644--- a/products/web_analytics/backend/hogql_queries/web_analytics_query_runner.py+++ b/products/web_analytics/backend/hogql_queries/web_analytics_query_runner.py@@ -222,7 +222,7 @@ class WebAnalyticsQueryRunner(AnalyticsQueryRunner[WAR], ABC):Runners that support a no-join query shape check this gate; anything notcovered falls through to the join path untouched."""- if self.team.pk not in settings.WEB_ANALYTICS_NO_JOIN_TEAM_IDS:+ if not self._team_in_no_join_rollout():return Falseif getattr(self.query, "conversionGoal", None):return False@@ -240,6 +240,14 @@ class WebAnalyticsQueryRunner(AnalyticsQueryRunner[WAR], ABC):return Falsereturn True+ def _team_in_no_join_rollout(self) -> bool:+ if self.team.pk in settings.WEB_ANALYTICS_NO_JOIN_TEAM_IDS:+ return True+ percent = settings.WEB_ANALYTICS_NO_JOIN_ROLLOUT_PERCENT+ # Deterministic per-team bucketing: query results must come from one code+ # path for everyone on a team, so the rollout unit is the team, not the user.+ return percent > 0 and self.team.pk % 100 < percent+@cached_propertydef filters_eligibility_hash(self) -> Optional[str]:"""Stable hash of the user-facing query inputs that would fragment a