Skip to content

Commit

Permalink
feat: feature flags feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedlicska committed Mar 28, 2024
1 parent 918c5ac commit 139065b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 18 deletions.
7 changes: 5 additions & 2 deletions feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For any usecase that is not Nuxt based, the code below is the preferred way of u
```typescript
import { Environment } from '@speckle/shared'

if (Environment.getFeatureFlags().ENABLE_AUTOMATE_MODULE)
if (Environment.getFeatureFlags().FF_AUTOMATE_MODULE_ENABLED)
console.log("Hurray I'm enabled")
```

Expand All @@ -34,7 +34,7 @@ So using the feature flag is the same as using any nuxt public runtime config va
```typescript
const config = useRuntimeConfig()

if (config.public.ENABLE_AUTOMATE_MODULE) console.log("Hurray I'm enabled")
if (config.public.FF_AUTOMATE_MODULE_ENABLED) console.log("Hurray I'm enabled")
```

## Definition
Expand All @@ -53,6 +53,9 @@ To enable the specific feature, please add an environment variable to the `.env`
> Note
>
> Since `znv` uses 1-1 name matching from the environment variables, we prefer using `MACRO_CASE` names.
> As a naming convention we've settled on prefixing the feature flags with `FF_`.
> After that, to provide some structure, the next word should categorize the flag into an app or module its meant to belong to. ie `FF_AUTOMATE_MODULE_ENABLED`.
> The names should also be declarative rather than imperative so that code like `if (FF_FLAG_NAME) { do something }` reads nicely.
## Deployment

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend-2/composables/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { useGlobalToast } from '~/lib/common/composables/toast'

export const useIsAutomateModuleEnabled = () => {
const {
public: { ENABLE_AUTOMATE_MODULE }
public: { FF_AUTOMATE_MODULE_ENABLED }
} = useRuntimeConfig()

return ref(ENABLE_AUTOMATE_MODULE)
return ref(FF_AUTOMATE_MODULE_ENABLED)
}

export { useGlobalToast, useActiveUser }
32 changes: 28 additions & 4 deletions packages/server/modules/automate/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
import { moduleLogger } from '@/logging/logging'
import { SpeckleModule } from '@/modules/shared/helpers/typeHelper'
import { ENABLE_AUTOMATE_MODULE } from '@/modules/shared/helpers/envHelper'
import { Optional, SpeckleModule } from '@/modules/shared/helpers/typeHelper'
import { VersionEvents, VersionsEmitter } from '@/modules/core/events/versionsEmitter'
import { onModelVersionCreate } from '@/modules/automate/services/trigger'
import { Environment } from '@speckle/shared'

let quitListeners: Optional<() => void> = undefined

const { FF_AUTOMATE_MODULE_ENABLED } = Environment.getFeatureFlags()

const automateModule: SpeckleModule = {
async init() {
if (!ENABLE_AUTOMATE_MODULE) return
async init(_, isInitial) {
if (!FF_AUTOMATE_MODULE_ENABLED) return
moduleLogger.info('⚙️ Init automate module')

if (isInitial) {
quitListeners = initializeEventListeners()
}
},
shutdown() {
if (!FF_AUTOMATE_MODULE_ENABLED) return
quitListeners?.()
}
}

export = automateModule

const initializeEventListeners = () => {
const quit = VersionsEmitter.listen(
VersionEvents.Created,
async ({ modelId, version }) => {
await onModelVersionCreate({ modelId, versionId: version.id })
}
)
return quit
}
4 changes: 2 additions & 2 deletions packages/server/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ async function getSpeckleModules() {
'./accessrequests',
'./webhooks',
'./cross-server-sync',
'./betaAutomations'
// './automate'
'./betaAutomations',
'./automate'
]

for (const dir of moduleDirs) {
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/environment/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { parseEnv } from 'znv'
import { z } from 'zod'

//INFO
// As a convention all feature flags should be prefixed with a FF_
const featureFlagSchema = z.object({
ENABLE_AUTOMATE_MODULE: z.boolean().default(false)
FF_AUTOMATE_MODULE_ENABLED: z.boolean().default(false)
})

function parseFeatureFlags() {
Expand Down
4 changes: 2 additions & 2 deletions utils/helm/speckle-server/templates/frontend_2/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ spec:
value: {{ .Values.analytics.datadog_env | quote }}
{{- end }}

- name: ENABLE_AUTOMATE_MODULE
value: {{ .Values.featureFlags.enableAutomateModule | quote }}
- name: FF_AUTOMATE_MODULE_ENABLED
value: {{ .Values.featureFlags.automateModuleEnabled | quote }}

priorityClassName: high-priority
{{- if .Values.frontend_2.affinity }}
Expand Down
4 changes: 2 additions & 2 deletions utils/helm/speckle-server/templates/server/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ spec:
- name: ENABLE_FE2_MESSAGING
value: {{ .Values.server.enableFe2Messaging | quote }}

- name: ENABLE_AUTOMATE_MODULE
value: {{ .Values.featureFlags.enableAutomateModule | quote }}
- name: FF_AUTOMATE_MODULE_ENABLED
value: {{ .Values.featureFlags.automateModuleEnabled | quote }}

- name: ONBOARDING_STREAM_URL
value: {{ .Values.server.onboarding.stream_url }}
Expand Down
2 changes: 1 addition & 1 deletion utils/helm/speckle-server/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"featureFlags": {
"type": "object",
"properties": {
"enableAutomateModule": {
"automateModuleEnabled": {
"type": "boolean",
"description": "High level flag fully toggles the integrated automate module",
"default": false
Expand Down
4 changes: 2 additions & 2 deletions utils/helm/speckle-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ cert_manager_issuer: letsencrypt-staging
## This object is a central location to define feature flags for the whole chart.
## @descriptionEnd
featureFlags:
## @param featureFlags.enableAutomateModule High level flag fully toggles the integrated automate module
enableAutomateModule: false
## @param featureFlags.automateModuleEnabled High level flag fully toggles the integrated automate module
automateModuleEnabled: false

analytics:
## @param analytics.enabled Enable or disable analytics
Expand Down

0 comments on commit 139065b

Please sign in to comment.