-
Notifications
You must be signed in to change notification settings - Fork 720
Add Azure App Configuration client integration #8459
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
Closed
zhiyuanliang-ms
wants to merge
20
commits into
dotnet:main
from
zhiyuanliang-ms:zhiyuanliang/app-config-component
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7f3fc99
client integration for Azure App Config
zhiyuanliang-ms aaac4cc
update
zhiyuanliang-ms 14bbfc0
add readme
zhiyuanliang-ms d347f91
update configuration schema
zhiyuanliang-ms 803de74
add conformance test
zhiyuanliang-ms 59b1dc2
fix project path
zhiyuanliang-ms 0b0baf9
update
zhiyuanliang-ms 24a3b56
fix testcases
zhiyuanliang-ms b98b94d
finished unit test
zhiyuanliang-ms d628c7a
use empty token credential in the testcase
zhiyuanliang-ms 21a6f75
merge main
zhiyuanliang-ms 316eb9d
update example
zhiyuanliang-ms 2cf4ec8
remove dead code
zhiyuanliang-ms 9ff3572
fix typo in readme
zhiyuanliang-ms f5a5732
update test project
zhiyuanliang-ms 3a893f7
improve health check
zhiyuanliang-ms 2a7a62e
merge main
zhiyuanliang-ms 2e4382f
update Directory.Packages
zhiyuanliang-ms f808da4
add configuration provider logging category
zhiyuanliang-ms b15edf8
update configurationschema
zhiyuanliang-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| <UserSecretsId>6624a704-3e83-4d16-826d-964ae9acb07c</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.AppConfiguration" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\WorkerService\WorkerService.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var appConfig = builder | ||
| .AddAzureAppConfiguration("appconfig"); | ||
|
|
||
| builder.AddProject<Projects.WorkerService>("workerservice") | ||
| .WithReference(appConfig); | ||
|
|
||
| builder.Build().Run(); |
29 changes: 29 additions & 0 deletions
29
playground/AzureAppConfiguration/AppHost/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17091;http://localhost:15133", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21146", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22084" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15133", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19209", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20168" | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
playground/AzureAppConfiguration/AppHost/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| }, | ||
| "Azure": { | ||
| "SubscriptionId": "<SUBSCRIPTION-ID>", | ||
| "AllowResourceGroupCreation": true, | ||
| "ResourceGroup": "<RESOURCE-GROUP-NAME>", | ||
| "Location": "<REGION-NAME>" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using Microsoft.FeatureManagement; | ||
| using WorkerService; | ||
|
|
||
| var builder = Host.CreateApplicationBuilder(args); | ||
|
|
||
| builder.AddServiceDefaults(); | ||
| builder.AddAzureAppConfigurationClient("appConfig"); | ||
| builder.Services.AddHostedService<Worker>(); | ||
| builder.Configuration.AddAzureAppConfiguration( | ||
| "appconfig", | ||
| configureOptions: options => { | ||
| options.UseFeatureFlags(); | ||
| options.ConfigureRefresh(refresh => | ||
| { | ||
| refresh.RegisterAll(); | ||
| }); | ||
| builder.Services.AddSingleton(options.GetRefresher()); | ||
| }); | ||
| builder.Services.AddFeatureManagement(); | ||
|
|
||
| var host = builder.Build(); | ||
| host.Run(); | ||
12 changes: 12 additions & 0 deletions
12
playground/AzureAppConfiguration/WorkerService/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "WorkerService": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "environmentVariables": { | ||
| "DOTNET_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using Microsoft.Extensions.Configuration.AzureAppConfiguration; | ||
| using Microsoft.FeatureManagement; | ||
|
|
||
| namespace WorkerService; | ||
|
|
||
| public class Worker : BackgroundService | ||
| { | ||
| private readonly ILogger<Worker> _logger; | ||
| private readonly IConfiguration _configuration; | ||
| private readonly IConfigurationRefresher _refresher; | ||
| private readonly IVariantFeatureManager _featureManager; | ||
|
|
||
| public Worker(ILogger<Worker> logger, IConfiguration configuration, IConfigurationRefresher refresher, IVariantFeatureManager featureManager) | ||
| { | ||
| _logger = logger; | ||
| _configuration = configuration; | ||
| _refresher = refresher; | ||
| _featureManager = featureManager; | ||
| } | ||
|
|
||
| protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
| { | ||
| while (!stoppingToken.IsCancellationRequested) | ||
| { | ||
| await _refresher.TryRefreshAsync(stoppingToken); | ||
| if (_logger.IsEnabled(LogLevel.Information)) | ||
| { | ||
| _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); | ||
| _logger.LogInformation("Message from App Config: {message}", _configuration["message"]); | ||
| _logger.LogInformation("Beta feature flag is enabled: {enabled}", await _featureManager.IsEnabledAsync("Beta", stoppingToken)); | ||
| } | ||
| await Task.Delay(10000, stoppingToken); | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
playground/AzureAppConfiguration/WorkerService/WorkerService.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <UserSecretsId>dotnet-WorkerService-a204435a-f29d-40a7-b698-e883da9db8da</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.FeatureManagement" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <AspireProjectOrPackageReference Include="Aspire.Azure.Data.AppConfiguration" /> | ||
| <ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
8 changes: 8 additions & 0 deletions
8
playground/AzureAppConfiguration/WorkerService/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.Hosting.Lifetime": "Information" | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
playground/AzureAppConfiguration/WorkerService/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.Hosting.Lifetime": "Information" | ||
| } | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/Components/Aspire.Azure.Data.AppConfiguration/AppConfigurationComponent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Azure.Common; | ||
| using Azure.Core; | ||
| using Azure.Core.Extensions; | ||
| using Azure.Data.AppConfiguration; | ||
| using Microsoft.Extensions.Azure; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
|
||
| namespace Aspire.Azure.Data.AppConfiguration; | ||
| internal sealed class AppConfigurationComponent : AzureComponent<AzureDataAppConfigurationSettings, ConfigurationClient, ConfigurationClientOptions> | ||
| { | ||
| protected override IAzureClientBuilder<ConfigurationClient, ConfigurationClientOptions> AddClient( | ||
| AzureClientFactoryBuilder azureFactoryBuilder, AzureDataAppConfigurationSettings settings, | ||
| string connectionName, string configurationSectionName) | ||
| { | ||
| return azureFactoryBuilder.AddClient<ConfigurationClient, ConfigurationClientOptions>((options, cred, _) => | ||
| { | ||
| if (settings.Endpoint is null) | ||
| { | ||
| throw new InvalidOperationException($"Endpoint is missing. It should be provided in 'ConnectionStrings:{connectionName}' or under the 'Endpoint' key in the '{configurationSectionName}' configuration section."); | ||
| } | ||
|
|
||
| return new ConfigurationClient(settings.Endpoint, cred, options); | ||
| }); | ||
| } | ||
|
|
||
| protected override IHealthCheck CreateHealthCheck(ConfigurationClient client, AzureDataAppConfigurationSettings settings) | ||
| { | ||
| return new AzureAppConfigurationHealthCheck(client); | ||
| } | ||
|
|
||
| protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<ConfigurationClient, ConfigurationClientOptions> clientBuilder, IConfiguration configuration) | ||
| { | ||
| #pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works | ||
| clientBuilder.ConfigureOptions(options => configuration.Bind(options)); | ||
| #pragma warning restore IDE0200 | ||
| } | ||
|
|
||
| protected override void BindSettingsToConfiguration(AzureDataAppConfigurationSettings settings, IConfiguration configuration) | ||
| { | ||
| configuration.Bind(settings); | ||
| } | ||
|
|
||
| protected override bool GetHealthCheckEnabled(AzureDataAppConfigurationSettings settings) | ||
| => !settings.DisableHealthChecks; | ||
|
|
||
| protected override TokenCredential? GetTokenCredential(AzureDataAppConfigurationSettings settings) | ||
| => settings.Credential; | ||
|
|
||
| protected override bool GetMetricsEnabled(AzureDataAppConfigurationSettings settings) | ||
| => false; | ||
|
|
||
| protected override bool GetTracingEnabled(AzureDataAppConfigurationSettings settings) | ||
| => !settings.DisableTracing; | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/Components/Aspire.Azure.Data.AppConfiguration/Aspire.Azure.Data.AppConfiguration.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
| <IsPackable>true</IsPackable> | ||
| <PackageTags>$(ComponentAzurePackageTags) configuration appconfiguration</PackageTags> | ||
| <Description>A client for Azure App Configuration that integrates with Aspire.</Description> | ||
| <PackageIconFullPath>$(SharedDir)AzureAppConfig_256x.png</PackageIconFullPath> | ||
| <NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn> | ||
| <!-- Disable package validation as this package hasn't shipped stable yet. --> | ||
| <EnablePackageValidation>false</EnablePackageValidation> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" /> | ||
| <Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" /> | ||
| <Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Data.AppConfiguration" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" /> | ||
| <PackageReference Include="Microsoft.Extensions.Azure" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.Binder" /> | ||
| <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" /> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" /> | ||
| <PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the minimal configuration. Why are there 3 layers of nested lambdas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the minimal configuration. The minimal configuration is just:
But to use advanced feature of App Config configuration provider (e.g. feature flag, dynamic refresh), you need to configure on
AzureAppConfigurationOptionsBTW, I followed the existing pattern of
AddAzureKeyVaultSecrets.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this sample is just trying to show both calls but we dont expect people to do this right?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people want to use advanced features of Azure App Configuration. They should write code just like what I did in the example. We do expect people to do this if they want to use feature flag and dynamic refresh. But for simple configuration scenario,
builder.Configuration.AddAzureAppConfiguration("appconfig");is enough.BTW, I am working on another PR: zhiyuanliang-ms#5
We decided to not implement anything for
ConfigurationClientfrom .net azure sdk. This PR should be deprecated.The new API will be an extension method on
IHostApplicationBuilder.builder.AddAzureAppConfiguration("appconfig");