Skip to content

Merge main to release/stable/v6 for 6.1.0 stable release #448

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 9 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
124 changes: 0 additions & 124 deletions .pipelines/windows-buddy-main.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

pr:
- main
- preview
- release/*

trigger:
- none
Expand Down Expand Up @@ -83,7 +85,6 @@ jobs:
script: '$(Build.SourcesDirectory)\build/CallPowerShell.cmd test.ps1|| exit /b 0'
workingDirectory: '$(Build.SourcesDirectory)'


- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.SourcesDirectory)\tests'
Expand Down
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: csharp
dist: trusty
mono: none
dotnet: 2.1.0
install:
- dotnet restore
script:
- dotnet build
- dotnet test Tests.AzureAppConfiguration/Tests.AzureAppConfiguration.csproj
language: csharp
dist: trusty
mono: none
dotnet: 2.1.0
install:
- dotnet restore
script:
- dotnet build
- dotnet test Tests.AzureAppConfiguration/Tests.AzureAppConfiguration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//
using Microsoft.Azure.AppConfiguration.AspNetCore;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;

namespace Microsoft.AspNetCore.Builder
{
Expand All @@ -23,14 +25,21 @@ public static IApplicationBuilder UseAzureAppConfiguration(this IApplicationBuil
throw new ArgumentNullException(nameof(builder));
}

IConfigurationRefresherProvider refresherProvider = (IConfigurationRefresherProvider)builder.ApplicationServices.GetService(typeof(IConfigurationRefresherProvider));

// Verify if AddAzureAppConfiguration was done before calling UseAzureAppConfiguration.
// We use the IConfigurationRefresherProvider to make sure if the required services were added.
if (builder.ApplicationServices.GetService(typeof(IConfigurationRefresherProvider)) == null)
if (refresherProvider == null)
{
throw new InvalidOperationException($"Unable to find the required services. Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(Microsoft.Extensions.Configuration.AzureAppConfigurationExtensions.AddAzureAppConfiguration)}()' in the application startup code.");
}

if (refresherProvider.Refreshers?.Count() > 0)
{
throw new InvalidOperationException("Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddAzureAppConfiguration' inside the call to 'ConfigureServices(...)' in the application startup code.");
builder.UseMiddleware<AzureAppConfigurationRefreshMiddleware>();
}

return builder.UseMiddleware<AzureAppConfigurationRefreshMiddleware>();
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.AppConfiguration.AspNetCore
Expand All @@ -13,7 +15,11 @@ namespace Microsoft.Azure.AppConfiguration.AspNetCore
/// </summary>
internal class AzureAppConfigurationRefreshMiddleware
{
// The minimum refresh interval on the configuration provider is 1 second, so refreshing more often is unnecessary
private static readonly long MinimumRefreshInterval = TimeSpan.FromSeconds(1).Ticks;
private readonly RequestDelegate _next;
private long _refreshReadyTime = DateTimeOffset.UtcNow.Ticks;

public IEnumerable<IConfigurationRefresher> Refreshers { get; }

public AzureAppConfigurationRefreshMiddleware(RequestDelegate next, IConfigurationRefresherProvider refresherProvider)
Expand All @@ -24,9 +30,23 @@ public AzureAppConfigurationRefreshMiddleware(RequestDelegate next, IConfigurati

public async Task InvokeAsync(HttpContext context)
{
foreach (var refresher in Refreshers)
long utcNow = DateTimeOffset.UtcNow.Ticks;

long refreshReadyTime = Interlocked.Read(ref _refreshReadyTime);

if (refreshReadyTime <= utcNow &&
Interlocked.CompareExchange(ref _refreshReadyTime, utcNow + MinimumRefreshInterval, refreshReadyTime) == refreshReadyTime)
{
_ = refresher.TryRefreshAsync();
//
// Configuration refresh is meant to execute as an isolated background task.
// To prevent access of request-based resources, such as HttpContext, we suppress the execution context within the refresh operation.
using (AsyncFlowControl flowControl = ExecutionContext.SuppressFlow())
{
foreach (IConfigurationRefresher refresher in Refreshers)
{
_ = Task.Run(() => refresher.TryRefreshAsync());
}
}
}

// Call the next delegate/middleware in the pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- Nuget Package Version Settings -->

<PropertyGroup>
<OfficialVersion>6.0.1</OfficialVersion>
<OfficialVersion>6.1.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 @@ -23,14 +23,22 @@ public static class AzureAppConfigurationRefreshExtensions
/// <param name="builder">An instance of <see cref="IFunctionsWorkerApplicationBuilder"/></param>
public static IFunctionsWorkerApplicationBuilder UseAzureAppConfiguration(this IFunctionsWorkerApplicationBuilder builder)
{
IServiceProvider serviceProvider = builder.Services.BuildServiceProvider();
IConfigurationRefresherProvider refresherProvider = serviceProvider.GetService<IConfigurationRefresherProvider>();

// Verify if AddAzureAppConfiguration was done before calling UseAzureAppConfiguration.
// We use the IConfigurationRefresherProvider to make sure if the required services were added.
if (!builder.Services.Any(service => service.ServiceType == typeof(IConfigurationRefresherProvider)))
if (refresherProvider == null)
{
throw new InvalidOperationException($"Unable to find the required services. Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(AzureAppConfigurationExtensions.AddAzureAppConfiguration)}()' in the application startup code.");
}

if (refresherProvider.Refreshers?.Count() > 0)
{
throw new InvalidOperationException($"Unable to find the required services. Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(AzureAppConfigurationExtensions.AddAzureAppConfiguration)}()' inside the call to 'ConfigureServices(...)' in the application startup code.");
builder.UseMiddleware<AzureAppConfigurationRefreshMiddleware>();
}

return builder.UseMiddleware<AzureAppConfigurationRefreshMiddleware>();
return builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Middleware;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.AppConfiguration.Functions.Worker
Expand All @@ -15,6 +16,10 @@ namespace Microsoft.Azure.AppConfiguration.Functions.Worker
/// </summary>
internal class AzureAppConfigurationRefreshMiddleware : IFunctionsWorkerMiddleware
{
// The minimum refresh interval on the configuration provider is 1 second, so refreshing more often is unnecessary
private static readonly long MinimumRefreshInterval = TimeSpan.FromSeconds(1).Ticks;
private long _refreshReadyTime = DateTimeOffset.UtcNow.Ticks;

private IEnumerable<IConfigurationRefresher> Refreshers { get; }

public AzureAppConfigurationRefreshMiddleware(IConfigurationRefresherProvider refresherProvider)
Expand All @@ -24,9 +29,23 @@ public AzureAppConfigurationRefreshMiddleware(IConfigurationRefresherProvider re

public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
{
foreach (IConfigurationRefresher refresher in Refreshers)
long utcNow = DateTimeOffset.UtcNow.Ticks;

long refreshReadyTime = Interlocked.Read(ref _refreshReadyTime);

if (refreshReadyTime <= utcNow &&
Interlocked.CompareExchange(ref _refreshReadyTime, utcNow + MinimumRefreshInterval, refreshReadyTime) == refreshReadyTime)
{
_ = refresher.TryRefreshAsync();
//
// Configuration refresh is meant to execute as an isolated background task.
// To prevent access of request-based resources, such as HttpContext, we suppress the execution context within the refresh operation.
using (AsyncFlowControl flowControl = ExecutionContext.SuppressFlow())
{
foreach (IConfigurationRefresher refresher in Refreshers)
{
_ = Task.Run(() => refresher.TryRefreshAsync());
}
}
}

await next(context).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<!-- Nuget Package Version Settings -->

<PropertyGroup>
<OfficialVersion>6.0.1</OfficialVersion>
<OfficialVersion>6.1.0</OfficialVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(CDP_PATCH_NUMBER)'!='' AND '$(CDP_BUILD_TYPE)'=='Official'">
Expand Down
Loading