-
Notifications
You must be signed in to change notification settings - Fork 118
Adds cancellationtoken to the FeatureEvaluationContext- and respects … #532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…CancellationToken throughout evaluation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a cancellation mechanism to the feature evaluation process in the Microsoft.FeatureManagement library, allowing for early termination during long-running feature evaluations.
- Added a CancellationToken property to FeatureFilterEvaluationContext.
- Integrated cancellation checks into the IsEnabledAsync and AssignVariantAsync methods to handle cancellation requests efficiently.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Microsoft.FeatureManagement/FeatureManager.cs | Added cancellation checks in evaluation loops for feature enabled and variant assignment methods. |
src/Microsoft.FeatureManagement/FeatureFilterEvaluationContext.cs | Added a CancellationToken property to support cancellation in feature filters. |
@@ -472,6 +472,11 @@ private async ValueTask<bool> IsEnabledAsync<TContext>(FeatureDefinition feature | |||
// For all enabling filters listed in the feature's state, evaluate them according to requirement type | |||
foreach (FeatureFilterConfiguration featureFilterConfiguration in featureDefinition.EnabledFor) | |||
{ | |||
if (cancellationToken.IsCancellationRequested) | |||
{ | |||
cancellationToken.ThrowIfCancellationRequested(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The surrounding if statement isn't needed. Note the If
in the method name.
/// <summary> | ||
/// A cancellation token that can be used to request cancellation of the feature evaluation operation. | ||
/// </summary> | ||
public CancellationToken CancellationToken { get; set; } = CancellationToken.None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a struct, no need for an initializer.
This pull request introduces a cancellation mechanism to the feature evaluation process in the
Microsoft.FeatureManagement
library. The changes ensure that long-running feature evaluations can be cancelled if needed, improving the responsiveness and control over feature management operations.Key changes include:
Cancellation Token Integration:
src/Microsoft.FeatureManagement/FeatureFilterEvaluationContext.cs
: Added aCancellationToken
property to theFeatureFilterEvaluationContext
class to support cancellation of feature evaluation operations.Cancellation Checks:
src/Microsoft.FeatureManagement/FeatureManager.cs
: Added checks forcancellationToken.IsCancellationRequested
in theIsEnabledAsync
method to allow for early termination of the evaluation loop if cancellation is requested.src/Microsoft.FeatureManagement/FeatureManager.cs
: Updated theFeatureFilterEvaluationContext
instantiation to include theCancellationToken
in theIsEnabledAsync
method.src/Microsoft.FeatureManagement/FeatureManager.cs
: Added checks forcancellationToken.IsCancellationRequested
in theAssignVariantAsync
method to handle cancellation during user, group, and percentile allocations. [1] [2] [3]These updates enhance the robustness of the feature management system by allowing operations to be cancelled gracefully, which can be particularly useful in scenarios where feature evaluations are time-sensitive or resource-intensive.
Addresses #531