-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feature-flags): use flipt as feature flag service (#486)
* feat(feature-flags): create basic support for feature flags * feat(feature-flags): add github actions for feature flags * feat(feature-flags): make feature flag evaluation context easier * fix(triage): properly hide tasks behind feature flag for triage editor * docs(feature-flags): update development docs for feature flags * fix: properly close the provider
- Loading branch information
1 parent
e571e7c
commit fad5799
Showing
11 changed files
with
267 additions
and
91 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,3 @@ | ||
version: "1.0" | ||
include: | ||
- "ui/features.yaml" |
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 |
---|---|---|
|
@@ -11,6 +11,23 @@ on: | |
- "main" | ||
- "develop" | ||
jobs: | ||
featureflags: | ||
runs-on: ubuntu-latest | ||
name: "Validate & Push Feature Flags" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- uses: flipt-io/[email protected] | ||
- run: flipt validate | ||
- name: Build and Push bundle | ||
# only build and push feature flags from the develop branch | ||
if: github.ref == 'refs/heads/develop' | ||
env: | ||
FLIPT_STORAGE_OCI_AUTHENTICATION_USERNAME: ${{ github.actor }} | ||
FLIPT_STORAGE_OCI_AUTHENTICATION_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
flipt bundle build sitrep-featureflags:latest | ||
flipt bundle push sitrep-featureflags:latest ghcr.io/f-eld-ch/sitrep/featureflags:develop | ||
build: | ||
runs-on: ubuntu-latest | ||
name: "Test and Build" | ||
|
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,32 @@ | ||
version: "1.2" | ||
namespace: sitrep-ui | ||
flags: | ||
# nimdanitro: flag for rolling out tasks Module, remove after tasks modules is GA | ||
- key: show-tasks | ||
name: Show Tasks | ||
type: BOOLEAN_FLAG_TYPE | ||
description: Show the task module (Pendenzen) | ||
enabled: false | ||
rollouts: | ||
- segment: | ||
key: Development | ||
value: true | ||
# nimdanitro: flag for rolling out Resources Module, remove after resources modules is GA | ||
- key: show-resources | ||
name: Show Resources | ||
type: BOOLEAN_FLAG_TYPE | ||
description: Show the resources module (Mittel) | ||
enabled: false | ||
rollouts: | ||
- segment: | ||
key: Development | ||
value: true | ||
segments: | ||
- key: Development | ||
name: Development | ||
constraints: | ||
- type: STRING_COMPARISON_TYPE | ||
property: domain | ||
operator: isoneof | ||
value: '["dev.sitrep.ch","localhost","127.0.0.1"]' | ||
match_type: ALL_MATCH_TYPE |
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,51 @@ | ||
import { EvaluationContext, OpenFeatureProvider, OpenFeature, InMemoryProvider } from "@openfeature/react-sdk"; | ||
import { FliptWebProvider } from "@openfeature/flipt-web-provider"; | ||
import { PropsWithChildren, useEffect, useContext } from "react"; | ||
|
||
import { UserContext } from "utils"; | ||
|
||
const localFlagConfig = { | ||
"new-message": { | ||
disabled: false, | ||
variants: { | ||
on: true, | ||
off: false, | ||
}, | ||
defaultVariant: "on", | ||
contextEvaluator: (context: EvaluationContext) => { | ||
if (context.silly) { | ||
return "on"; | ||
} | ||
return "off"; | ||
}, | ||
}, | ||
}; | ||
|
||
const Provider = (props: PropsWithChildren) => { | ||
const { children } = props; | ||
const userState = useContext(UserContext); | ||
|
||
useEffect(() => { | ||
const fliptProvider = new FliptWebProvider("sitrep-ui", { url: "https://flipt.sitrep.ch" }); | ||
OpenFeature.setProvider("local", new InMemoryProvider(localFlagConfig)); | ||
OpenFeature.setProvider(fliptProvider); | ||
}, []); | ||
|
||
// sync the evaulation context here, so far only depends on domain and UserContext state | ||
useEffect(() => { | ||
const context = { | ||
domain: document.location.host.split(":")[0], | ||
email: userState.email, | ||
}; | ||
OpenFeature.setContext(context); | ||
|
||
return () => { | ||
console.log("closing openfeature provider"); | ||
OpenFeature.close(); | ||
}; | ||
}, [userState]); | ||
|
||
return <OpenFeatureProvider>{children}</OpenFeatureProvider>; | ||
}; | ||
|
||
export { Provider }; |
Oops, something went wrong.