Skip to content

Commit 7b2884c

Browse files
Merge pull request #724 from Azure/main
Merge main to release/stable/v8
2 parents 2caf9e7 + af1c96c commit 7b2884c

15 files changed

+149
-54
lines changed

src/Microsoft.Azure.AppConfiguration.AspNetCore/Microsoft.Azure.AppConfiguration.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<!-- Nuget Package Version Settings -->
2222

2323
<PropertyGroup>
24-
<OfficialVersion>8.4.0</OfficialVersion>
24+
<OfficialVersion>8.5.0</OfficialVersion>
2525
</PropertyGroup>
2626

2727
<PropertyGroup Condition="'$(CDP_PATCH_NUMBER)'!='' AND '$(CDP_BUILD_TYPE)'=='Official'">

src/Microsoft.Azure.AppConfiguration.Functions.Worker/Microsoft.Azure.AppConfiguration.Functions.Worker.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<!-- Nuget Package Version Settings -->
2525

2626
<PropertyGroup>
27-
<OfficialVersion>8.4.0</OfficialVersion>
27+
<OfficialVersion>8.5.0</OfficialVersion>
2828
</PropertyGroup>
2929

3030
<PropertyGroup Condition="'$(CDP_PATCH_NUMBER)'!='' AND '$(CDP_BUILD_TYPE)'=='Official'">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
using Microsoft.Extensions.Diagnostics.HealthChecks;
5+
using System.Threading.Tasks;
6+
using System.Threading;
7+
8+
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration
9+
{
10+
internal sealed class AlwaysHealthyHealthCheck : IHealthCheck
11+
{
12+
private static readonly Task<HealthCheckResult> _healthyResult = Task.FromResult(HealthCheckResult.Healthy());
13+
14+
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
15+
{
16+
return _healthyResult;
17+
}
18+
}
19+
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.Extensions.DependencyInjection.Extensions;
88
using System;
99
using System.Collections.Generic;
10-
using System.Security;
1110

1211
namespace Microsoft.Extensions.Configuration
1312
{
@@ -16,19 +15,7 @@ namespace Microsoft.Extensions.Configuration
1615
/// </summary>
1716
public static class AzureAppConfigurationExtensions
1817
{
19-
private const string DisableProviderEnvironmentVariable = "AZURE_APP_CONFIGURATION_PROVIDER_DISABLED";
20-
private static readonly bool _isProviderDisabled = IsProviderDisabled();
21-
22-
private static bool IsProviderDisabled()
23-
{
24-
try
25-
{
26-
return bool.TryParse(Environment.GetEnvironmentVariable(DisableProviderEnvironmentVariable), out bool disabled) ? disabled : false;
27-
}
28-
catch (SecurityException) { }
29-
30-
return false;
31-
}
18+
private static readonly bool _isProviderDisabled = EnvironmentVariableHelper.GetBoolOrDefault(EnvironmentVariableNames.AppConfigurationProviderDisabled);
3219

3320
/// <summary>
3421
/// Adds key-value data from an Azure App Configuration store to a configuration builder using its connection string.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration
1313
{
14-
internal class AzureAppConfigurationHealthCheck : IHealthCheck
14+
internal sealed class AzureAppConfigurationHealthCheck : IHealthCheck
1515
{
1616
private static readonly PropertyInfo _propertyInfo = typeof(ChainedConfigurationProvider).GetProperty("Configuration", BindingFlags.Public | BindingFlags.Instance);
1717
private readonly IEnumerable<IHealthCheck> _healthChecks;
@@ -37,17 +37,27 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
3737
return HealthCheckResult.Unhealthy(HealthCheckConstants.NoProviderFoundMessage);
3838
}
3939

40+
HealthCheckResult worstResult = HealthCheckResult.Healthy();
41+
4042
foreach (IHealthCheck healthCheck in _healthChecks)
4143
{
4244
var result = await healthCheck.CheckHealthAsync(context, cancellationToken).ConfigureAwait(false);
4345

46+
// Keep track of the worst health status found
47+
// HealthStatus enum is ordered: Unhealthy(0) < Degraded(1) < Healthy(2)
48+
if (result.Status < worstResult.Status)
49+
{
50+
worstResult = result;
51+
}
52+
53+
// If an Unhealthy status is found, short-circuit since that's the worst possible
4454
if (result.Status == HealthStatus.Unhealthy)
4555
{
4656
return result;
4757
}
4858
}
4959

50-
return HealthCheckResult.Healthy();
60+
return worstResult;
5161
}
5262

5363
private void FindHealthChecks(IConfigurationRoot configurationRoot, List<IHealthCheck> healthChecks)

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Microsoft.Extensions.DependencyInjection
1414
/// </summary>
1515
public static class AzureAppConfigurationHealthChecksBuilderExtensions
1616
{
17+
private static readonly bool _isProviderDisabled = EnvironmentVariableHelper.GetBoolOrDefault(EnvironmentVariableNames.AppConfigurationProviderDisabled);
18+
1719
/// <summary>
1820
/// Add a health check for Azure App Configuration to given <paramref name="builder"/>.
1921
/// </summary>
@@ -32,10 +34,20 @@ public static IHealthChecksBuilder AddAzureAppConfiguration(
3234
IEnumerable<string> tags = default,
3335
TimeSpan? timeout = default)
3436
{
37+
IHealthCheck CreateHealthCheck(IServiceProvider sp)
38+
{
39+
if (_isProviderDisabled)
40+
{
41+
return new AlwaysHealthyHealthCheck();
42+
}
43+
44+
return new AzureAppConfigurationHealthCheck(
45+
factory?.Invoke(sp) ?? sp.GetRequiredService<IConfiguration>());
46+
}
47+
3548
return builder.Add(new HealthCheckRegistration(
3649
name ?? HealthCheckConstants.HealthCheckRegistrationName,
37-
sp => new AzureAppConfigurationHealthCheck(
38-
factory?.Invoke(sp) ?? sp.GetRequiredService<IConfiguration>()),
50+
CreateHealthCheck,
3951
failureStatus,
4052
tags,
4153
timeout));

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System.Net;
1717
using System.Net.Http;
1818
using System.Net.Sockets;
19-
using System.Security;
2019
using System.Text;
2120
using System.Threading;
2221
using System.Threading.Tasks;
@@ -143,15 +142,7 @@ public AzureAppConfigurationProvider(IConfigurationClientManager configClientMan
143142
MinRefreshInterval = RefreshConstants.DefaultRefreshInterval;
144143
}
145144

146-
// Enable request tracing if not opt-out
147-
string requestTracingDisabled = null;
148-
try
149-
{
150-
requestTracingDisabled = Environment.GetEnvironmentVariable(EnvironmentVariables.DisableRequestTracing);
151-
}
152-
catch (SecurityException) { }
153-
154-
_requestTracingEnabled = bool.TryParse(requestTracingDisabled, out bool tracingDisabled) ? !tracingDisabled : true;
145+
_requestTracingEnabled = !EnvironmentVariableHelper.GetBoolOrDefault(EnvironmentVariableNames.RequestTracingDisabled);
155146

156147
if (_requestTracingEnabled)
157148
{
@@ -583,15 +574,17 @@ public void ProcessPushNotification(PushNotification pushNotification, TimeSpan?
583574

584575
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
585576
{
577+
HealthStatus failureStatus = context.Registration?.FailureStatus ?? HealthStatus.Unhealthy;
578+
586579
if (!_lastSuccessfulAttempt.HasValue)
587580
{
588-
return HealthCheckResult.Unhealthy(HealthCheckConstants.LoadNotCompletedMessage);
581+
return new HealthCheckResult(status: failureStatus, description: HealthCheckConstants.LoadNotCompletedMessage);
589582
}
590583

591584
if (_lastFailedAttempt.HasValue &&
592585
_lastSuccessfulAttempt.Value < _lastFailedAttempt.Value)
593586
{
594-
return HealthCheckResult.Unhealthy(HealthCheckConstants.RefreshFailedMessage);
587+
return new HealthCheckResult(status: failureStatus, description: HealthCheckConstants.RefreshFailedMessage);
595588
}
596589

597590
return HealthCheckResult.Healthy();

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ private void FindRefreshers(IConfigurationRoot configurationRoot, ILoggerFactory
6363
{
6464
foreach (IConfigurationProvider provider in configurationRoot.Providers)
6565
{
66-
if (provider is AzureAppConfigurationProvider appConfigurationProvider)
66+
if (provider is IConfigurationRefresher configurationRefresher)
6767
{
68-
appConfigurationProvider.LoggerFactory = loggerFactory;
69-
refreshers.Add(appConfigurationProvider);
68+
refreshers.Add(configurationRefresher);
69+
70+
if (configurationRefresher is AzureAppConfigurationProvider azureAppConfigurationProvider)
71+
{
72+
azureAppConfigurationProvider.LoggerFactory = loggerFactory;
73+
}
7074
}
7175
else if (provider is ChainedConfigurationProvider chainedProvider)
7276
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
5+
using System;
6+
using System.Security;
7+
8+
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration
9+
{
10+
internal static class EnvironmentVariableHelper
11+
{
12+
public static bool GetBoolOrDefault(string variableName)
13+
{
14+
try
15+
{
16+
return bool.TryParse(Environment.GetEnvironmentVariable(variableName), out bool disabled) ? disabled : false;
17+
}
18+
catch (SecurityException) { }
19+
20+
return false;
21+
}
22+
}
23+
}

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/EnvironmentVariables.cs renamed to src/Microsoft.Extensions.Configuration.AzureAppConfiguration/EnvironmentVariableNames.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,26 @@ namespace Microsoft.Extensions.Configuration.AzureAppConfiguration
66
/// <summary>
77
/// Environment variables used to configure Azure App Configuration provider behavior.
88
/// </summary>
9-
internal static class EnvironmentVariables
9+
internal static class EnvironmentVariableNames
1010
{
1111
/// <summary>
1212
/// Environment variable to disable Feature Management schema compatibility.
1313
/// The value of this variable is a boolean string, e.g. "true" or "false".
1414
/// When set to "true", schema compatibility checks for feature flags are disabled,
1515
/// and all feature flags will be interpreted using the Microsoft Feature Flags schema.
1616
/// </summary>
17-
public const string DisableFmSchemaCompatibility = "AZURE_APP_CONFIGURATION_FM_SCHEMA_COMPATIBILITY_DISABLED";
17+
public const string FmSchemacompatibilityDisabled = "AZURE_APP_CONFIGURATION_FM_SCHEMA_COMPATIBILITY_DISABLED";
1818

1919
/// <summary>
2020
/// Environment variable to disable request tracing.
2121
/// The value of this variable is a boolean string, e.g. "true" or "false".
2222
/// </summary>
23-
public const string DisableRequestTracing = "AZURE_APP_CONFIGURATION_TRACING_DISABLED";
23+
public const string RequestTracingDisabled = "AZURE_APP_CONFIGURATION_TRACING_DISABLED";
24+
25+
/// <summary>
26+
/// Environment variable to disable Azure App Configuration provider.
27+
/// The value of this variable is a boolean string, e.g. "true" or "false".
28+
/// </summary>
29+
public const string AppConfigurationProviderDisabled = "AZURE_APP_CONFIGURATION_PROVIDER_DISABLED";
2430
}
2531
}

0 commit comments

Comments
 (0)