You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: add feature flag for submitting quotes and update UI accordingly
- Implemented a new API endpoint to fetch feature flags.
- Updated the QuoteDisplay component to disable the submit link based on the feature flag.
- Modified the Home component to fetch the feature flag and control the submission of new quotes.
- Enhanced the SubmitQuote component to reflect the feature flag status and provide user feedback when submissions are disabled.
- Introduced a utility for managing feature flags using Unleash.
- Updated unleash configuration for quotes-loadgen.
* fix: update action versions in workflow files for consistency and stability
* feat: sanitize quote IDs for logging to enhance security and prevent logging of control characters
* fix: change Dependabot trigger to pull_request_target for improved security
* refactor: change quote ID type from string to int for improved validation and consistency
* feat: add security scan tasks for all services and update feature flag handling
* fix: update semgrep entry format in .mise.toml for consistency
Copy file name to clipboardExpand all lines: .github/workflows/codeql.yml
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -61,11 +61,11 @@ jobs:
61
61
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
Copy file name to clipboardExpand all lines: README.md
+65Lines changed: 65 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,71 @@ graph LR
115
115
116
116
```
117
117
118
+
## Feature Flags with Unleash
119
+
120
+
This project demonstrates [Unleash](https://docs.nais.io/services/feature-flagging/) feature flagging on the NAIS platform. Unleash lets you toggle features on and off without redeploying.
121
+
122
+
### How it works
123
+
124
+
Each service has an [Unleash API token](https://docs.nais.io/services/feature-flagging/#step-2-define-an-apitoken-for-your-application) defined in `.nais/unleash.yaml`. When deployed, the NAIS Unleash operator provisions a client token and stores it as a Kubernetes secret. The app reads the secret via `envFrom` in `.nais/app.yaml`:
125
+
126
+
```yaml
127
+
# .nais/app.yaml
128
+
envFrom:
129
+
- secret: quotes-backend-unleash-api-token
130
+
```
131
+
132
+
This provides the environment variables `UNLEASH_SERVER_API_URL`, `UNLEASH_SERVER_API_TOKEN`, and `UNLEASH_SERVER_API_ENVIRONMENT` to the application at runtime.
| `quotes.submit` | quotes-backend, quotes-frontend | Controls whether users can submit new quotes. When disabled, the backend returns 403 and the frontend hides/disables the submit button. |
139
+
| `quotes.errors` | quotes-backend | Enables simulated error injection (10% error rate on GET/POST endpoints). Default: **disabled**. Turn on to generate errors visible in dashboards and alerts. |
140
+
141
+
### Adding a new feature flag
142
+
143
+
1. **Create the toggle** in the [Unleash UI](http://localhost:4242) (or on NAIS at your team's Unleash instance)
144
+
2. **Check the flag in code:**
145
+
146
+
**Kotlin (backend):**
147
+
148
+
```kotlin
149
+
if (FeatureFlags.isEnabled("my.new.flag")) {
150
+
// feature code
151
+
}
152
+
```
153
+
154
+
**TypeScript (frontend, server-side):**
155
+
156
+
```typescript
157
+
import { isEnabled } from '@/utils/unleash';
158
+
const enabled = isEnabled('my.new.flag');
159
+
```
160
+
161
+
3. **Register the flag name** in `FeatureFlags.kt` (backend) or `unleash.ts` (frontend) so it appears in the `/api/features` endpoint
162
+
163
+
### Local development
164
+
165
+
Unleash runs locally via docker-compose on port 4242. The admin UI is at <http://localhost:4242>. Log in with the default credentials configured in `docker-compose.yaml` (username `admin`, password `unleash`).
166
+
167
+
To create the `quotes.submit` toggle locally:
168
+
169
+
1. Start infrastructure: `mise run infra:up`
170
+
2. Open <http://localhost:4242>
171
+
3. Create feature flags named `quotes.submit` and `quotes.errors` in the `development` environment
172
+
4. Enable or disable them to see the effect in the running application
173
+
174
+
The local client token `default:development.client-token` is pre-configured in both `.mise.toml` (for `mise run dev`) and `docker-compose.yaml`.
175
+
176
+
### Graceful degradation
177
+
178
+
When Unleash is unavailable (no env vars set, or server unreachable), feature flags fall back to their configured default values. These defaults are defined per flag in the backend/frontend and may be either enabled or disabled. This means:
179
+
180
+
- Tests can run without Unleash, using the configured default values for each flag
181
+
- A misconfigured Unleash connection won't break the application; features will follow their safe defaults
182
+
118
183
## License
119
184
120
185
The code in this repository is licensed under the MIT license. See [LICENSE](LICENSE) for more information.
0 commit comments