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: product folders #26693

Merged
merged 64 commits into from
Jan 20, 2025
Merged

feat: product folders #26693

merged 64 commits into from
Jan 20, 2025

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Dec 5, 2024

Problem

Read the internal RFC.

PostHog is growing. We've doubled our engineering headcount in a year, and will soon double it again and again. This means soon hundreds of hands will be adding to the PostHog/posthog codebase every day. If you think CI is slow/flakey now, imagine it in a year.

Team DevEx was formed to proactively get ahead of problems with developer velocity. Our goal is to clean up the common layer between projects and products, including code, communication and UI, so that you could focus on your task at hand. We want to make it easier to build the next 50 products, than it was to build the last 10.

Changes

products/ folder

Here's the first PR in a bunch to come that splits products into their own folders/apps, starting with messaging (unreleased product), easy access features (small and lowish risk) and LLM observability (new product). The new/moved files in this PR are:

products
   llm_observability
      __init__.py
      manifest.json
      frontend
         urls.ts
         LLMObservabilityScene.tsx
         llmObservabilityLogic.tsx
         llmObservabilityLogicType.ts
   early_access_features
      __init__.py
      manifest.json
      migrations
         __init__.py
         max_migration.txt
         0001_initial_migration.py
         0002_alter_earlyaccessfeature_options_and_more.py
      backend
         models.py
         test
            test_early_access_feature.py
         api.py
      frontend
         urls.ts
         InstructionsModal.tsx
         earlyAccessFeaturesLogic.ts
         earlyAccessFeatureLogicType.ts
         earlyAccessFeaturesLogicType.ts
         EarlyAccessFeature.tsx
         EarlyAccessFeatures.stories.tsx
         EarlyAccessFeatures.tsx
         earlyAccessFeatureLogic.ts
   messaging
      __init__.py
      manifest.json
      backend # empty
      frontend
         urls.ts
         providersLogicType.ts
         broadcastsLogic.tsx
         Broadcasts.tsx
         functionsTableLogicType.ts
         messagingTabsLogic.ts
         functionsTableLogic.tsx
         FunctionsTable.tsx
         messagingTabsLogicType.ts
         MessagingTabs.tsx
         providersLogic.ts
         broadcastsLogicType.ts
         Providers.tsx

Product manifests + codegen

Each product has a manifest.json (will be manifest.ts for better typing in the future), which provides all django and esbuild need to assemble the whole hog. This is done via code generation for the frontend, including some TypeScript AST merging to make a combined urls object. The python/backend parts require manual wiring and don't yet come with a codegen.

Backend apps

We want to move backend/django code into product folders as well. Django supports multiple apps, however migrations are tricky. Check the code for an example. We need to delete the model's metadata in the main app, and recreate it in the product. It's a bit of work we'll have to do once per product. I think it's worth it.

Dependency graph

This PR adds a tool called toch which maps dependencies between django apps. We can use it to help us untangle apps in the future. Its output will be merged with the graph generated by nx once we get that up and running (one will generate the other).

image

TODO, outside this PR, but sooner rather than later

  • Kea typegen adds "..", ".." in front of the path. Remove "frontend" from within the path as well.
  • Support gathering imported typescript types in urls.ts files
  • Do we want to add some global product enum? Product scene enums now changed to strings which is a bit of a downgrade.
  • manifest.json to manifest.ts for better autocomplete support

To investigate later

  • Move backend routing into product folders + codegen
  • Other places in django we should inject into?
  • Common home for hogql_queries
  • Shorter frontend imports than products/early_access_features/frontend/earlyAccessFeatureLogic
  • Everything else in this big list

How did you test this code?

Works on my machine

@@ -0,0 +1,80 @@
# Generated by Django 4.2.15 on 2024-12-06 14:43
Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m on the fence on having each product be a separate django app (see this article. Basically Django doesn’t guarantee execution order of migrations I think so it potentially could be a bit of a nightmare. However, not having different product have merge conflicts when doing migrations is definitely a + for productivity so maybe it is worth it

Copy link
Collaborator Author

@mariusandra mariusandra Dec 6, 2024

Choose a reason for hiding this comment

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

In the article they mention fixing it with a homegrown migration manifest: https://gist.github.com/084ef47c4f68922c587bf1252e2d6d89

What I'd do is to have a text file with the order in which migrations are run, globally for all apps. If there's a merge conflict, you just make sure all migrations are in a logical order in this file, and that's that.

@mariusandra mariusandra marked this pull request as draft December 6, 2024 23:07
@mariusandra mariusandra marked this pull request as ready for review December 7, 2024 00:01
@mariusandra mariusandra changed the title feat: product manifests feat: product folders Dec 7, 2024
@daibhin
Copy link
Contributor

daibhin commented Dec 11, 2024

From what you showed me of this on Friday this seems to cover all the toil creating various scenes on the frontend for a new product. That certainly took some time for Error Tracking so maybe a scaffold would be nice but it was also a one time cost so not the most painful.

I wonder if similarly there is something we could do when creating a new service. Hooking it up to Argo for auto deploys, some basic charts / metrics / alert configurations. We didn't or still don't have a lot of that setup.

Taking that idea even further - there was a bunch of stuff involved in setting up a new product team that right now just gets added to the handbook (maybe). I'm thinking updating the website & roadmap, team Slack channels (and user group), Support inboxes & SLA alerts, standups, adding an in-app support option. It's probably not worth the investment but feels quite cookie cutter when creating a new team. Perhaps it can begin life as a Github issue template like we have for onboarding new hires.

@timgl
Copy link
Collaborator

timgl commented Dec 12, 2024

@daibhin on your last point, we have a template issue for ops to deal with creating a new team: https://github.com/PostHog/company-internal/issues/new/choose

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week. If you want to permanentely keep it open, use the waiting label.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week. If you want to permanentely keep it open, use the waiting label.

@github-actions github-actions bot temporarily deployed to pr-project-folders January 15, 2025 14:08 Destroyed
@github-actions github-actions bot temporarily deployed to pr-project-folders January 15, 2025 14:39 Destroyed
@github-actions github-actions bot temporarily deployed to pr-project-folders January 16, 2025 10:36 Destroyed
@mariusandra mariusandra requested a review from timgl January 17, 2025 15:56
@github-actions github-actions bot temporarily deployed to pr-project-folders January 20, 2025 12:41 Destroyed
@github-actions github-actions bot temporarily deployed to pr-project-folders January 20, 2025 14:10 Destroyed
@github-actions github-actions bot temporarily deployed to pr-project-folders January 20, 2025 14:59 Destroyed
@github-actions github-actions bot temporarily deployed to pr-project-folders January 20, 2025 15:23 Destroyed
@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 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@github-actions github-actions bot temporarily deployed to pr-project-folders January 20, 2025 15:42 Destroyed
@mariusandra mariusandra enabled auto-merge (squash) January 20, 2025 15:48
@mariusandra mariusandra merged commit 099a12f into master Jan 20, 2025
99 checks passed
@mariusandra mariusandra deleted the project-folders branch January 20, 2025 16:05
zlwaterfield pushed a commit that referenced this pull request Jan 20, 2025
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants