Skip to content
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

[WIP] add variant allocation context option #506

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Microsoft.FeatureManagement/Allocation/Allocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class Allocation
/// </summary>
public IEnumerable<PercentileAllocation> Percentile { get; set; }

/// <summary>
/// Describes a mapping of contextual filters to variants.
/// </summary>
public IEnumerable<ContextualFilterAllocation> AllocatedFor { get; set; }

/// <summary>
/// Maps users to the same percentile across multiple feature flags.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//

namespace Microsoft.FeatureManagement
{
/// <summary>
/// The definition of a filter allocation.
/// </summary>
public class ContextualFilterAllocation : FeatureFilterConfiguration
{
/// <summary>
/// The name of the variant.
/// </summary>
public string Variant { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,15 @@ private FeatureDefinition ParseMicrosoftSchemaFeatureDefinition(IConfigurationSe
To = to
};
}),
AllocatedFor = allocationSection.GetSection(MicrosoftFeatureManagementFields.ClientFilters).GetChildren().Select(filterAllocation =>
{
return new ContextualFilterAllocation()
{
Name = filterAllocation[MicrosoftFeatureManagementFields.Name],
Parameters = new ConfigurationWrapper(filterAllocation.GetSection(MicrosoftFeatureManagementFields.Parameters)),
Variant = filterAllocation[MicrosoftFeatureManagementFields.AllocationVariantKeyword]
};
}),
Seed = allocationSection[MicrosoftFeatureManagementFields.AllocationSeed]
};
}
Expand Down
228 changes: 170 additions & 58 deletions src/Microsoft.FeatureManagement/FeatureManager.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async ValueTask<Variant> GetVariantAsync(string feature, CancellationToke
return variant;
}

public async ValueTask<Variant> GetVariantAsync(string feature, ITargetingContext context, CancellationToken cancellationToken)
public async ValueTask<Variant> GetVariantAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken)
{
string cacheKey = GetVariantCacheKey(feature);

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.FeatureManagement/IVariantFeatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public interface IVariantFeatureManager
/// <param name="context">A context that provides information to evaluate which variant will be assigned to the user.</param>
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
/// <returns>A variant assigned to the user based on the feature's configured allocation.</returns>
ValueTask<Variant> GetVariantAsync(string feature, ITargetingContext context, CancellationToken cancellationToken = default);
ValueTask<Variant> GetVariantAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal static class MicrosoftFeatureManagementFields
public const string PercentileAllocationSectionName = "percentile";
public const string PercentileAllocationFrom = "from";
public const string PercentileAllocationTo = "to";
public const string FilterAllocationSectionName = ClientFilters;
public const string AllocationSeed = "seed";

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public enum VariantAssignmentReason
/// <summary>
/// The variant is assigned because of the percentile allocation when a feature flag is enabled.
/// </summary>
Percentile
Percentile,

/// <summary>
/// The variant is assigned because of a matching filter.
/// </summary>
Filter
}
}