Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -32,6 +32,7 @@ internal class AzureAppConfigurationProvider : ConfigurationProvider, IConfigura
private AzureAppConfigurationOptions _options;
private Dictionary<string, ConfigurationSetting> _mappedData;
private Dictionary<KeyValueIdentifier, ConfigurationSetting> _watchedIndividualKvs = new Dictionary<KeyValueIdentifier, ConfigurationSetting>();
private HashSet<string> _ffKeys = new HashSet<string>();
private Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> _kvEtags = new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>();
private Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> _ffEtags = new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>();
private RequestTracingOptions _requestTracingOptions;
Expand Down Expand Up @@ -262,6 +263,7 @@ public async Task RefreshAsync(CancellationToken cancellationToken)
// Avoid instance state modification
Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> ffEtags = null;
Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> kvEtags = null;
HashSet<string> ffKeys = null;
Dictionary<KeyValueIdentifier, ConfigurationSetting> watchedIndividualKvs = null;
List<KeyValueChange> keyValueChanges = null;
Dictionary<string, ConfigurationSetting> data = null;
Expand All @@ -273,17 +275,18 @@ public async Task RefreshAsync(CancellationToken cancellationToken)

await ExecuteWithFailOverPolicyAsync(clients, async (client) =>
{
data = null;
ffCollectionData = null;
watchedIndividualKvs = null;
kvEtags = null;
ffEtags = null;
ffKeys = null;
watchedIndividualKvs = null;
keyValueChanges = new List<KeyValueChange>();
data = null;
ffCollectionData = null;
ffCollectionUpdated = false;
refreshAll = false;
Uri endpoint = _configClientManager.GetEndpointForClient(client);
logDebugBuilder.Clear();
logInfoBuilder.Clear();
Uri endpoint = _configClientManager.GetEndpointForClient(client);

if (_options.RegisterAllEnabled)
{
Expand Down Expand Up @@ -315,8 +318,9 @@ await ExecuteWithFailOverPolicyAsync(clients, async (client) =>
// or if any key-value collection change was detected.
kvEtags = new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>();
ffEtags = new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>();
ffKeys = new HashSet<string>();

data = await LoadSelected(client, kvEtags, ffEtags, _options.Selectors, cancellationToken).ConfigureAwait(false);
data = await LoadSelected(client, kvEtags, ffEtags, _options.Selectors, ffKeys, cancellationToken).ConfigureAwait(false);
watchedIndividualKvs = await LoadKeyValuesRegisteredForRefresh(client, data, cancellationToken).ConfigureAwait(false);
logInfoBuilder.AppendLine(LogHelper.BuildConfigurationUpdatedMessage());
return;
Expand All @@ -332,12 +336,14 @@ await ExecuteWithFailOverPolicyAsync(clients, async (client) =>
if (ffCollectionUpdated)
{
ffEtags = new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>();
ffKeys = new HashSet<string>();

ffCollectionData = await LoadSelected(
client,
new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>(),
ffEtags,
_options.Selectors.Where(selector => selector.IsFeatureFlagSelector),
ffKeys,
cancellationToken).ConfigureAwait(false);

logInfoBuilder.Append(LogHelper.BuildFeatureFlagsUpdatedMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anywhere that we logged feature flag updates as info before. Am I missing it.

Also, why

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a LogFeatureFlagUpdated message when refreshing individual flags in the ConfigurationClientExtensions file, so I thought it might make sense to log the collection being updated since it seems like whenever we update a value (kv, flag, secret) we would log it as info.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. In that case, I see for configuration we log "Configuration reloaded.", but for flags it is currently "Feature flags updated." It seems to me we should be consistent and log "Feature flags reloaded."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, they both do a full reload so it makes sense

Expand Down Expand Up @@ -374,6 +380,12 @@ await ExecuteWithFailOverPolicyAsync(clients, async (client) =>

if (ffCollectionUpdated)
{
// Remove all feature flag keys that are not present in the latest loading of feature flags, but were loaded previously
foreach (string key in _ffKeys.Except(ffKeys))
{
_mappedData.Remove(key);
}

Dictionary<string, ConfigurationSetting> mappedFfData = await MapConfigurationSettings(ffCollectionData).ConfigureAwait(false);

foreach (KeyValuePair<string, ConfigurationSetting> kvp in mappedFfData)
Expand All @@ -397,11 +409,13 @@ await ExecuteWithFailOverPolicyAsync(clients, async (client) =>

if (_options.Adapters.Any(adapter => adapter.NeedsRefresh()) || keyValueChanges.Any() || refreshAll || ffCollectionUpdated)
{
_watchedIndividualKvs = watchedIndividualKvs;
_watchedIndividualKvs = watchedIndividualKvs ?? _watchedIndividualKvs;

_ffEtags = ffEtags ?? _ffEtags;

_ffEtags = ffEtags;
_kvEtags = kvEtags ?? _kvEtags;

_kvEtags = kvEtags;
_ffKeys = ffKeys ?? _ffKeys;

if (logDebugBuilder.Length > 0)
{
Expand Down Expand Up @@ -698,6 +712,7 @@ private async Task InitializeAsync(IEnumerable<ConfigurationClient> clients, Can
Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> kvEtags = new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>();
Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> ffEtags = new Dictionary<KeyValueSelector, IEnumerable<MatchConditions>>();
Dictionary<KeyValueIdentifier, ConfigurationSetting> watchedIndividualKvs = null;
HashSet<string> ffKeys = new HashSet<string>();

await ExecuteWithFailOverPolicyAsync(
clients,
Expand All @@ -708,6 +723,7 @@ await ExecuteWithFailOverPolicyAsync(
kvEtags,
ffEtags,
_options.Selectors,
ffKeys,
cancellationToken)
.ConfigureAwait(false);

Expand Down Expand Up @@ -755,6 +771,7 @@ private async Task<Dictionary<string, ConfigurationSetting>> LoadSelected(
Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> kvEtags,
Dictionary<KeyValueSelector, IEnumerable<MatchConditions>> ffEtags,
IEnumerable<KeyValueSelector> selectors,
HashSet<string> ffKeys,
CancellationToken cancellationToken)
{
Dictionary<string, ConfigurationSetting> data = new Dictionary<string, ConfigurationSetting>();
Expand Down Expand Up @@ -784,6 +801,11 @@ await CallWithRequestTracing(async () =>
foreach (ConfigurationSetting setting in page.Values)
{
data[setting.Key] = setting;

if (loadOption.IsFeatureFlagSelector)
{
ffKeys.Add(setting.Key);
}
}

matchConditions.Add(new MatchConditions { IfNoneMatch = serverEtag });
Expand Down
113 changes: 113 additions & 0 deletions tests/Tests.AzureAppConfiguration/RefreshTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration.FeatureManagement;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using System;
Expand Down Expand Up @@ -1108,6 +1109,118 @@ public async Task RefreshTests_SelectedKeysRefreshWithRegisterAll()
Assert.Null(config["TestKey3"]);
}

[Fact]
public async Task RefreshTests_RegisterAllRefreshesFeatureFlags()
{
IConfigurationRefresher refresher = null;
var mockClient = GetMockConfigurationClient();

var featureFlags = new List<ConfigurationSetting> {
ConfigurationModelFactory.ConfigurationSetting(
key: FeatureManagementConstants.FeatureFlagMarker + "myFeature",
value: @"
{
""id"": ""MyFeature"",
""description"": ""The new beta version of our web site."",
""display_name"": ""Beta Feature"",
""enabled"": true,
""conditions"": {
""client_filters"": [
{
""name"": ""SuperUsers""
}
]
}
}
",
label: default,
contentType: FeatureManagementConstants.ContentType + ";charset=utf-8",
eTag: new ETag("c3c231fd-39a0-4cb6-3237-4614474b92c1"))
};

var mockAsyncPageableKv = new MockAsyncPageable(_kvCollection);

var mockAsyncPageableFf = new MockAsyncPageable(featureFlags);

MockAsyncPageable GetTestKeys(SettingSelector selector, CancellationToken ct)
{
if (selector.KeyFilter.StartsWith(FeatureManagementConstants.FeatureFlagMarker))
{
mockAsyncPageableFf.UpdateCollection(featureFlags);

return mockAsyncPageableFf;
}

mockAsyncPageableKv.UpdateCollection(_kvCollection);

return mockAsyncPageableKv;
}

mockClient.Setup(c => c.GetConfigurationSettingsAsync(It.IsAny<SettingSelector>(), It.IsAny<CancellationToken>()))
.Returns((Func<SettingSelector, CancellationToken, MockAsyncPageable>)GetTestKeys);

var config = new ConfigurationBuilder()
.AddAzureAppConfiguration(options =>
{
options.ClientManager = TestHelpers.CreateMockedConfigurationClientManager(mockClient.Object);
options.Select("TestKey*");
options.ConfigurationSettingPageIterator = new MockConfigurationSettingPageIterator();
options.ConfigureRefresh(refreshOptions =>
{
refreshOptions.RegisterAll()
.SetRefreshInterval(TimeSpan.FromSeconds(1));
});
options.UseFeatureFlags();

refresher = options.GetRefresher();
})
.Build();

Assert.Equal("TestValue1", config["TestKey1"]);
Assert.Equal("SuperUsers", config["FeatureManagement:MyFeature:EnabledFor:0:Name"]);

FirstKeyValue.Value = "newValue1";
featureFlags[0] = ConfigurationModelFactory.ConfigurationSetting(
key: FeatureManagementConstants.FeatureFlagMarker + "myFeature",
value: @"
{
""id"": ""MyFeature"",
""description"": ""The new beta version of our web site."",
""display_name"": ""Beta Feature"",
""enabled"": true,
""conditions"": {
""client_filters"": [
{
""name"": ""AllUsers""
}
]
}
}
",
label: default,
contentType: FeatureManagementConstants.ContentType + ";charset=utf-8",
eTag: new ETag("c3c231fd-39a0-4cb6-3237-4614474b92c1"));

// Wait for the cache to expire
Thread.Sleep(1500);

await refresher.RefreshAsync();

Assert.Equal("newValue1", config["TestKey1"]);
Assert.Equal("AllUsers", config["FeatureManagement:MyFeature:EnabledFor:0:Name"]);

FirstKeyValue.Value = "newerValue1";
featureFlags.RemoveAt(0);

// Wait for the cache to expire
Thread.Sleep(1500);

await refresher.RefreshAsync();

Assert.Equal("newerValue1", config["TestKey1"]);
Assert.Null(config["FeatureManagement:MyFeature"]);
}

#if NET8_0
[Fact]
public void RefreshTests_ChainedConfigurationProviderUsedAsRootForRefresherProvider()
Expand Down