Skip to content

Commit 204f7a6

Browse files
authored
Merge pull request #274815 from MicrosoftDocs/main
Merge main to live, 4 AM
2 parents 0bceadf + b43ff9e commit 204f7a6

File tree

49 files changed

+569
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+569
-254
lines changed

articles/api-management/api-management-gateways-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ Managed and self-hosted gateways support all available [policies](api-management
129129

130130
<sup>1</sup> Configured policies that aren't supported by the self-hosted gateway are skipped during policy execution.<br/>
131131
<sup>2</sup> The quota by key policy isn't available in the v2 tiers.<br/>
132-
<sup>2</sup> The rate limit by key and quota by key policies aren't available in the Consumption tier.<br/>
133-
<sup>3</sup> [!INCLUDE [api-management-self-hosted-gateway-rate-limit](../../includes/api-management-self-hosted-gateway-rate-limit.md)] [Learn more](how-to-self-hosted-gateway-on-kubernetes-in-production.md#request-throttling)
132+
<sup>3</sup> The rate limit by key and quota by key policies aren't available in the Consumption tier.<br/>
133+
<sup>4</sup> [!INCLUDE [api-management-self-hosted-gateway-rate-limit](../../includes/api-management-self-hosted-gateway-rate-limit.md)] [Learn more](how-to-self-hosted-gateway-on-kubernetes-in-production.md#request-throttling)
134134

135135

136136
### Monitoring

articles/azure-app-configuration/TOC.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,24 @@
126126
href: use-feature-flags-dotnet-core.md
127127
- name: Spring Boot
128128
href: use-feature-flags-spring-boot.md
129-
- name: Use conditional feature flags
130-
href: howto-feature-filters-aspnet-core.md
131-
- name: Enable a feature for specified users/groups
132-
href: howto-targetingfilter-aspnet-core.md
129+
- name: Enable conditional features with feature filters
130+
items:
131+
- name: Overview
132+
href: howto-feature-filters.md
133+
- name: ASP.NET Core
134+
href: howto-feature-filters-aspnet-core.md
135+
- name: Enable features on a schedule
136+
items:
137+
- name: Overview
138+
href: howto-timewindow-filter.md
139+
- name: ASP.NET Core
140+
href: howto-timewindow-filter-aspnet-core.md
141+
- name: Roll out features to targeted audience
142+
items:
143+
- name: Overview
144+
href: howto-targetingfilter.md
145+
- name: ASP.NET Core
146+
href: howto-targetingfilter-aspnet-core.md
133147
- name: Enable Azure monitoring
134148
items:
135149
- name: Monitor App Configuration
Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,96 @@
11
---
2-
title: Use feature filters to enable conditional feature flags
2+
title: Enable conditional features with a custom filter in an ASP.NET Core application
33
titleSuffix: Azure App Configuration
4-
description: Learn how to use feature filters in Azure App Configuration to enable conditional feature flags for your app.
4+
description: Learn how to implement a custom feature filter to enable conditional feature flags for your ASP.NET Core application.
55
ms.service: azure-app-configuration
66
ms.devlang: csharp
77
ms.custom: devx-track-csharp
88
author: zhiyuanliang
99
ms.author: zhiyuanliang
1010
ms.topic: how-to
11-
ms.date: 02/28/2024
12-
#Customerintent: As a developer, I want to create a feature filter to activate a feature flag depending on a specific scenario.
11+
ms.date: 03/28/2024
1312
---
1413

15-
# Use feature filters to enable conditional feature flags
14+
# Tutorial: Enable conditional features with a custom filter in an ASP.NET Core application
1615

17-
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.
16+
Feature flags can use feature filters to enable features conditionally. To learn more about feature filters, see [Tutorial: Enable conditional features with feature filters](./howto-feature-filters.md).
1817

19-
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.
18+
The example used in this tutorial is based on the ASP.NET Core application introduced in the feature management [quickstart](./quickstart-feature-flag-aspnet-core.md). Before proceeding further, complete the quickstart to create an ASP.NET Core application with a *Beta* feature flag. Once completed, you must [add a custom feature filter](./howto-feature-filters.md) to the *Beta* feature flag in your App Configuration store.
2019

21-
The `Microsoft.FeatureManagement` library includes the following built-in feature filters accessible from the Azure App Configuration portal.
22-
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.
25-
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).
20+
In this tutorial, you'll learn how to implement a custom feature filter and use the feature filter to enable features conditionally.
2721

2822
## Prerequisites
2923

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.
32-
33-
## Register a feature filter
34-
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.
24+
- Create an [ASP.NET Core app with a feature flag](./quickstart-feature-flag-aspnet-core.md).
25+
- [Add a custom feature filter to the feature flag](./howto-feature-filters.md)
3626

37-
```csharp
38-
services.AddFeatureManagement()
39-
.AddFeatureFilter<MyCriteriaFilter>();
40-
```
27+
## Implement a custom feature filter
4128

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.
29+
You've added a custom feature filter named **Random** with a **Percentage** parameter for your *Beta* feature flag in the prerequisites. Next, you'll implement the feature filter to enable the *Beta* feature flag based on the chance defined by the **Percentage** parameter.
4330

44-
- `TimeWindowFilter`
45-
- `ContextualTargetingFilter`
46-
- `PercentageFilter`
31+
1. Add a `RandomFilter.cs` file with the following code.
4732

48-
> [!TIP]
49-
> For more information on using `TargetingFilter`, see [Enable staged rollout of features for targeted audiences](./howto-targetingfilter-aspnet-core.md).
33+
```csharp
34+
using Microsoft.FeatureManagement;
5035

51-
## Add a feature filter to a feature flag
36+
namespace TestAppConfig
37+
{
38+
[FilterAlias("Random")]
39+
public class RandomFilter : IFeatureFilter
40+
{
41+
private readonly Random _random;
5242

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.
43+
public RandomFilter()
44+
{
45+
_random = new Random();
46+
}
5447

55-
1. In the Azure portal, go to your configuration store and select **Feature manager**.
48+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context)
49+
{
50+
int percentage = context.Parameters.GetSection("Percentage").Get<int>();
5651

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.":::
52+
int randomNumber = _random.Next(100);
5853

59-
1. On the line with the **Beta** feature flag you created in the quickstart, select the context menu and then **Edit**.
54+
return Task.FromResult(randomNumber <= percentage);
55+
}
56+
}
57+
}
58+
```
6059

61-
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**.
60+
You added a `RandomFilter` class that implements the `IFeatureFilter` interface from the `Microsoft.FeatureManagement` library. The `IFeatureFilter` interface has a single method named `EvaluateAsync`, which is called whenever a feature flag is evaluated. In `EvaluateAsync`, a feature filter enables a feature flag by returning `true`.
6261

63-
:::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'.":::
62+
You decorated a `FilterAliasAttribute` to the `RandomFilter` to give your filter an alias **Random**, which matches the filter name you set in the *Beta* feature flag in Azure App Configuration.
6463

65-
1. The pane **Create a new filter** opens. Under **Filter type**, select **Time window filter**.
64+
1. Open the *Program.cs* file and register the `RandomFilter` by calling the `AddFeatureFilter` method.
6665

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.":::
66+
```csharp
67+
// The rest of existing code in Program.cs
68+
// ... ...
6869
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**
70+
// Add feature management to the container of services.
71+
builder.Services.AddFeatureManagement()
72+
.AddFeatureFilter<RandomFilter>();
7073

71-
1. Select **Add** to save the new feature filter and return to the **Edit feature flag** screen.
74+
// The rest of existing code in Program.cs
75+
// ... ...
76+
```
7277

73-
1. The feature filter you created is now listed in the feature flag details. Select **Apply** to save the new feature flag settings.
78+
## Feature filter in action
7479

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.":::
80+
Relaunch the application and refresh the browser a few times. Without manually toggling the feature flag, you will see that the **Beta** menu sometimes appears and sometimes doesn't.
7681

77-
1. On the **Feature manager** page, the feature flag now has a **Feature filter(s)** value of **1**.
82+
> [!div class="mx-imgBorder"]
83+
> ![Screenshot of browser with Beta menu hidden.](./media/quickstarts/aspnet-core-feature-flag-local-before.png)
7884

79-
:::image type="content" source="./media/feature-filters/updated-feature-flag.png" alt-text="Screenshot of the Azure portal, displaying updated feature flag.":::
85+
> [!div class="mx-imgBorder"]
86+
> ![Screenshot of browser with Beta menu.](./media/quickstarts/aspnet-core-feature-flag-local-after.png)
8087

81-
## Feature filters in action
82-
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.
88+
## Next steps
8489

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.
90+
To learn more about the built-in feature filters, continue to the following tutorials.
8691

87-
## Next steps
92+
> [!div class="nextstepaction"]
93+
> [Enable features on a schedule](./howto-timewindow-filter.md)
8894

8995
> [!div class="nextstepaction"]
90-
> [Enable staged rollout of features for targeted audiences](./howto-targetingfilter-aspnet-core.md)
96+
> [Roll out features to targeted audience](./howto-targetingfilter.md)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: Enable conditional features with feature filters
3+
titleSuffix: Azure App Configuration
4+
description: Learn how to use feature filters in Azure App Configuration to enable conditional feature flags for your application.
5+
ms.service: azure-app-configuration
6+
ms.devlang: csharp
7+
ms.custom: devx-track-csharp
8+
author: zhiyuanliang
9+
ms.author: zhiyuanliang
10+
ms.topic: how-to
11+
ms.date: 03/21/2024
12+
#Customerintent: As a developer, I want to create a feature filter to activate a feature flag depending on a specific scenario.
13+
---
14+
15+
# Tutorial: Enable conditional features with feature filters
16+
17+
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.
18+
19+
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.
20+
21+
## What is a feature filter?
22+
23+
_Feature filters_ are conditions for determining the state of the feature flag. Adding feature filters to a feature flag allows you to invoke custom code each time the feature flag is evaluated.
24+
25+
The Microsoft feature management libraries include the following built-in feature filters configurable from the Azure App Configuration portal.
26+
27+
- **Time window filter** enables the feature flag during a specified window of time.
28+
- **Targeting filter** enables the feature flag for specified users and groups.
29+
30+
You can create custom feature filters that enable features based on your specific criteria in code. This article will guide you through adding a custom feature filter to a feature flag. Afterward, you can follow the instructions in the *Next Steps* section to implement the feature filter in your application.
31+
32+
## Add a custom feature filter
33+
34+
1. Create a feature flag named *Beta* in your App Configuration store and open to edit it. For more information about how to add and edit a feature flag, see [Manage feature flags](./manage-feature-flags.md).
35+
36+
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**.
37+
38+
> [!div class="mx-imgBorder"]
39+
> ![Screenshot of the Azure portal, filling out the form 'Edit feature flag'.](./media/feature-filters/edit-a-feature-flag.png)
40+
41+
1. The pane **Create a new filter** opens. Under **Filter type**, select **Custom filter** and enter the name *Random* for your custom filter.
42+
43+
> [!div class="mx-imgBorder"]
44+
> ![Screenshot of the Azure portal, creating a new custom filter.](./media/feature-filters/add-custom-filter.png)
45+
46+
1. Feature filters can optionally use parameters for configurable conditions. In this example, you use a **Percentage** parameter and set its value to **50**, which tells the filter to enable the feature flag with a 50% chance.
47+
48+
> [!div class="mx-imgBorder"]
49+
> ![Screenshot of the Azure portal, adding paramters for the custom filter.](./media/feature-filters/add-custom-filter-parameter.png)
50+
51+
1. Select **Add** to save the new feature filter and return to the **Edit feature flag** screen.
52+
53+
1. The feature filter is now listed in the feature flag details. Select **Apply** to save the feature flag.
54+
55+
> [!div class="mx-imgBorder"]
56+
> ![Screenshot of the Azure portal, applying new custom filter.](./media/feature-filters/feature-flag-edit-apply-filter.png)
57+
58+
You have successfully added a custom filter to a feature flag. Follow the instructions in the [Next Steps](#next-steps) section to implement the feature filter into your application for the language or platform you are using.
59+
60+
## Next steps
61+
62+
In this tutorial, you learned the concept of feature filter and added a custom feature filter to a feature flag.
63+
64+
To learn how to implement a custom feature filter, continue to the following tutorial:
65+
66+
> [!div class="nextstepaction"]
67+
> [ASP.NET Core](./howto-feature-filters-aspnet-core.md)
68+
69+
To learn more about the built-in feature filters, continue to the following tutorials:
70+
71+
> [!div class="nextstepaction"]
72+
> [Enable features on a schedule](./howto-timewindow-filter.md)
73+
74+
> [!div class="nextstepaction"]
75+
> [Roll out features to targeted audience](./howto-targetingfilter.md)

0 commit comments

Comments
 (0)