Skip to content

Commit 22a4bdc

Browse files
Merge pull request #267522 from zhiyuanliang-ms/zhiyuanliang/update-how-to-use-feature-filter
Azure App Configuration - Use TimeWindowFilter as example in feature filter tutorial
2 parents a2cabcb + 31e36f0 commit 22a4bdc

File tree

5 files changed

+30
-27
lines changed

5 files changed

+30
-27
lines changed

articles/azure-app-configuration/howto-feature-filters-aspnet-core.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ description: Learn how to use feature filters in Azure App Configuration to enab
55
ms.service: azure-app-configuration
66
ms.devlang: csharp
77
ms.custom: devx-track-csharp
8-
author: maud-lv
9-
ms.author: malev
8+
author: zhiyuanliang
9+
ms.author: zhiyuanliang
1010
ms.topic: how-to
11-
ms.date: 01/12/2024
11+
ms.date: 02/28/2024
1212
#Customerintent: As a developer, I want to create a feature filter to activate a feature flag depending on a specific scenario.
1313
---
1414

@@ -18,68 +18,71 @@ Feature flags allow you to activate or deactivate functionality in your applicat
1818

1919
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.
2020

21-
The `Microsoft.FeatureManagement` library includes three feature filters:
21+
The `Microsoft.FeatureManagement` library includes the following built-in feature filters accessible from the Azure App Configuration portal.
2222

23-
- `PercentageFilter` enables the feature flag based on a percentage.
24-
- `TimeWindowFilter` enables the feature flag during a specified window of time.
25-
- `TargetingFilter` enables the feature flag for specified users and groups.
23+
- **Time window filter** enables the feature flag during a specified window of time.
24+
- **Targeting filter** enables the feature flag for specified users and groups.
2625

27-
You can also create your own feature filter that implements the Microsoft.FeatureManagement.IFeatureFilter interface.
26+
You can also create your own feature filter that implements the `Microsoft.FeatureManagement.IFeatureFilter` interface. For more information, see [Implementing a Feature Filter](https://github.com/microsoft/FeatureManagement-Dotnet#implementing-a-feature-filter).
2827

2928
## Prerequisites
3029

31-
- An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
30+
- 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.
31+
- Install the [`Microsoft.FeatureManagement.AspNetCore`](https://www.nuget.org/packages/Microsoft.FeatureManagement.AspNetCore/) package of version **3.0.0** or later.
3232

3333
## Register a feature filter
3434

35-
You register a feature filter by calling the `AddFeatureFilter` method, specifying the type name of the desired feature filter. For example, the following code registers `PercentageFilter`:
35+
If you have a [custom feature filter](https://github.com/microsoft/FeatureManagement-Dotnet#implementing-a-feature-filter), you can register it by calling the `AddFeatureFilter` method.
3636

3737
```csharp
38-
public void ConfigureServices(IServiceCollection services)
39-
{
40-
services.AddControllersWithViews();
41-
services.AddFeatureManagement().AddFeatureFilter<PercentageFilter>();
42-
}
38+
services.AddFeatureManagement()
39+
.AddFeatureFilter<MyCriteriaFilter>();
4340
```
4441

45-
## Configure a feature filter in Azure App Configuration
42+
Starting with version *3.0.0* of `Microsoft.FeatureManagement`, the following [built-in filters](https://github.com/microsoft/FeatureManagement-Dotnet#built-in-feature-filters) are registered automatically as part of the `AddFeatureManagement` call, so you don't need to register them.
4643

47-
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.
44+
- `TimeWindowFilter`
45+
- `ContextualTargetingFilter`
46+
- `PercentageFilter`
4847

49-
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:
48+
> [!TIP]
49+
> For more information on using `TargetingFilter`, see [Enable staged rollout of features for targeted audiences](./howto-targetingfilter-aspnet-core.md).
5050
51-
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.
51+
## Add a feature filter to a feature flag
52+
53+
In this section, you will learn how to add a feature filter to the **Beta** feature flag you created in the [Quickstart](./quickstart-feature-flag-aspnet-core.md). The following steps use the built-in `TimeWindowFilter` as an example.
5254

5355
1. In the Azure portal, go to your configuration store and select **Feature manager**.
5456

55-
:::image type="content" source="./media/feature-filters/edit-beta-feature-flag.png" alt-text="Screenshot of the Azure portal, selecting the Edit option for the Beta feature flag, under Feature manager.":::
57+
:::image type="content" source="./media/feature-filters/edit-beta-feature-flag.png" alt-text="Screenshot of the Azure portal, selecting the Edit option for the **Beta** feature flag, under Feature manager.":::
5658

57-
1. On the line with the Beta feature flag you created in the quickstart, select the context menu and then **Edit**.
59+
1. On the line with the **Beta** feature flag you created in the quickstart, select the context menu and then **Edit**.
5860

5961
1. In the **Edit feature flag** pane that opens, check the **Enable feature flag** checkbox if it isn't already enabled. Then check the **Use feature filter** checkbox and select **Create**.
6062

6163
:::image type="content" source="./media/feature-filters/edit-a-feature-flag.png" alt-text="Screenshot of the Azure portal, filling out the form 'Edit feature flag'.":::
6264

63-
1. The pane **Create a new filter** opens. Under **Filter type**, select **Targeting filter** to enable a new filter for specific users or a group.
65+
1. The pane **Create a new filter** opens. Under **Filter type**, select **Time window filter**.
66+
67+
:::image type="content" source="./media/feature-filters/add-time-window-filter.png" alt-text="Screenshot of the Azure portal, creating a new time window filter.":::
6468

65-
:::image type="content" source="./media/feature-filters/add-targeting-filter.png" alt-text="Screenshot of the Azure portal, creating a new targeting filter.":::
69+
1. Set the **Start date** to **Custom** and select a time a few minutes ahead of your current time. Set the **Expiry date** to **Never**
6670

67-
1. Optionally expand the **Evaluation flow** menu to see a graph showing how the targeting filter is evaluated in the selected scenario. Leave the **Default Percentage** at 50. The options **Override by Groups** and **Override by Users** let you enable or disable the feature flag for select groups or users. These options are disabled by default.
6871
1. Select **Add** to save the new feature filter and return to the **Edit feature flag** screen.
6972

7073
1. The feature filter you created is now listed in the feature flag details. Select **Apply** to save the new feature flag settings.
7174

72-
:::image type="content" source="./media/feature-filters/feature-flag-edit-apply-filter.png" alt-text="Screenshot of the Azure portal, applying new targeting filter.":::
75+
:::image type="content" source="./media/feature-filters/feature-flag-edit-apply-filter.png" alt-text="Screenshot of the Azure portal, applying new time window filter.":::
7376

7477
1. On the **Feature manager** page, the feature flag now has a **Feature filter(s)** value of **1**.
7578

7679
:::image type="content" source="./media/feature-filters/updated-feature-flag.png" alt-text="Screenshot of the Azure portal, displaying updated feature flag.":::
7780

7881
## Feature filters in action
7982

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.
83+
Relaunch the application you created in the [Quickstart](./quickstart-feature-flag-aspnet-core.md). If your current time is earlier than the start time set for the time window filter, the **Beta** menu item will not appear on the toolbar. This is because the **Beta** feature flag is disabled by the time window filter.
8184

82-
:::image type="content" source="./media/feature-filters/feature-flags-percentagefilter.gif" alt-text="Screenshot of a web browser showing a targeting filter in action.":::
85+
Once the start time has passed, refresh your browser a few times. You will notice that the **Beta** menu item will now appear. This is because the **Beta** feature flag is now enabled by the time window filter.
8386

8487
## Next steps
8588

Binary file not shown.
49.3 KB
Loading
19.8 KB
Loading

0 commit comments

Comments
 (0)