Global feature flags via environment variables#1158
Conversation
There was a problem hiding this comment.
All of the important changes are in this file!
allisonking
left a comment
There was a problem hiding this comment.
worked as promised! although just a note that the check does not kick in on server reload. if I make my .env.local invalid, I'll get a message on the server that says "Reload env: .env.local" but the server will keep working fine. I think this is okay, but I guess means we can't dynamically swap out feature flags without restarting the server?
|
@allisonking I'm not totally sure what's causing the issue with reloading. Because we'll probably have a more robust solution in the future (i.e. one that supports per-community settings), I think I'm okay with the limitation of a server restart for global feature flags for now! |
* feat: disable specific actions using environment variable * feat: validate disabled actions using action names * Global feature flags via environment variables (#1158) * feat: simple feature flagging via new FLAGS env var * feat: use fflag for disabled actions * fix: default to [] for disabled-actions * fix: another stab at the env.FLAGS undefined problem * refactor: move flags into separate module * woops * feat: use transformer again * fix: test errors * fix: try explicit mock * test: try this * fix: okay do this for now * chore: cleanup
Issue(s) Resolved
Partial #1140
High-level Explanation of PR
This PR introduces a simple pattern for implementing global (i.e. not community-level) feature flags.
One would create a new feature flag by adding a tuple to the new
flagSchemazod type inenv.ts, where the first element of the tuple is a unique flag name, and the second element is the flag "args" or options. Default flag states/args are defined using Zod's.defaultmethod.Turning a flag on or off is as simple as starting the app with
FLAGS=flag-name:off. You can toggle multiple flags using a comma separated list, e.g.FLAGS=flag-1:off,flag-2:on.Some flags may take slightly more complex options than just "off" or "on". For example, the
disabled-actionsflag has a transformer that parses the following flag expression:into
The state and/or arguments of a flag can be retrieved on the server like
The flags I've introduced here don't do anything yet. I intend to utilize them in the
em/disabled-actionsbranch, and a small follow-up branch to disable file uploads and member invites in our sandbox environment.Test Plan
FLAGS=uploads:off,invites:off. It should start successfully! (These flags don't do anything yet).FLAGS=uploads:pancakes. The app should fail to start again.Screenshots (if applicable)
Notes
Setting a feature flag currently doesn't have any effect, this PR just introduces the pattern.