Skip to content

Commit

Permalink
Merge pull request #576 from Azure/main
Browse files Browse the repository at this point in the history
Merge main to release/stable/v7 for 7.3.0 release
  • Loading branch information
amerjusupovic authored Jul 16, 2024
2 parents 1608a3a + 0c9e17a commit 059b529
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 122 deletions.
6 changes: 3 additions & 3 deletions examples/ConsoleAppWithFailOver/ConsoleAppWithFailOver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions examples/ConsoleApplication/ConsoleApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- Nuget Package Version Settings -->

<PropertyGroup>
<OfficialVersion>7.2.0</OfficialVersion>
<OfficialVersion>7.3.0</OfficialVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(CDP_PATCH_NUMBER)'!='' AND '$(CDP_BUILD_TYPE)'=='Official'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<!-- Nuget Package Version Settings -->

<PropertyGroup>
<OfficialVersion>7.2.0</OfficialVersion>
<OfficialVersion>7.3.0</OfficialVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(CDP_PATCH_NUMBER)'!='' AND '$(CDP_BUILD_TYPE)'=='Official'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class AzureAppConfigurationProvider : ConfigurationProvider, IConfigura
{
private bool _optional;
private bool _isInitialLoadComplete = false;
private bool _isFeatureManagementVersionInspected;
private bool _isAssemblyInspected;
private readonly bool _requestTracingEnabled;
private readonly IConfigurationClientManager _configClientManager;
private AzureAppConfigurationOptions _options;
Expand Down Expand Up @@ -189,7 +189,7 @@ public async Task RefreshAsync(CancellationToken cancellationToken)
try
{
// FeatureManagement assemblies may not be loaded on provider startup, so version information is gathered upon first refresh for tracing
EnsureFeatureManagementVersionInspected();
EnsureAssemblyInspected();

var utcNow = DateTimeOffset.UtcNow;
IEnumerable<KeyValueWatcher> cacheExpiredWatchers = _options.ChangeWatchers.Where(changeWatcher => utcNow >= changeWatcher.CacheExpires);
Expand Down Expand Up @@ -492,6 +492,12 @@ public async Task<bool> TryRefreshAsync(CancellationToken cancellationToken)

return false;
}
catch (FormatException fe)
{
_logger.LogWarning(LogHelper.BuildRefreshFailedDueToFormattingErrorMessage(fe.Message));

return false;
}

return true;
}
Expand Down Expand Up @@ -634,6 +640,7 @@ exception is KeyVaultReferenceException ||
exception is TimeoutException ||
exception is OperationCanceledException ||
exception is InvalidOperationException ||
exception is FormatException ||
((exception as AggregateException)?.InnerExceptions?.Any(e =>
e is RequestFailedException ||
e is OperationCanceledException) ?? false)))
Expand Down Expand Up @@ -1179,17 +1186,22 @@ private IEnumerable<ConfigurationSetting> GetCurrentKeyValueCollection(string ke
return currentKeyValues;
}

private void EnsureFeatureManagementVersionInspected()
private void EnsureAssemblyInspected()
{
if (!_isFeatureManagementVersionInspected)
if (!_isAssemblyInspected)
{
_isFeatureManagementVersionInspected = true;
_isAssemblyInspected = true;

if (_requestTracingEnabled && _requestTracingOptions != null)
{
_requestTracingOptions.FeatureManagementVersion = TracingUtils.GetAssemblyVersion(RequestTracingConstants.FeatureManagementAssemblyName);

_requestTracingOptions.FeatureManagementAspNetCoreVersion = TracingUtils.GetAssemblyVersion(RequestTracingConstants.FeatureManagementAspNetCoreAssemblyName);

if (TracingUtils.GetAssemblyVersion(RequestTracingConstants.SignalRAssemblyName) != null)
{
_requestTracingOptions.IsSignalRUsed = true;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal class LoggingConstants
public const string RefreshFailedDueToKeyVaultError = "A refresh operation failed while resolving a Key Vault reference.";
public const string PushNotificationUnregisteredEndpoint = "Ignoring the push notification received for the unregistered endpoint";
public const string FallbackClientLookupError = "Failed to perform fallback client lookup.";
public const string RefreshFailedDueToFormattingError = "A refresh operation failed due to a formatting error.";

// Successful update, debug log level
public const string RefreshKeyValueRead = "Key-value read from App Configuration.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ internal class RequestTracingConstants
public const string KeyVaultConfiguredTag = "UsesKeyVault";
public const string KeyVaultRefreshConfiguredTag = "RefreshesKeyVault";
public const string ReplicaCountKey = "ReplicaCount";
public const string SignalRUsedTag = "UsesSignalR";

public const string DiagnosticHeaderActivityName = "Azure.CustomDiagnosticHeaders";
public const string CorrelationContextHeader = "Correlation-Context";
public const string UserAgentHeader = "User-Agent";

public const string FeatureManagementAssemblyName = "Microsoft.FeatureManagement";
public const string FeatureManagementAspNetCoreAssemblyName = "Microsoft.FeatureManagement.AspNetCore";

public const string SignalRAssemblyName = "Microsoft.AspNetCore.SignalR";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private FeatureFlag ParseFeatureFlag(string settingKey, string settingValue)
}
catch (JsonException e)
{
throw new FormatException(settingKey, e);
throw new FormatException(string.Format(ErrorMessages.FeatureFlagInvalidFormat, settingKey), e);
}

return featureFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,10 @@ public static string BuildFallbackClientLookupFailMessage(string exceptionMessag
{
return $"{LoggingConstants.FallbackClientLookupError}\n{exceptionMessage}";
}

public static string BuildRefreshFailedDueToFormattingErrorMessage(string exceptionMessage)
{
return $"{LoggingConstants.RefreshFailedDueToFormattingError}\n{exceptionMessage}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Azure.Data.AppConfiguration" Version="1.4.1" />
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.7.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.3.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
<PackageReference Include="DnsClient" Version="1.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
Expand All @@ -34,7 +34,7 @@
<!-- Nuget Package Version Settings -->

<PropertyGroup>
<OfficialVersion>7.2.0</OfficialVersion>
<OfficialVersion>7.3.0</OfficialVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(CDP_PATCH_NUMBER)'!='' AND '$(CDP_BUILD_TYPE)'=='Official'">
Expand All @@ -48,7 +48,7 @@
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\AzureAppConfigurationRules.ruleset</CodeAnalysisRuleSet>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<IsAotCompatible>true</IsAotCompatible>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ internal class RequestTracingOptions
/// Version of the Microsoft.FeatureManagement.AspNetCore assembly, if present in the application.
/// </summary>
public string FeatureManagementAspNetCoreVersion { get; set; }

/// <summary>
/// Flag to indicate whether Microsoft.AspNetCore.SignalR assembly is present in the application.
/// </summary>
public bool IsSignalRUsed { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re
correlationContextTags.Add(RequestTracingConstants.KeyVaultRefreshConfiguredTag);
}

if (requestTracingOptions.IsSignalRUsed)
{
correlationContextTags.Add(RequestTracingConstants.SignalRUsedTag);
}

var sb = new StringBuilder();

foreach (KeyValuePair<string,string> kvp in correlationContextKeyValues)
Expand Down
10 changes: 5 additions & 5 deletions tests/Tests.AzureAppConfiguration/FailoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FailOverTests
contentType: "text");

[Fact]
public void FailOverTests_ReturnsAllClientsIfAllBackedOff()
public async Task FailOverTests_ReturnsAllClientsIfAllBackedOff()
{
// Arrange
IConfigurationRefresher refresher = null;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void FailOverTests_ReturnsAllClientsIfAllBackedOff()
// Assert the inner request failed exceptions
Assert.True((exception.InnerException as AggregateException)?.InnerExceptions?.All(e => e is RequestFailedException) ?? false);

refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

// The client manager should have called RefreshClients when all clients were backed off
Assert.Equal(1, configClientManager.RefreshClientsCalled);
Expand Down Expand Up @@ -144,7 +144,7 @@ public void FailOverTests_PropagatesNonFailOverableExceptions()
}

[Fact]
public void FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
public async Task FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
{
// Arrange
IConfigurationRefresher refresher = null;
Expand Down Expand Up @@ -199,7 +199,7 @@ public void FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
refresher = options.GetRefresher();
}).Build();

refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

// The first client should not have been called during refresh
mockClient1.Verify(mc => mc.GetConfigurationSettingAsync(It.IsAny<ConfigurationSetting>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()), Times.Exactly(0));
Expand All @@ -211,7 +211,7 @@ public void FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
// Wait for client 1 backoff to end
Thread.Sleep(2500);

refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

// The first client should have been called now with refresh after the backoff time ends
mockClient1.Verify(mc => mc.GetConfigurationSettingAsync(It.IsAny<ConfigurationSetting>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()), Times.Exactly(1));
Expand Down
Loading

0 comments on commit 059b529

Please sign in to comment.