Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web-analytics): Add a DB field cookieless_server_hash_mode to a team, and setting to change it behind a flag #27059

Merged
merged 5 commits into from
Dec 20, 2024

Conversation

robbie-c
Copy link
Member

@robbie-c robbie-c commented Dec 19, 2024

Problem

Pulled this out of #25915 as it's a source of merge conflicts while it remains unmerged.

It's not actually used anywhere as of this PR, but it will be in a different PR.

This controls whether a team can send us cookieless events, and if they do, whether we use the stateless path or the stateful path.

See https://posthog.slack.com/archives/C06GG249PR6/p1734012638807509?thread_ts=1734012386.974969&cid=C06GG249PR6 for some more context but essentially.

  • stateful mode: uses Redis to maintain session state and identify state, which is a risk as we haven't used redis at this scale before
  • stateless mode: only uses Redis to manage the salt, but is less powerful (identify doesn't work, and there is only one session per user per day regardless of periods of inactivity)

See plugin-server/src/worker/ingestion/event-pipeline/cookielessServerHashStep.ts in https://github.com/PostHog/posthog/pull/25915/files for more.

Changes

  • Add a migration to add this column
  • Read the column in the team type in plugin-server
  • Fix some types in the db tests in plugin-server
  • Add a setting behind a FF to change this column

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Updated plugin-server DB tests

Copy link
Contributor

github-actions bot commented Dec 19, 2024

Size Change: +74 B (+0.01%)

Total Size: 1.11 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.11 MB +74 B (+0.01%)

compressed-size-action

@robbie-c robbie-c requested a review from a team December 19, 2024 14:32
Comment on lines +285 to +287
cookieless_server_hash_mode = models.SmallIntegerField(
default=CookielessServerHashMode.DISABLED, choices=CookielessServerHashMode.choices, null=True
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make it nullable? What Postgres version are we running?

If we are on PG 11+ we can make it non-nullable, and because there's a default it will automatically "backfill" it in a lightweight manner (i.e. it won't backfill, it computes it when returning the row)

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=16828d5c0273b4fe5f10f42588005f16b415b2d8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with making it nullable is that we now need to handle DISABLED, STATEFUL, STATELESS and now null as well (which we aren't)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SELECT version();

PostgreSQL 15.4 on aarch64-unknown-linux-gnu, compiled by aarch64-unknown-linux-gnu-gcc (GCC) 9.5.0, 64-

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So yes I should be able to use this if I can make django do the right thing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well DISABLED and null are just treated as the same atm (as both python and JS will treat them as equally falsy)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well DISABLED and null are just treated as the same atm (as both python and JS will treat them as equally falsy)
True, but is that a coincidence or a conscious choice? Similarly, this only true until we need to read this from Rust.

Anyway, this is going to work for now, and it is minor, but I still think that we should eventually move to a world where fields are not unconsciously nullable if they don't need to be

Copy link
Member Author

@robbie-c robbie-c Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on it :)

Ah I forgot that I'd have to fight with django migrations. I'll merge this first and can do the django dance/fight later.

plugin-server/src/types.ts Show resolved Hide resolved
@robbie-c robbie-c force-pushed the add/column-for-cookieless-mode branch from 5840342 to e8c3cd0 Compare December 19, 2024 15:25
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@robbie-c robbie-c merged commit f203ab5 into master Dec 20, 2024
99 checks passed
@robbie-c robbie-c deleted the add/column-for-cookieless-mode branch December 20, 2024 09:49
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.

3 participants