Skip to content

Commit 27d291a

Browse files
authored
Update environment variable names and clarify feature flag instructions (#19)
Signed-off-by: André Silva <[email protected]>
1 parent 2071d44 commit 27d291a

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

Workshop.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,21 @@ time with each exercise and don't hesitate to experiment!
3939
2. Toggle the Statistics Header
4040

4141
- Locate the environment variables in `src/Garage.AppHost/Properties/launchSettings.json`
42-
- Change the `ENABLE_STATS_HEADER` environment variable from `"true"` to `"false"`
42+
- Change the `EnableStatsHeader` environment variable from `"true"` to `"false"`
4343
- Restart the application to see the behavior change in the web frontend
4444
- Toggle it back to `"true"`
4545

4646
3. Verify the Changes
4747

4848
- Navigate to the web frontend
4949
- Confirm the statistics header appears/disappears based on your flag value
50-
- Check the Aspire dashboard for any relevant metrics
5150

5251
4. Create a New Feature Flag
5352

5453
- Add a new boolean flag in `IFeatureFlags.cs` (`EnableTabs`) making sure it is `true`
55-
- Implement it in `FeatureFlags.cs` to read from environment variable `ENABLE_TABS`
54+
- Implement it in `FeatureFlags.cs` to read from environment variable `EnableTabs`
5655
- Add the environment variable to `launchSettings.json` with value `"true"`
57-
- Use this flag in the `.collection-tabs` div in the `Home.razor` file
56+
- Use this flag in the `.collection-tabs` div in the `Home.razor` file. Tip: You can use the `ShowHeader` flag as a reference
5857

5958
### Expected Outcome
6059

@@ -87,12 +86,12 @@ You should see the statistics header toggle on and off based on your feature fla
8786
2. Configure OpenFeature in Extensions file
8887

8988
- Open `src/Garage.ServiceDefaults/Extensions.cs`
90-
- Add OpenFeature services in the `AddFeatureFlags` method, you can ignore the error for now
89+
- Add OpenFeature services in the `AddFeatureFlags` method
9190

9291
3. Implement a Custom Provider
9392

9493
- Create a new class `CustomFeatureProvider` in `src/Garage.ServiceDefaults/Providers`
95-
- Look at the `FeatureProvider` base class. Tip: You can try access the environment variables directly in the `CustomFeatureProvider` class
94+
- Look at the `FeatureProvider` base class. Tip: You can try access the environment variables directly in the `CustomFeatureProvider` class. Tip: You can skip implementing the `ResolveStructureValueAsync` method for now
9695
- Add the provider to the OpenFeature configuration in `Extensions.cs`
9796

9897
4. Replace the IFeatureFlags dependency injection
@@ -102,7 +101,7 @@ You should see the statistics header toggle on and off based on your feature fla
102101
5. Make sure to use the UserId in the OpenFeature context
103102

104103
- Use the `_userId` property in the `Home.razor` file to set the user context for OpenFeature
105-
- Ensure the OpenFeature client is aware of the user context
104+
- Ensure the OpenFeature client is aware of the user context. Tip: Have a look at the `EvaluationContext` class.
106105

107106
### Expected Outcome
108107

@@ -151,7 +150,7 @@ see the custom provider in action, and the feature flags should be evaluated bas
151150
4. Configure the flagd dependents
152151

153152
- Open `src/Garage.AppHost/Program.cs`
154-
- Modify the `apiservice` and `webfrontend` services to depend on the `flagd` service
153+
- Modify the `apiservice` and `webfrontend` services to wait for the `flagd` service
155154

156155
### Expected Outcome
157156

@@ -179,30 +178,29 @@ reflected in real-time without restarting the application.
179178

180179
1. Understand the SlowOperationDelay Flag
181180

182-
- Examine the `SlowOperationDelay` property in `IFeatureFlags.cs`
183181
- Find where this delay is implemented in the API service
184-
- Note the default value (1000ms)
185182

186183
2. Experiment with Different Delays
187184

185+
- Locate the `SlowOperationDelay` flag in `flagd.json`
188186
- Change the delay to different values:
189187
- `0` (no delay)
190188
- `500` (fast)
191189
- `1000` (default)
192190
- `2000` (slow)
193191
- `5000` (very slow)
192+
- Add a new integer flag for `SlowOperationDelay` in `flagd.json`. For example: `10000` (time to grab a coffee). Tip: This might break the application, so you can have a look into the aspire dashboard to see the error logs
194193
- Test each configuration and observe the impact
195194

196195
3. Monitor Performance Impact
197196

198-
- Use the Aspire dashboard to monitor request times
199197
- Compare response times with different delay values
200198
- Note how this affects user experience
201199

202200
4. Implement a Dynamic Configuration
203201

204202
- Consider how you might change this value without redeploying
205-
- Think about gradual rollout scenarios (e.g., 10% of users get faster performance)
203+
- Think about gradual rollout scenarios (e.g., 90% of users get faster performance)
206204
- Look into <https://flagd.dev/playground/> for the fractional rollout feature example
207205

208206
### Expected Outcome
@@ -238,7 +236,7 @@ You'll understand how integer flags can control performance characteristics and
238236
2. Test Data Source Switching
239237

240238
- Start with `EnableDatabaseWinners = false` (JSON source)
241-
- View the winners data in the web application
239+
- Remove the 2024 winner from the JSON file
242240
- Change to `EnableDatabaseWinners = true` (database source)
243241
- Compare the data between sources
244242

@@ -248,11 +246,6 @@ You'll understand how integer flags can control performance characteristics and
248246
- Consider error handling scenarios
249247
- Think about data consistency during transitions
250248

251-
4. Add Your Own Data
252-
253-
- Add a new winner record to the JSON file
254-
- Toggle between sources to see different datasets
255-
256249
### Expected Outcome
257250

258251
You'll see how feature flags can safely control major architectural decisions and enable smooth data migrations.
@@ -278,15 +271,15 @@ You'll see how feature flags can safely control major architectural decisions an
278271
1. Use the flag `EnableStatsHeader`
279272

280273
- Using the `EnableStatsHeader` flag, implement a simple A/B test
281-
- Use the `EvaluationContext` to differentiate between users, making sure to use the `_userId` property as the targetingKey
274+
- Use the `EvaluationContext` to differentiate between users, making sure to use the `_userId` property
282275
- Use the "Change User ID" button on the homepage to simulate different users by changing your user ID
283276
- Observe how the tabs are displayed in the web application
284277

285278
2. Create a new configuration in flagd for `EnableTabs`
286279

287280
- Add a new flag in `flagd.json` for `EnableTabs`
288281
- Set it to `true` for some users and `false` for others
289-
- Use the `EvaluationContext` to differentiate between users
282+
- Don't forget to refresh the browser to see the changes
290283

291284
### Expected Outcome
292285

@@ -319,7 +312,7 @@ You will have implemented a basic A/B test using feature flags, allowing you to
319312

320313
2. Visualize Flag Usage
321314

322-
- Open the Aspire dashboard at <https://localhost:15888>
315+
- Open the Aspire dashboard
323316
- Visit the `Traces` section
324317
- Look for traces related to feature flag evaluations
325318
- Check the `Metrics` section for flag usage statistics

src/Garage.AppHost/Properties/launchSettings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"DOTNET_ENVIRONMENT": "Development",
1212
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21198",
1313
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22178",
14-
"SLOW_OPERATION_DELAY": "1000",
15-
"ENABLE_DATABASE_WINNERS": "false",
16-
"ENABLE_STATS_HEADER": "true"
14+
"SlowOperationDelay": "1000",
15+
"EnableDatabaseWinners": "false",
16+
"EnableStatsHeader": "false"
1717
}
1818
},
1919
"http": {
@@ -26,9 +26,9 @@
2626
"DOTNET_ENVIRONMENT": "Development",
2727
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19055",
2828
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20286",
29-
"SLOW_OPERATION_DELAY": "1000",
30-
"ENABLE_DATABASE_WINNERS": "false",
31-
"ENABLE_STATS_HEADER": "true"
29+
"SlowOperationDelay": "1000",
30+
"EnableDatabaseWinners": "false",
31+
"EnableStatsHeader": "true"
3232
}
3333
}
3434
}

src/Garage.ServiceDefaults/Services/FeatureFlags.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Garage.ServiceDefaults.Services;
22

33
public class FeatureFlags : IFeatureFlags
44
{
5-
public int SlowOperationDelay => int.TryParse(Environment.GetEnvironmentVariable("SLOW_OPERATION_DELAY"), out var delay) ? delay : 1000;
6-
public bool EnableDatabaseWinners => bool.TryParse(Environment.GetEnvironmentVariable("ENABLE_DATABASE_WINNERS"), out var enable) ? enable : false;
7-
public bool EnableStatsHeader => bool.TryParse(Environment.GetEnvironmentVariable("ENABLE_STATS_HEADER"), out var enable) ? enable : true; // Default to true
5+
public int SlowOperationDelay => int.TryParse(Environment.GetEnvironmentVariable(nameof(SlowOperationDelay)), out var delay) ? delay : 1000;
6+
public bool EnableDatabaseWinners => bool.TryParse(Environment.GetEnvironmentVariable(nameof(EnableDatabaseWinners)), out var enable) ? enable : false;
7+
public bool EnableStatsHeader => bool.TryParse(Environment.GetEnvironmentVariable(nameof(EnableStatsHeader)), out var enable) ? enable : true; // Default to true
88
}

0 commit comments

Comments
 (0)