Skip to content

Commit f0b8b87

Browse files
Merge branch 'zhiyuanliang/afd' of https://github.com/Azure/AppConfiguration-DotnetProvider into zhiyuanliang/afd
2 parents 5d3d2c2 + 3049eb3 commit f0b8b87

File tree

10 files changed

+528
-52
lines changed

10 files changed

+528
-52
lines changed

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Afd/AfdConfigurationClientManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Extensions.Azure;
66
using System;
77
using System.Collections.Generic;
8+
89
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.Afd
910
{
1011
internal class AfdConfigurationClientManager : IConfigurationClientManager

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/AzureAppConfigurationOptions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ public AzureAppConfigurationOptions Connect(IEnumerable<Uri> endpoints, TokenCre
433433
}
434434

435435
Credential = credential ?? throw new ArgumentNullException(nameof(credential));
436-
437436
Endpoints = endpoints;
438437
ConnectionStrings = null;
439438
return this;
@@ -450,6 +449,11 @@ public AzureAppConfigurationOptions ConnectAzureFrontDoor(Uri endpoint)
450449
throw new InvalidOperationException(ErrorMessages.ConnectionConflict);
451450
}
452451

452+
if (IsAfdUsed)
453+
{
454+
throw new InvalidOperationException(ErrorMessages.AfdConnectionConflict);
455+
}
456+
453457
if (endpoint == null)
454458
{
455459
throw new ArgumentNullException(nameof(endpoint));
@@ -459,9 +463,7 @@ public AzureAppConfigurationOptions ConnectAzureFrontDoor(Uri endpoint)
459463

460464
Endpoints = new List<Uri>() { endpoint };
461465
ConnectionStrings = null;
462-
463466
IsAfdUsed = true;
464-
465467
return this;
466468
}
467469

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/AzureAppConfigurationProvider.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,13 @@ await ExecuteWithFailOverPolicyAsync(clients, async (client) =>
370370
watchedIndividualKvChangeDetectedTime = new Dictionary<KeyValueIdentifier, DateTimeOffset>();
371371

372372
data = await LoadSelected(client, kvEtags, ffEtags, _options.Selectors, ffKeys, false, cancellationToken).ConfigureAwait(false);
373-
watchedIndividualKvs = await LoadKeyValuesRegisteredForRefresh(client, data, watchedIndividualKvChangeDetectedTime, cancellationToken).ConfigureAwait(false);
374-
if (data != null && watchedIndividualKvs != null && !_isLastRefreshAborted)
373+
374+
if (!_isLastRefreshAborted)
375+
{
376+
watchedIndividualKvs = await LoadKeyValuesRegisteredForRefresh(client, data, watchedIndividualKvChangeDetectedTime, cancellationToken).ConfigureAwait(false);
377+
}
378+
379+
if (!_isLastRefreshAborted)
375380
{
376381
logInfoBuilder.AppendLine(LogHelper.BuildConfigurationUpdatedMessage());
377382
}
@@ -893,6 +898,7 @@ await ExecuteWithFailOverPolicyAsync(
893898
_kvEtags = kvEtags;
894899
_ffEtags = ffEtags;
895900
_watchedIndividualKvs = watchedIndividualKvs;
901+
_watchedIndividualKvChangeDetectedTime = watchedIndividualKvChangeDetectedTime;
896902
_ffKeys = ffKeys;
897903
}
898904
}
@@ -1130,7 +1136,7 @@ await CallWithRequestTracing(async () =>
11301136
}
11311137

11321138
// If the key-value was found, store it for updating the settings
1133-
if (watchedKv != null)
1139+
if (watchedKv != null && existingSettings != null)
11341140
{
11351141
watchedIndividualKvs[watchedKeyLabel] = new ConfigurationSetting(watchedKv.Key, watchedKv.Value, watchedKv.Label, watchedKv.ETag);
11361142

@@ -1184,7 +1190,8 @@ private async Task<bool> RefreshIndividualKvWatchers(
11841190

11851191
KeyValueChange change = default;
11861192

1187-
// if fail to get, the default DateTimeOffset.MinValue will be used
1193+
// Unless initial load failed, _watchedIndividualKvChangeDetectedTime should always have an entry for the watched key-label
1194+
// If fail to get, lastChangeDetectedTime will be DateTimeOffset.MinValue by default
11881195
_watchedIndividualKvChangeDetectedTime.TryGetValue(watchedKeyLabel, out DateTimeOffset lastChangeDetectedTime);
11891196

11901197
//
@@ -1300,7 +1307,8 @@ private void SetRequestTracingOptions()
13001307
IsKeyVaultConfigured = _options.IsKeyVaultConfigured,
13011308
IsKeyVaultRefreshConfigured = _options.IsKeyVaultRefreshConfigured,
13021309
FeatureFlagTracing = _options.FeatureFlagTracing,
1303-
IsLoadBalancingEnabled = _options.LoadBalancingEnabled
1310+
IsLoadBalancingEnabled = _options.LoadBalancingEnabled,
1311+
IsAfdUsed = _options.IsAfdUsed
13041312
};
13051313
}
13061314

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/AzureAppConfigurationSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public IConfigurationProvider Build(IConfigurationBuilder builder)
4747

4848
if (clientFactory != null)
4949
{
50-
throw new InvalidOperationException(ErrorMessages.AfdCustomClientOptionsUnsupported);
50+
throw new InvalidOperationException(ErrorMessages.AfdCustomClientFactoryUnsupported);
5151
}
5252

5353
options.ClientOptions.AddPolicy(new AfdPolicy(), HttpPipelinePosition.PerRetry);

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Constants/ErrorMessages.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ internal class ErrorMessages
1515
public const string SnapshotReferencePropertyMissing = "Invalid snapshot reference format for key '{0}' (label: '{1}'). The '{2}' property is required.";
1616
public const string SnapshotInvalidComposition = "{0} for the selected snapshot with name '{1}' must be 'key', found '{2}'.";
1717
public const string ConnectionConflict = "Cannot connect to both Azure App Configuration and Azure Front Door at the same time.";
18+
public const string AfdConnectionConflict = "Cannot connect to multiple Azure Front Doors.";
1819
public const string AfdLoadBalancingUnsupported = "Load balancing is not supported when connecting to Azure Front Door.";
19-
public const string AfdCustomClientOptionsUnsupported = "Custom client options are not supported when connecting to Azure Front Door.";
20+
public const string AfdCustomClientFactoryUnsupported = "Custom client factory is not supported when connecting to Azure Front Door.";
2021
}
2122
}

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Extensions/ConfigurationClientExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44
using Azure;
55
using Azure.Data.AppConfiguration;
6-
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
76
using Microsoft.Extensions.Configuration.AzureAppConfiguration.Models;
87
using System;
98
using System.Collections.Generic;
@@ -120,6 +119,8 @@ public static async Task<Page<ConfigurationSetting>> GetPageChange(this Configur
120119
{
121120
return page;
122121
}
122+
123+
i++;
123124
}
124125

125126
return null;

tests/Tests.AzureAppConfiguration/Azure.Core.Testing/MockResponse.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ public class MockResponse : Response
1313
{
1414
private readonly Dictionary<string, List<string>> _headers = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
1515

16-
public MockResponse(int status, string reasonPhrase = null)
16+
public MockResponse(int status, string etag = null, DateTimeOffset? date = null, string reasonPhrase = null)
1717
{
1818
Status = status;
1919
ReasonPhrase = reasonPhrase;
2020

2121
if (status == 200)
2222
{
23-
AddHeader(new HttpHeader(HttpHeader.Names.ETag, "\"" + Guid.NewGuid().ToString() + "\""));
23+
AddHeader(new HttpHeader(HttpHeader.Names.ETag, "\"" + (etag ?? Guid.NewGuid().ToString()) + "\""));
2424
}
25+
26+
AddHeader(new HttpHeader(HttpHeader.Names.XMsDate, date?.ToString() ?? DateTimeOffset.UtcNow.ToString()));
2527
}
2628

2729
public override int Status { get; }

0 commit comments

Comments
 (0)