-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-analytics): Improve session v2 double-event count workaround (…
…#24402) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
15d9a07
commit 3a0d758
Showing
7 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
posthog/clickhouse/migrations/0077_sessions_v2_faster_bounce.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions | ||
from posthog.models.raw_sessions.migrations import ( | ||
WRITABLE_RAW_SESSIONS_ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL, | ||
DISTRIBUTED_RAW_SESSIONS_ADD_EVENT_COUNT_SESSION_REPLAY_EVENTS_TABLE_SQL, | ||
BASE_RAW_SESSIONS_ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL, | ||
) | ||
from posthog.models.raw_sessions.sql import DROP_RAW_SESSION_MATERIALIZED_VIEW_SQL, RAW_SESSIONS_TABLE_MV_SQL | ||
|
||
operations = [ | ||
# drop the mv, so we are no longer receiving events from the sessions table | ||
run_sql_with_exceptions(DROP_RAW_SESSION_MATERIALIZED_VIEW_SQL()), | ||
# now we can alter the target tables | ||
run_sql_with_exceptions(WRITABLE_RAW_SESSIONS_ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL()), | ||
run_sql_with_exceptions(DISTRIBUTED_RAW_SESSIONS_ADD_EVENT_COUNT_SESSION_REPLAY_EVENTS_TABLE_SQL()), | ||
run_sql_with_exceptions(BASE_RAW_SESSIONS_ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL()), | ||
# and then recreate the materialized view | ||
run_sql_with_exceptions(RAW_SESSIONS_TABLE_MV_SQL()), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.conf import settings | ||
|
||
from posthog.models.raw_sessions.sql import RAW_SESSIONS_DATA_TABLE, TABLE_BASE_NAME | ||
|
||
ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL = """ | ||
ALTER TABLE {table_name} on CLUSTER '{cluster}' | ||
ADD COLUMN IF NOT EXISTS | ||
page_screen_autocapture_uniq_up_to | ||
AggregateFunction(uniqUpTo(1), Nullable(UUID)) | ||
""" | ||
|
||
BASE_RAW_SESSIONS_ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL = ( | ||
lambda: ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL.format( | ||
table_name=TABLE_BASE_NAME, | ||
cluster=settings.CLICKHOUSE_CLUSTER, | ||
) | ||
) | ||
|
||
WRITABLE_RAW_SESSIONS_ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL = ( | ||
lambda: ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL.format( | ||
table_name="writable_raw_sessions", | ||
cluster=settings.CLICKHOUSE_CLUSTER, | ||
) | ||
) | ||
|
||
DISTRIBUTED_RAW_SESSIONS_ADD_EVENT_COUNT_SESSION_REPLAY_EVENTS_TABLE_SQL = ( | ||
lambda: ADD_PAGEVIEW_AUTOCAPTURE_SCREEN_UP_TO_2_COLUMN_SQL.format( | ||
table_name=RAW_SESSIONS_DATA_TABLE(), | ||
cluster=settings.CLICKHOUSE_CLUSTER, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters