Skip to content

Commit 5023b9f

Browse files
authored
Merge pull request #107207 from lisaguthrie/6037756-featurefilters
Feature filters howto
2 parents 62e5a38 + adf82eb commit 5023b9f

7 files changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: Use feature filters to enable a feature for a subset of users
3+
titleSuffix: Azure App Configuration
4+
description: Learn how to use feature filters to enable a feature for a subset of users
5+
ms.service: azure-app-configuration
6+
author: lisaguthrie
7+
8+
ms.service: azure-app-configuration
9+
ms.topic: conceptual
10+
ms.date: 3/9/2020
11+
ms.author: lcozzens
12+
13+
---
14+
# Use feature filters to enable a feature for a subset of users
15+
16+
Feature flags allow you to activate or deactivate functionality in your application. A simple feature flag is either on or off. The application always behaves the same way. For example, you could roll out a new feature behind a feature flag. When the feature flag is enabled, all users see the new feature. Disabling the feature flag hides the new feature.
17+
18+
In contrast, a _conditional feature flag_ allows the feature flag to be enabled or disabled dynamically. The application may behave differently, depending on the feature flag criteria. Suppose you want to show your new feature to a small subset of users at first. A conditional feature flag allows you to enable the feature flag for some users while disabling it for others. _Feature filters_ determine the state of the feature flag each time it's evaluated.
19+
20+
The `Microsoft.FeatureManagement` library includes two feature filters:
21+
22+
- `PercentageFilter` enables the feature flag based on a percentage.
23+
- `TimeWindowFilter` enables the feature flag during a specified window of time.
24+
25+
You can also create your own feature filter that implements the [Microsoft.FeatureManagement.IFeatureFilter interface](/dotnet/api/microsoft.featuremanagement.ifeaturefilter).
26+
27+
## Registering a feature filter
28+
29+
You register a feature filter by calling the `AddFeatureFilter` method, specifying the name of the feature filter. For example, the following code registers `PercentageFilter`:
30+
31+
```csharp
32+
public void ConfigureServices(IServiceCollection services)
33+
{
34+
services.AddControllersWithViews();
35+
services.AddFeatureManagement().AddFeatureFilter<PercentageFilter>();
36+
}
37+
```
38+
39+
## Configuring a feature filter in Azure App Configuration
40+
41+
Some feature filters have additional settings. For example, `PercentageFilter` activates a feature based on a percentage. It has a setting defining the percentage to use.
42+
43+
You can configure these settings for feature flags defined in Azure App Configuration. For example, follow these steps to use `PercentageFilter` to enable the feature flag for 50% of requests to a web app:
44+
45+
1. Follow the instructions in [Quickstart: Add feature flags to an ASP.NET Core app](./quickstart-feature-flag-aspnet-core.md) to create a web app with a feature flag.
46+
47+
1. In the Azure portal, go to your configuration store and click **Feature Manager**.
48+
49+
1. Click on the context menu for the *Beta* feature flag that you created in the quickstart. Click **Edit**.
50+
51+
> [!div class="mx-imgBorder"]
52+
> ![Edit Beta feature flag](./media/edit-beta-feature-flag.png)
53+
54+
1. In the **Edit** screen, select the **On** radio button if it isn't already selected. Then click the **Add Filter** button. (The **On** radio button's label will change to read **Conditional**.)
55+
56+
1. In the **Key** field, enter *Microsoft.Percentage*.
57+
58+
> [!div class="mx-imgBorder"]
59+
> ![Add feature filter](./media/feature-flag-add-filter.png)
60+
61+
1. Click the context menu next to the feature filter key. Click **Edit Parameters**.
62+
63+
> [!div class="mx-imgBorder"]
64+
> ![Edit feature filter parameters](./media/feature-flag-edit-filter-parameters.png)
65+
66+
1. Hover under the **Name** header so that text boxes appear in the grid. Enter a **Name** of *Value* and a **Value** of 50. The **Value** field indicates the percentage of requests for which to enable the feature filter.
67+
68+
> [!div class="mx-imgBorder"]
69+
> ![Set feature filter parameters](./media/feature-flag-set-filter-parameters.png)
70+
71+
1. Click **Apply** to return to the **Edit feature flag** screen. Then click **Apply** again to save the feature flag settings.
72+
73+
1. The **State** of the feature flag now appears as *Conditional*. This state indicates that the feature flag will be enabled or disabled on a per-request basis, based on the criteria enforced by the feature filter.
74+
75+
> [!div class="mx-imgBorder"]
76+
> ![Conditional feature flag](./media/feature-flag-filter-enabled.png)
77+
78+
## Feature filters in action
79+
80+
To see the effects of this feature flag, launch the application and hit the **Refresh** button in your browser multiple times. You'll see that the *Beta* item appears on the toolbar about 50% of the time. It's hidden the rest of the time, because the `PercentageFilter` deactivates the *Beta* feature for a subset of requests. The following video shows this behavior in action.
81+
82+
> [!div class="mx-imgBorder"]
83+
> ![PercentageFilter in action](./media/feature-flags-percentagefilter.gif)
84+
85+
## Next steps
86+
87+
> [!div class="nextstepaction"]
88+
> [Feature management overview](./concept-feature-management.md)
92.1 KB
Loading
57.6 KB
Loading
61.6 KB
Loading
61.5 KB
Loading
23.2 KB
Loading
1.66 MB
Loading

0 commit comments

Comments
 (0)