-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d8b7f9
commit 0614deb
Showing
14 changed files
with
142 additions
and
12 deletions.
There are no files selected for viewing
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,88 @@ | ||
# Feature flags in the web stack | ||
|
||
This document describes the recommended way to use of feature flags in our web stack. | ||
|
||
## Flag management | ||
|
||
At the moment for managing feature flags, we're relying on good old environment variables. | ||
Currently we do not have a need to use an external flag managing service, but that might change in the future. | ||
|
||
## Usage | ||
|
||
The Speckle shared package exposes a `FeatureFlags` object, that contains all the available flags. | ||
|
||
> ⚠️ Warning | ||
> The feature flag mechanism doesn't work on the old frontend stack the same way. | ||
> If you still need some of this functionality, the backend `serverInfo` graphql query is probably the best place to expose the value at. | ||
### Backend, script usage | ||
|
||
For any usecase that is not Nuxt based, the code below is the preferred way of using feature flags. | ||
|
||
```typescript | ||
import { Environment } from '@speckle/shared' | ||
|
||
if (Environment.getFeatureFlags().ENABLE_AUTOMATE_MODULE) | ||
console.log("Hurray I'm enabled") | ||
``` | ||
|
||
### Frontend usage | ||
|
||
For our Nuxt based frontend we hook into Nuxt's config module to expose the feature flags in both SSR and frontend context. | ||
So using the feature flag is the same as using any nuxt public runtime config value. | ||
|
||
```typescript | ||
const config = useRuntimeConfig() | ||
|
||
if (config.public.ENABLE_AUTOMATE_MODULE) console.log("Hurray I'm enabled") | ||
``` | ||
|
||
## Definition | ||
|
||
The `@speckle/shared` package is the place where the common implementation of the feature flags is declared. | ||
To add a new feature flag, you need to modify the `featureFlagSchema` zod definition in `./src/environment/index.ts`. | ||
|
||
> 📣 Important | ||
> | ||
> Always add a default value, most probably `false` to the flag. | ||
> This will ensure that the feature you areKeep in mind, in order to support adding doesn't automatically roll out to all our deployments | ||
Once the flag is added to the zod schema, the flag is ready to be used in our apps. | ||
To enable the specific feature, please add an environment variable to the `.env` file of the component. | ||
|
||
> Note | ||
> | ||
> Since `znv` uses 1-1 name matching from the environment variables, we prefer using `MACRO_CASE` names. | ||
## Deployment | ||
|
||
With the use of `znv` we are directly parsing all environment variables into feature flags. So in general, all feature flags are just environment variables. We need to supply them to the application runtimes where they are needed. | ||
|
||
### Docker compose | ||
|
||
This is less relevant nowadays, but practically it is a copy pasta exercise, each container definition declares env vars. | ||
|
||
### Helm chart | ||
|
||
Helm charts allow configurations via the chart `values.yaml` for this purpose (intentionally omitting secrets). The chart values file defines a `featureFlags` object, that should be extended with the newly added flag. | ||
|
||
```yaml | ||
## @section Feature flags | ||
## @descriptionStart | ||
## This object is a central location to define feature flags for the whole chart. | ||
## @descriptionEnd | ||
featureFlags: | ||
## @param enableAutomateModule High level flag fully toggles the integrated automate module | ||
enableAutomateModule: false | ||
``` | ||
To expose the flag to specific deployments, we need to add the value into each deployment's env array like so | ||
```yaml | ||
# ... | ||
env: | ||
- name: ENABLE_AUTOMATE_MODULE | ||
// prettier-ignore | ||
value: {{ .Values.featureFlags.enableAutomateModule | quote }} | ||
# ... | ||
``` |
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
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
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,17 @@ | ||
import { parseEnv } from 'znv' | ||
import { z } from 'zod' | ||
|
||
const featureFlagSchema = z.object({ | ||
ENABLE_AUTOMATE_MODULE: z.boolean().default(false) | ||
}) | ||
|
||
function parseFeatureFlags() { | ||
return parseEnv(process.env, featureFlagSchema.shape) | ||
} | ||
|
||
let parsedFlags: ReturnType<typeof parseFeatureFlags> | undefined | ||
|
||
export function getFeatureFlags() { | ||
if (!parsedFlags) parsedFlags = parseFeatureFlags() | ||
return parsedFlags | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * as RichTextEditor from './rich-text-editor' | ||
export * as Observability from './observability' | ||
export * as SpeckleViewer from './viewer' | ||
export * as Environment from './environment' | ||
export * from './core' |
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
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