Skip to content

Commit d28bf88

Browse files
committed
in progress, add new classes for variants and define methods in featuremanager
1 parent 9527c18 commit d28bf88

File tree

9 files changed

+180
-3
lines changed

9 files changed

+180
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
using Microsoft.FeatureManagement.FeatureFilters;
5+
using System.Collections.Generic;
6+
7+
namespace Microsoft.FeatureManagement
8+
{
9+
/// <summary>
10+
///
11+
/// </summary>
12+
public class Allocation
13+
{
14+
/// <summary>
15+
/// Describes a mapping of user id to variant.
16+
/// </summary>
17+
public List<string> Users { get; set; }
18+
19+
/// <summary>
20+
/// Describes a mapping of group names to variants.
21+
/// </summary>
22+
public List<GroupRollout> Groups { get; set; }
23+
24+
/// <summary>
25+
/// Allocate a percentage of the user base to variants.
26+
/// </summary>
27+
public double Percentile { get; set; }
28+
}
29+
}

src/Microsoft.FeatureManagement/FeatureDefinition.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,20 @@ public class FeatureDefinition
2525
/// The default value is <see cref="RequirementType.Any"/>.
2626
/// </summary>
2727
public RequirementType RequirementType { get; set; } = RequirementType.Any;
28+
29+
/// <summary>
30+
/// kill switch
31+
/// </summary>
32+
public Status Status { get; set; } = Status.Conditional;
33+
34+
/// <summary>
35+
///
36+
/// </summary>
37+
public Allocation Allocation { get; set; };
38+
39+
/// <summary>
40+
///
41+
/// </summary>
42+
public List<FeatureVariant> Variants { get; set; }
2843
}
2944
}

src/Microsoft.FeatureManagement/FeatureManager.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.FeatureManagement
1616
/// <summary>
1717
/// Used to evaluate whether a feature is enabled or disabled.
1818
/// </summary>
19-
class FeatureManager : IFeatureManager, IDisposable
19+
class FeatureManager : IFeatureManager, IDisposable, IVariantFeatureManager
2020
{
2121
private readonly TimeSpan ParametersCacheSlidingExpiration = TimeSpan.FromMinutes(5);
2222
private readonly TimeSpan ParametersCacheAbsoluteExpirationRelativeToNow = TimeSpan.FromDays(1);
@@ -141,6 +141,13 @@ private async Task<bool> IsEnabledAsync<TContext>(string feature, TContext appCo
141141
continue;
142142
}
143143

144+
//
145+
// Handle On filters for variants
146+
if (string.Equals(featureFilterConfiguration.Name, "On", StringComparison.OrdinalIgnoreCase))
147+
{
148+
// TODO
149+
}
150+
144151
IFeatureFilterMetadata filter = GetFeatureFilterMetadata(featureFilterConfiguration.Name);
145152

146153
if (filter == null)
@@ -217,6 +224,16 @@ await contextualFilter.EvaluateAsync(context, appContext).ConfigureAwait(false)
217224
return enabled;
218225
}
219226

227+
public ValueTask<Variant> GetVariantAsync(string feature)
228+
{
229+
throw new NotImplementedException();
230+
}
231+
232+
public ValueTask<Variant> GetVariantAsync<TContext>(string feature, TContext context)
233+
{
234+
throw new NotImplementedException();
235+
}
236+
220237
private void BindSettings(IFeatureFilterMetadata filter, FeatureFilterEvaluationContext context, int filterIndex)
221238
{
222239
IFilterParametersBinder binder = filter as IFilterParametersBinder;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
5+
namespace Microsoft.FeatureManagement
6+
{
7+
/// <summary>
8+
/// A variant of a feature.
9+
/// </summary>
10+
public class FeatureVariant
11+
{
12+
/// <summary>
13+
/// The name of the variant.
14+
/// </summary>
15+
public string Name { get; set; }
16+
17+
/// <summary>
18+
/// The value of the configuration for this variant of the feature.
19+
/// </summary>
20+
public string ConfigurationValue { get; set; }
21+
22+
/// <summary>
23+
/// A reference pointing to the configuration for this variant of the feature.
24+
/// </summary>
25+
public string ConfigurationReference { get; set; }
26+
27+
/// <summary>
28+
///
29+
/// </summary>
30+
public StatusOverride StatusOverride { get; set; }
31+
}
32+
}

src/Microsoft.FeatureManagement/IFeatureManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33
//
44
using System.Collections.Generic;
5+
using System.Threading;
56
using System.Threading.Tasks;
67

78
namespace Microsoft.FeatureManagement
@@ -21,15 +22,17 @@ public interface IFeatureManager
2122
/// Checks whether a given feature is enabled.
2223
/// </summary>
2324
/// <param name="feature">The name of the feature to check.</param>
25+
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
2426
/// <returns>True if the feature is enabled, otherwise false.</returns>
25-
Task<bool> IsEnabledAsync(string feature);
27+
Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken = default);
2628

2729
/// <summary>
2830
/// Checks whether a given feature is enabled.
2931
/// </summary>
3032
/// <param name="feature">The name of the feature to check.</param>
3133
/// <param name="context">A context providing information that can be used to evaluate whether a feature should be on or off.</param>
34+
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
3235
/// <returns>True if the feature is enabled, otherwise false.</returns>
33-
Task<bool> IsEnabledAsync<TContext>(string feature, TContext context);
36+
Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken = default);
3437
}
3538
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
using System.Threading.Tasks;
5+
using System.Threading;
6+
7+
namespace Microsoft.FeatureManagement
8+
{
9+
public interface IVariantFeatureManager
10+
{
11+
/// <summary>
12+
/// Checks whether a given feature is enabled.
13+
/// </summary>
14+
/// <param name="feature">The name of the feature to check.</param>
15+
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
16+
/// <returns>True if the feature is enabled, otherwise false.</returns>
17+
Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken);
18+
19+
/// <summary>
20+
/// Checks whether a given feature is enabled.
21+
/// </summary>
22+
/// <param name="feature">The name of the feature to check.</param>
23+
/// <param name="context">A context providing information that can be used to evaluate whether a feature should be on or off.</param>
24+
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
25+
/// <returns>True if the feature is enabled, otherwise false.</returns>
26+
Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken);
27+
28+
/// <summary>
29+
/// Gets the assigned variant for a specfic feature.
30+
/// </summary>
31+
/// <param name="feature">The name of the feature from which the variant will be assigned.</param>
32+
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
33+
/// <returns>A variant assigned to the user based on the feature's allocation logic.</returns>
34+
ValueTask<Variant> GetVariantAsync(string feature, CancellationToken cancellationToken);
35+
36+
/// <summary>
37+
/// Gets the assigned variant for a specfic feature.
38+
/// </summary>
39+
/// <param name="feature">The name of the feature from which the variant will be assigned.</param>
40+
/// <param name="context">A context providing information that can be used to evaluate which variant the user will be assigned.</param>
41+
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
42+
/// <returns>A variant assigned to the user based on the feature's allocation logic.</returns>
43+
ValueTask<Variant> GetVariantAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken);
44+
}
45+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
namespace Microsoft.FeatureManagement
5+
{
6+
public enum Status
7+
{
8+
Conditional,
9+
Disabled
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
namespace Microsoft.FeatureManagement
5+
{
6+
public enum StatusOverride
7+
{
8+
Enabled,
9+
Disabled
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
using Microsoft.Extensions.Configuration;
5+
6+
namespace Microsoft.FeatureManagement
7+
{
8+
public class Variant
9+
{
10+
public string Name { get; set; }
11+
12+
public IConfiguration Configuration { get; set; }
13+
}
14+
}

0 commit comments

Comments
 (0)