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

Add Posthog integration to backend #682

Merged
merged 16 commits into from
Mar 29, 2024
Merged

Add Posthog integration to backend #682

merged 16 commits into from
Mar 29, 2024

Conversation

jkachel
Copy link
Contributor

@jkachel jkachel commented Mar 27, 2024

What are the relevant tickets?

Partially closes #589

Description (What does it do?)

Adds support for querying feature flags via Posthog, with fallback to the standard local environment. Posthog support is toggleable and queries to Posthog are cached locally in the database in case their API becomes unavailable.

To configure:

  • Set the Posthog specific .env file settings:
    • POSTHOG_PROJECT_API_KEY - the API key for the project the app should look at
    • POSTHOG_HOST - should be https://app.posthog.com generally but can be changed if needed
    • POSTHOG_ENABLED - boolean
  • Run ./manage.py createcachetable to create the table for the durable cache

How can this be tested?

Automated tests should pass.

The code exposes an internal meta API at /_/features that provides read operations on feature flags. Listing feature flags will additionally load the cache for the default case. (Posthog identifies users via a ID for the instance and an ID for the user; the default is to use the app's hostname for the instance ID, and the environment and user ID or None for the user ID, so this is what you'll get here.) The features API is intended as a sanity-check so user-specific flag settings aren't there (but we could add that).

@jkachel jkachel added Needs Review An open Pull Request that is ready for review product:mit-open Issues related to the MIT Open product labels Mar 27, 2024
Copy link

gitguardian bot commented Mar 27, 2024

⚠️ GitGuardian has uncovered 4 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9430286 Triggered Generic Password 50ea8f0 docker-compose.yml View secret
9430286 Triggered Generic Password b85583f docker-compose.yml View secret
9430286 Triggered Generic Password 81a6361 docker-compose.yml View secret
9430286 Triggered Generic Password 72c4253 docker-compose.yml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@shanbady shanbady self-assigned this Mar 28, 2024
@shanbady shanbady self-requested a review March 28, 2024 19:44
Copy link
Contributor

@shanbady shanbady left a comment

Choose a reason for hiding this comment

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

looks ok. left some comments about minor stuff

main/features.py Outdated
bool: True if the feature flag is enabled
""" # noqa: D401
return settings.FEATURES.get(name, default or settings.MITOPEN_FEATURES_DEFAULT)
bool: True if the feature flag is enablede
Copy link
Contributor

Choose a reason for hiding this comment

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

spelling * enablede

@@ -78,7 +78,7 @@ drf-nested-routers = "^0.93.5"
django-scim2 = "^0.19.1"
django-oauth-toolkit = "^2.3.0"
youtube-transcript-api = "^0.6.2"
ruff = "0.3.4"
Copy link
Contributor

Choose a reason for hiding this comment

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

was removing ruff 0.3.4 intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

think this was a rebase error... I put it back but looking at it I'm not sure why it's here and in dev dependencies (with a different version?) but that's sort of out of scope for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it's in there for IDE support. pre-commit is the source of truth for linting/formatting, but IDEs (to my knowledge) can't run pre-commit's ruff.

It's sometimes a bit out of date with pre-commit's, but they both get updated (pre-commit by its autoupdate, dev deps by renovate) and if they're slightly out of sync, it's not a big deal.

@jkachel jkachel requested a review from shanbady March 29, 2024 12:53
Copy link
Contributor

@shanbady shanbady left a comment

Choose a reason for hiding this comment

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

looks good.

@shanbady shanbady added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Mar 29, 2024
@jkachel jkachel merged commit 880d095 into main Mar 29, 2024
9 checks passed
@jkachel jkachel deleted the nl/posthog branch March 29, 2024 15:01
@odlbot odlbot mentioned this pull request Apr 1, 2024
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product:mit-open Issues related to the MIT Open product Waiting on author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature flag support (Posthog)
4 participants