Skip to content

Commit 75e32bd

Browse files
authored
Merge pull request #163 from jimmyca15/user/jimmyca/merge/feature/v3
Integrate main commits into feature/v3 branch.
2 parents 28982a1 + 44be34e commit 75e32bd

File tree

11 files changed

+149
-69
lines changed

11 files changed

+149
-69
lines changed

src/Microsoft.FeatureManagement.AspNetCore/Microsoft.FeatureManagement.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- Official Version -->
55
<PropertyGroup>
66
<MajorVersion>2</MajorVersion>
7-
<MinorVersion>3</MinorVersion>
7+
<MinorVersion>4</MinorVersion>
88
<PatchVersion>0</PatchVersion>
99
</PropertyGroup>
1010

src/Microsoft.FeatureManagement/FeatureFilters/PercentageFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, Cancella
4848

4949
if (result)
5050
{
51-
result = (RandomGenerator.NextDouble() * 100) <= settings.Value;
51+
result = (RandomGenerator.NextDouble() * 100) < settings.Value;
5252
}
5353

5454
return Task.FromResult(result);

src/Microsoft.FeatureManagement/FeatureManagementError.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public enum FeatureManagementError
1818
/// </summary>
1919
AmbiguousFeatureFilter,
2020

21+
/// <summary>
22+
/// A feature that was requested for evaluation was not found.
23+
/// </summary>
24+
MissingFeature,
25+
2126
/// <summary>
2227
/// A feature filter being used in feature evaluation is invalid.
2328
/// </summary>
@@ -43,11 +48,6 @@ public enum FeatureManagementError
4348
/// </summary>
4449
InvalidFeatureVariantAssigner,
4550

46-
/// <summary>
47-
/// A feature that was requested for evaluation was not found.
48-
/// </summary>
49-
MissingFeature,
50-
5151
/// <summary>
5252
/// A dynamic feature does not have any feature variants registered.
5353
/// </summary>

src/Microsoft.FeatureManagement/FeatureManagementOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ public class FeatureManagementOptions
1111
/// <summary>
1212
/// Controls the behavior of feature evaluation when dependent feature filters are missing.
1313
/// If missing feature filters are not ignored an exception will be thrown when attempting to evaluate a feature that depends on a missing feature filter.
14+
/// The default value is false.
1415
/// </summary>
1516
public bool IgnoreMissingFeatureFilters { get; set; }
17+
18+
/// <summary>
19+
/// Controls the behavior of feature evaluation when the target feature is missing.
20+
/// If missing features are not ignored an exception will be thrown when attempting to evaluate them.
21+
/// The default value is true.
22+
/// </summary>
23+
public bool IgnoreMissingFeatures { get; set; } = true;
1624
}
1725
}

src/Microsoft.FeatureManagement/FeatureManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ private async Task<bool> IsEnabledAsync<TContext>(string feature, TContext appCo
161161
}
162162
}
163163
}
164+
else
165+
{
166+
string errorMessage = $"The feature declaration for the feature '{feature}' was not found.";
167+
168+
if (!_options.IgnoreMissingFeatures)
169+
{
170+
throw new FeatureManagementException(FeatureManagementError.MissingFeature, errorMessage);
171+
}
172+
else
173+
{
174+
_logger.LogWarning(errorMessage);
175+
}
176+
}
164177

165178
foreach (ISessionManager sessionManager in _sessionManagers)
166179
{

src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33
//
44
using System;
5+
using System.Collections.Concurrent;
56
using System.Collections.Generic;
67
using System.Runtime.CompilerServices;
78
using System.Threading;
@@ -15,7 +16,7 @@ namespace Microsoft.FeatureManagement
1516
class FeatureManagerSnapshot : IFeatureManagerSnapshot
1617
{
1718
private readonly IFeatureManager _featureManager;
18-
private readonly IDictionary<string, bool> _flagCache = new Dictionary<string, bool>();
19+
private readonly ConcurrentDictionary<string, Task<bool>> _flagCache = new ConcurrentDictionary<string, Task<bool>>();
1920
private IEnumerable<string> _featureFlagNames;
2021

2122
public FeatureManagerSnapshot(IFeatureManager featureManager)
@@ -43,36 +44,18 @@ public async IAsyncEnumerable<string> GetFeatureFlagNamesAsync([EnumeratorCancel
4344
}
4445
}
4546

46-
public async Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
47+
public Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
4748
{
48-
//
49-
// First, check local cache
50-
if (_flagCache.ContainsKey(feature))
51-
{
52-
return _flagCache[feature];
53-
}
54-
55-
bool enabled = await _featureManager.IsEnabledAsync(feature, cancellationToken).ConfigureAwait(false);
56-
57-
_flagCache[feature] = enabled;
58-
59-
return enabled;
49+
return _flagCache.GetOrAdd(
50+
feature,
51+
(key) => _featureManager.IsEnabledAsync(key, cancellationToken));
6052
}
6153

62-
public async Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken)
54+
public Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken)
6355
{
64-
//
65-
// First, check local cache
66-
if (_flagCache.ContainsKey(feature))
67-
{
68-
return _flagCache[feature];
69-
}
70-
71-
bool enabled = await _featureManager.IsEnabledAsync(feature, context, cancellationToken).ConfigureAwait(false);
72-
73-
_flagCache[feature] = enabled;
74-
75-
return enabled;
56+
return _flagCache.GetOrAdd(
57+
feature,
58+
(key) => _featureManager.IsEnabledAsync(key, context, cancellationToken));
7659
}
7760
}
7861
}

src/Microsoft.FeatureManagement/FilterAliasAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public FilterAliasAttribute(string alias)
1818
{
1919
if (string.IsNullOrEmpty(alias))
2020
{
21-
throw new ArgumentNullException(alias);
21+
throw new ArgumentNullException(nameof(alias));
2222
}
2323

2424
Alias = alias;

src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
<!-- Official Version -->
55
<PropertyGroup>
6-
<MajorVersion>3</MajorVersion>
7-
<MinorVersion>0</MinorVersion>
6+
<MajorVersion>2</MajorVersion>
7+
<MinorVersion>4</MinorVersion>
88
<PatchVersion>0</PatchVersion>
9-
<PreviewVersion>-preview</PreviewVersion>
109
</PropertyGroup>
1110

1211
<Import Project="..\..\build\Versioning.props" />

0 commit comments

Comments
 (0)