Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Official Version -->
<PropertyGroup>
<MajorVersion>2</MajorVersion>
<MinorVersion>3</MinorVersion>
<MinorVersion>4</MinorVersion>
<PatchVersion>0</PatchVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, Cancella

if (result)
{
result = (RandomGenerator.NextDouble() * 100) <= settings.Value;
result = (RandomGenerator.NextDouble() * 100) < settings.Value;
}

return Task.FromResult(result);
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.FeatureManagement/FeatureManagementError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public enum FeatureManagementError
/// </summary>
AmbiguousFeatureFilter,

/// <summary>
/// A feature that was requested for evaluation was not found.
/// </summary>
MissingFeature,

/// <summary>
/// A feature filter being used in feature evaluation is invalid.
/// </summary>
Expand All @@ -43,11 +48,6 @@ public enum FeatureManagementError
/// </summary>
InvalidFeatureVariantAssigner,

/// <summary>
/// A feature that was requested for evaluation was not found.
/// </summary>
MissingFeature,

/// <summary>
/// A dynamic feature does not have any feature variants registered.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.FeatureManagement/FeatureManagementOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ public class FeatureManagementOptions
/// <summary>
/// Controls the behavior of feature evaluation when dependent feature filters are missing.
/// 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.
/// The default value is false.
/// </summary>
public bool IgnoreMissingFeatureFilters { get; set; }

/// <summary>
/// Controls the behavior of feature evaluation when the target feature is missing.
/// If missing features are not ignored an exception will be thrown when attempting to evaluate them.
/// The default value is true.
/// </summary>
public bool IgnoreMissingFeatures { get; set; } = true;
}
}
13 changes: 13 additions & 0 deletions src/Microsoft.FeatureManagement/FeatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ private async Task<bool> IsEnabledAsync<TContext>(string feature, TContext appCo
}
}
}
else
{
string errorMessage = $"The feature declaration for the feature '{feature}' was not found.";

if (!_options.IgnoreMissingFeatures)
{
throw new FeatureManagementException(FeatureManagementError.MissingFeature, errorMessage);
}
else
{
_logger.LogWarning(errorMessage);
}
}

foreach (ISessionManager sessionManager in _sessionManagers)
{
Expand Down
37 changes: 10 additions & 27 deletions src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.
//
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
Expand All @@ -15,7 +16,7 @@ namespace Microsoft.FeatureManagement
class FeatureManagerSnapshot : IFeatureManagerSnapshot
{
private readonly IFeatureManager _featureManager;
private readonly IDictionary<string, bool> _flagCache = new Dictionary<string, bool>();
private readonly ConcurrentDictionary<string, Task<bool>> _flagCache = new ConcurrentDictionary<string, Task<bool>>();
private IEnumerable<string> _featureFlagNames;

public FeatureManagerSnapshot(IFeatureManager featureManager)
Expand Down Expand Up @@ -43,36 +44,18 @@ public async IAsyncEnumerable<string> GetFeatureFlagNamesAsync([EnumeratorCancel
}
}

public async Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
public Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
{
//
// First, check local cache
if (_flagCache.ContainsKey(feature))
{
return _flagCache[feature];
}

bool enabled = await _featureManager.IsEnabledAsync(feature, cancellationToken).ConfigureAwait(false);

_flagCache[feature] = enabled;

return enabled;
return _flagCache.GetOrAdd(
feature,
(key) => _featureManager.IsEnabledAsync(key, cancellationToken));
}

public async Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken)
public Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken)
{
//
// First, check local cache
if (_flagCache.ContainsKey(feature))
{
return _flagCache[feature];
}

bool enabled = await _featureManager.IsEnabledAsync(feature, context, cancellationToken).ConfigureAwait(false);

_flagCache[feature] = enabled;

return enabled;
return _flagCache.GetOrAdd(
feature,
(key) => _featureManager.IsEnabledAsync(key, context, cancellationToken));
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.FeatureManagement/FilterAliasAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public FilterAliasAttribute(string alias)
{
if (string.IsNullOrEmpty(alias))
{
throw new ArgumentNullException(alias);
throw new ArgumentNullException(nameof(alias));
}

Alias = alias;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

<!-- Official Version -->
<PropertyGroup>
<MajorVersion>3</MajorVersion>
<MinorVersion>0</MinorVersion>
<MajorVersion>2</MajorVersion>
<MinorVersion>4</MinorVersion>
<PatchVersion>0</PatchVersion>
<PreviewVersion>-preview</PreviewVersion>
</PropertyGroup>

<Import Project="..\..\build\Versioning.props" />
Expand Down
Loading