Skip to content

Add RegisterAll API to enable monitoring collections of key-values for refresh #574

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

Merged
merged 81 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
a6e3300
WIP
amerjusupovic Apr 3, 2024
15c53fe
WIP testing out client extensions methods
amerjusupovic Apr 4, 2024
75a01eb
WIP added selectors to multikeywatchers
amerjusupovic Apr 5, 2024
f1b07b4
remove unused property
amerjusupovic Apr 5, 2024
25c262c
WIP check for registerall changes to change refreshall
amerjusupovic Apr 9, 2024
302140b
WIP
amerjusupovic Apr 9, 2024
cc1bc58
WIP fixing types and reslving errors
amerjusupovic Apr 10, 2024
28ecc05
WIP fixing client extensions class
amerjusupovic Apr 12, 2024
38ba768
WIP
amerjusupovic Apr 15, 2024
67ec320
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-D…
amerjusupovic Apr 24, 2024
9f4c1de
WIP update feature flag logic
amerjusupovic Apr 24, 2024
937e012
WIP client extensions
amerjusupovic Apr 25, 2024
7e17870
WIP reload all flags on change
amerjusupovic Apr 26, 2024
f4c17ae
WIP
amerjusupovic Apr 29, 2024
65de1cd
WIP fixing tests to return response for getconfigurationsettingsasync
amerjusupovic May 29, 2024
25c477b
WIP etag for tests
amerjusupovic May 31, 2024
913587e
fix watchedcollections null
amerjusupovic Jun 20, 2024
5f84295
WIP tests, working for examples
amerjusupovic Jun 20, 2024
e18a835
remove unused variables
amerjusupovic Jun 20, 2024
d41499e
update to newest sdk version, remove unused
amerjusupovic Jun 20, 2024
85d9909
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-D…
amerjusupovic Jul 1, 2024
d6ac25b
WIP fixing tests
amerjusupovic Jul 1, 2024
5410b5d
WIP reworking testing to work with new etag approach
amerjusupovic Jul 1, 2024
fc752d3
tests passing, fix mockasyncpageable
amerjusupovic Jul 2, 2024
8b02c76
update sdk package version
amerjusupovic Jul 3, 2024
3ebf1e4
fix loghelper, tests
amerjusupovic Jul 3, 2024
26d3391
WIP fixing aspages tests
amerjusupovic Jul 8, 2024
aa037b6
revert watchesfeatureflags test
amerjusupovic Jul 11, 2024
415c577
update test again
amerjusupovic Jul 11, 2024
57f5b80
WIP
amerjusupovic Jul 12, 2024
7ac2cd5
fixing watchconditions
amerjusupovic Jul 12, 2024
bbdac93
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-D…
amerjusupovic Jul 12, 2024
ec9a9da
separate selected key value collections from feature flag collections…
amerjusupovic Jul 15, 2024
e6aadf4
comment and naming updates
amerjusupovic Jul 15, 2024
a122a10
Merge branch 'preview' into ajusupovic/collection-monitoring
amerjusupovic Jul 17, 2024
36f0b80
fixing unit tests, namespace of defining/calling code needs to be same
amerjusupovic Jul 22, 2024
ba8ad5f
Merge branch 'preview' into ajusupovic/collection-monitoring
amerjusupovic Jul 25, 2024
13db869
fixing tests using AsPages
amerjusupovic Jul 25, 2024
d39a767
Merge branch 'ajusupovic/collection-monitoring' of https://github.com…
amerjusupovic Jul 25, 2024
113143a
fix tests with pageablemanager
amerjusupovic Aug 1, 2024
ebae7c9
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-D…
amerjusupovic Aug 1, 2024
05ede06
format
amerjusupovic Aug 1, 2024
e584d6c
fix tests
amerjusupovic Aug 2, 2024
76f369b
fix tests
amerjusupovic Aug 2, 2024
4e0f949
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-D…
amerjusupovic Aug 20, 2024
8391d74
remove unused extension test class
amerjusupovic Oct 8, 2024
e20546d
fix comment, capitalization
amerjusupovic Oct 30, 2024
655ec2d
check etag on 200, fix tests
amerjusupovic Nov 8, 2024
6e39cac
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-D…
amerjusupovic Nov 8, 2024
d9bf761
add registerall test, fix refresh tests
amerjusupovic Nov 8, 2024
b92ae2c
fix condition for pages and old match conditions
amerjusupovic Nov 13, 2024
81f844c
WIP fixing PR comments, tests
amerjusupovic Nov 19, 2024
6212daa
check status after advancing existing etag enumerator
amerjusupovic Nov 19, 2024
e27dea1
move around refresh logic
amerjusupovic Nov 19, 2024
78b83d3
null check page etag, revert break to existing keys check in getrefre…
amerjusupovic Nov 20, 2024
ee36891
fix loadselected, replace selectedkvwatchers with registerall refresh…
amerjusupovic Nov 21, 2024
569656f
fix comment in options
amerjusupovic Nov 21, 2024
d049c2d
clean up tests
amerjusupovic Nov 21, 2024
1375b28
PR comments
amerjusupovic Nov 21, 2024
47cd0ba
PR comments
amerjusupovic Dec 2, 2024
fff31b3
don't allow both registerall and register
amerjusupovic Dec 2, 2024
b9a39c4
fix check for calls to both register methods
amerjusupovic Dec 6, 2024
d8ae90f
PR comments for rename/small changes
amerjusupovic Dec 16, 2024
3ab8672
fix compile error
amerjusupovic Dec 16, 2024
c2bca82
simplify refreshasync path, fix naming from comments
amerjusupovic Dec 17, 2024
6d1cc1a
remove redundant if check
amerjusupovic Dec 19, 2024
aa4829b
simplify logic for minrefreshinterval
amerjusupovic Dec 30, 2024
9afe17a
fix smaller comments
amerjusupovic Jan 2, 2025
69fb9cc
call loadselected when refreshing collection, separate data for indiv…
amerjusupovic Jan 8, 2025
1155b78
in progress change to registerall include ff
amerjusupovic Jan 10, 2025
9ed77af
fix load order
amerjusupovic Jan 11, 2025
cd62a68
fix comments, rename logging constants to match new behavior
amerjusupovic Jan 13, 2025
beab237
pr comments, refactor refreshasync
amerjusupovic Jan 15, 2025
1928357
clean up etags dictionary creation
amerjusupovic Jan 15, 2025
9135d42
PR comments
amerjusupovic Jan 15, 2025
c55aa60
add uncommitted changes to testhelper
amerjusupovic Jan 15, 2025
0b6aecb
update tests for registerall with feature flags, check ff keys to rem…
amerjusupovic Jan 16, 2025
8b3f49a
PR comments
amerjusupovic Jan 17, 2025
00ac014
PR comments
amerjusupovic Jan 21, 2025
d318127
use invalidoperationexception in configurerefresh, update loggingcons…
amerjusupovic Jan 21, 2025
396fe54
remove unused changes
amerjusupovic Jan 22, 2025
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 @@ -23,12 +23,13 @@ public class AzureAppConfigurationOptions
private const int MaxRetries = 2;
private static readonly TimeSpan MaxRetryDelay = TimeSpan.FromMinutes(1);

private List<KeyValueWatcher> _changeWatchers = new List<KeyValueWatcher>();
private List<KeyValueWatcher> _multiKeyWatchers = new List<KeyValueWatcher>();
private List<KeyValueWatcher> _individualKvWatchers = new List<KeyValueWatcher>();
private List<KeyValueWatcher> _ffWatchers = new List<KeyValueWatcher>();
private List<IKeyValueAdapter> _adapters;
private List<Func<ConfigurationSetting, ValueTask<ConfigurationSetting>>> _mappers = new List<Func<ConfigurationSetting, ValueTask<ConfigurationSetting>>>();
private List<KeyValueSelector> _kvSelectors = new List<KeyValueSelector>();
private List<KeyValueSelector> _selectors;
private IConfigurationRefresher _refresher = new AzureAppConfigurationRefresher();
private bool _selectCalled = false;

// The following set is sorted in descending order.
// Since multiple prefixes could start with the same characters, we need to trim the longest prefix first.
Expand Down Expand Up @@ -62,19 +63,29 @@ public class AzureAppConfigurationOptions
internal TokenCredential Credential { get; private set; }

/// <summary>
/// A collection of <see cref="KeyValueSelector"/>.
/// A collection of <see cref="KeyValueSelector"/> specified by user.
/// </summary>
internal IEnumerable<KeyValueSelector> KeyValueSelectors => _kvSelectors;
internal IEnumerable<KeyValueSelector> Selectors => _selectors;

/// <summary>
/// Indicates if <see cref="AzureAppConfigurationRefreshOptions.RegisterAll"/> was called.
/// </summary>
internal bool RegisterAllEnabled { get; private set; }

/// <summary>
/// Refresh interval for selected key-value collections when <see cref="AzureAppConfigurationRefreshOptions.RegisterAll"/> is called.
/// </summary>
internal TimeSpan KvCollectionRefreshInterval { get; private set; }

/// <summary>
/// A collection of <see cref="KeyValueWatcher"/>.
/// </summary>
internal IEnumerable<KeyValueWatcher> ChangeWatchers => _changeWatchers;
internal IEnumerable<KeyValueWatcher> IndividualKvWatchers => _individualKvWatchers;

/// <summary>
/// A collection of <see cref="KeyValueWatcher"/>.
/// </summary>
internal IEnumerable<KeyValueWatcher> MultiKeyWatchers => _multiKeyWatchers;
internal IEnumerable<KeyValueWatcher> FeatureFlagWatchers => _ffWatchers;

/// <summary>
/// A collection of <see cref="IKeyValueAdapter"/>.
Expand All @@ -96,11 +107,15 @@ internal IEnumerable<IKeyValueAdapter> Adapters
internal IEnumerable<string> KeyPrefixes => _keyPrefixes;

/// <summary>
/// An optional configuration client manager that can be used to provide clients to communicate with Azure App Configuration.
/// For use in tests only. An optional configuration client manager that can be used to provide clients to communicate with Azure App Configuration.
/// </summary>
/// <remarks>This property is used only for unit testing.</remarks>
internal IConfigurationClientManager ClientManager { get; set; }

/// <summary>
/// For use in tests only. An optional class used to process pageable results from Azure App Configuration.
/// </summary>
internal IConfigurationSettingPageIterator ConfigurationSettingPageIterator { get; set; }

/// <summary>
/// An optional timespan value to set the minimum backoff duration to a value other than the default.
/// </summary>
Expand Down Expand Up @@ -142,6 +157,9 @@ public AzureAppConfigurationOptions()
new JsonKeyValueAdapter(),
new FeatureManagementKeyValueAdapter(FeatureFlagTracing)
};

// Adds the default query to App Configuration if <see cref="Select"/> and <see cref="SelectSnapshot"/> are never called.
_selectors = new List<KeyValueSelector> { new KeyValueSelector { KeyFilter = KeyFilter.Any, LabelFilter = LabelFilter.Null } };
}

/// <summary>
Expand Down Expand Up @@ -170,22 +188,30 @@ public AzureAppConfigurationOptions Select(string keyFilter, string labelFilter
throw new ArgumentNullException(nameof(keyFilter));
}

// Do not support * and , for label filter for now.
if (labelFilter != null && (labelFilter.Contains('*') || labelFilter.Contains(',')))
{
throw new ArgumentException("The characters '*' and ',' are not supported in label filters.", nameof(labelFilter));
}

if (string.IsNullOrWhiteSpace(labelFilter))
{
labelFilter = LabelFilter.Null;
}

// Do not support * and , for label filter for now.
if (labelFilter.Contains('*') || labelFilter.Contains(','))
if (!_selectCalled)
{
throw new ArgumentException("The characters '*' and ',' are not supported in label filters.", nameof(labelFilter));
_selectors.Clear();

_selectCalled = true;
}

_kvSelectors.AppendUnique(new KeyValueSelector
_selectors.AppendUnique(new KeyValueSelector
{
KeyFilter = keyFilter,
LabelFilter = labelFilter
});

return this;
}

Expand All @@ -201,7 +227,14 @@ public AzureAppConfigurationOptions SelectSnapshot(string name)
throw new ArgumentNullException(nameof(name));
}

_kvSelectors.AppendUnique(new KeyValueSelector
if (!_selectCalled)
{
_selectors.Clear();

_selectCalled = true;
}

_selectors.AppendUnique(new KeyValueSelector
{
SnapshotName = name
});
Expand All @@ -212,7 +245,7 @@ public AzureAppConfigurationOptions SelectSnapshot(string name)
/// <summary>
/// Configures options for Azure App Configuration feature flags that will be parsed and transformed into feature management configuration.
/// If no filtering is specified via the <see cref="FeatureFlagOptions"/> then all feature flags with no label are loaded.
/// All loaded feature flags will be automatically registered for refresh on an individual flag level.
/// All loaded feature flags will be automatically registered for refresh as a collection.
/// </summary>
/// <param name="configure">A callback used to configure feature flag options.</param>
public AzureAppConfigurationOptions UseFeatureFlags(Action<FeatureFlagOptions> configure = null)
Expand All @@ -237,25 +270,22 @@ public AzureAppConfigurationOptions UseFeatureFlags(Action<FeatureFlagOptions> c
options.FeatureFlagSelectors.Add(new KeyValueSelector
{
KeyFilter = FeatureManagementConstants.FeatureFlagMarker + "*",
LabelFilter = options.Label == null ? LabelFilter.Null : options.Label
LabelFilter = string.IsNullOrWhiteSpace(options.Label) ? LabelFilter.Null : options.Label,
IsFeatureFlagSelector = true
});
}

foreach (var featureFlagSelector in options.FeatureFlagSelectors)
foreach (KeyValueSelector featureFlagSelector in options.FeatureFlagSelectors)
{
var featureFlagFilter = featureFlagSelector.KeyFilter;
var labelFilter = featureFlagSelector.LabelFilter;
_selectors.AppendUnique(featureFlagSelector);

Select(featureFlagFilter, labelFilter);

_multiKeyWatchers.AppendUnique(new KeyValueWatcher
_ffWatchers.AppendUnique(new KeyValueWatcher
{
Key = featureFlagFilter,
Label = labelFilter,
Key = featureFlagSelector.KeyFilter,
Label = featureFlagSelector.LabelFilter,
// If UseFeatureFlags is called multiple times for the same key and label filters, last refresh interval wins
RefreshInterval = options.RefreshInterval
});

}

return this;
Expand Down Expand Up @@ -376,18 +406,41 @@ public AzureAppConfigurationOptions ConfigureClientOptions(Action<ConfigurationC
/// <param name="configure">A callback used to configure Azure App Configuration refresh options.</param>
public AzureAppConfigurationOptions ConfigureRefresh(Action<AzureAppConfigurationRefreshOptions> configure)
{
if (RegisterAllEnabled)
{
throw new InvalidOperationException($"{nameof(ConfigureRefresh)}() cannot be invoked multiple times when {nameof(AzureAppConfigurationRefreshOptions.RegisterAll)} has been invoked.");
}

var refreshOptions = new AzureAppConfigurationRefreshOptions();
configure?.Invoke(refreshOptions);

if (!refreshOptions.RefreshRegistrations.Any())
bool isRegisterCalled = refreshOptions.RefreshRegistrations.Any();
RegisterAllEnabled = refreshOptions.RegisterAllEnabled;

if (!isRegisterCalled && !RegisterAllEnabled)
{
throw new InvalidOperationException($"{nameof(ConfigureRefresh)}() must call either {nameof(AzureAppConfigurationRefreshOptions.Register)}()" +
$" or {nameof(AzureAppConfigurationRefreshOptions.RegisterAll)}()");
}

// Check if both register methods are called at any point
if (RegisterAllEnabled && (_individualKvWatchers.Any() || isRegisterCalled))
{
throw new ArgumentException($"{nameof(ConfigureRefresh)}() must have at least one key-value registered for refresh.");
throw new InvalidOperationException($"Cannot call both {nameof(AzureAppConfigurationRefreshOptions.RegisterAll)} and "
+ $"{nameof(AzureAppConfigurationRefreshOptions.Register)}.");
}

foreach (var item in refreshOptions.RefreshRegistrations)
if (RegisterAllEnabled)
{
KvCollectionRefreshInterval = refreshOptions.RefreshInterval;
}
else
{
item.RefreshInterval = refreshOptions.RefreshInterval;
_changeWatchers.Add(item);
foreach (KeyValueWatcher item in refreshOptions.RefreshRegistrations)
{
item.RefreshInterval = refreshOptions.RefreshInterval;
_individualKvWatchers.Add(item);
}
}

return this;
Expand Down
Loading