Sick Gaming
Redesigning Configuration Refresh for Azure App Configuration - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Programming (https://www.sickgaming.net/forum-76.html)
+--- Forum: C#, Visual Basic, & .Net Frameworks (https://www.sickgaming.net/forum-79.html)
+--- Thread: Redesigning Configuration Refresh for Azure App Configuration (/thread-92043.html)



Redesigning Configuration Refresh for Azure App Configuration - xSicKxBot - 10-21-2019

Redesigning Configuration Refresh for Azure App Configuration

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2019/08/redesigning-configuration-refresh-for-azure-app-configuration.jpg" width="58" height="58" title="" alt="" /></div><div><div class="row justify-content-center">
<div class="col-md-4">
<div><img src="https://www.sickgaming.net/blog/wp-content/uploads/2019/08/redesigning-configuration-refresh-for-azure-app-configuration.jpg" width="58" height="58" alt="Avatar" class="avatar avatar-58 wp-user-avatar wp-user-avatar-58 photo avatar-default"></div>
</div>
</div>
<div class="entry-meta">
<p>August 27th, 2019</p>
</p></div>
<p><!-- .entry-meta --> </p>
<h2>Overview</h2>
<p>Since its inception, the .NET Core configuration provider for <a href="https://docs.microsoft.com/en-us/azure/azure-app-configuration/overview">Azure App Configuration</a> has provided the capability to monitor changes and sync them to the configuration within a running application. We recently redesigned this functionality to allow for on-demand refresh of the configuration. The new design paves the way for smarter applications that only refresh the configuration when necessary. As a result, inactive applications no longer have to monitor for configuration changes unnecessarily.<br />&nbsp;</p>
<h2>Initial design : Timer-based watch</h2>
<p>In the initial design, configuration was kept in sync with Azure App Configuration using a watch mechanism which ran on a timer. At the time of initialization of the Azure App Configuration provider, users could specify the configuration settings to be updated and an optional polling interval. In case the polling interval was not specified, a default value of 30 seconds was used.</p>
<pre><code>public static IWebHost BuildWebHost(string[] args)
{ WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostingContext, config) =&gt; { // Load settings from Azure App Configuration // Set up the provider to listen for changes triggered by a sentinel value var settings = config.Build(); string appConfigurationEndpoint = settings["AzureAppConfigurationEndpoint"]; config.AddAzureAppConfiguration(options =&gt; { options.ConnectWithManagedIdentity(appConfigurationEndpoint) .Use(keyFilter: "WebDemo:*") .WatchAndReloadAll(key: "WebDemo:Sentinel", label: LabelFilter.Null); }); settings = config.Build(); }) .UseStartup&lt;Startup&gt;() .Build();
}
</code></pre>
<p>For example, in the above code snippet, Azure App Configuration would be pinged every 30 seconds for changes. These calls would be made irrespective of whether the application was active or not. As a result, there would be unnecessary usage of network and CPU resources within inactive applications. Applications needed a way to trigger a refresh of the configuration on demand in order to be able to limit the refreshes to active applications. Then unnecessary checks for changes could be avoided.</p>
<p>This timer-based watch mechanism had the following fundamental design flaws.</p>
<ol>
<li>It could not be invoked on-demand.</li>
<li>It continued to run in the background even in applications that could be considered inactive.</li>
<li>It promoted constant polling of configuration rather than a more intelligent approach of updating configuration when applications are active or need to ensure freshness.<br />&nbsp;</li>
</ol>
<h2>New design : Activity-based refresh</h2>
<p>The new refresh mechanism allows users to keep their configuration updated using a middleware to determine activity. As long as the ASP.NET Core web application continues to receive requests, the configuration settings continue to get updated with the configuration store.</p>
<p>The application can be configured to trigger refresh for each request by adding the Azure App Configuration middleware from package <a href="https://www.nuget.org/packages/Microsoft.Azure.AppConfiguration.AspNetCore"><code>Microsoft.Azure.AppConfiguration.AspNetCore</code></a> in your application’s startup code.</p>
<pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ app.UseAzureAppConfiguration(); app.UseMvc();
}
</code></pre>
<p>At the time of initialization of the configuration provider, the user can use the <code>ConfigureRefresh</code> method to register the configuration settings to be updated with an optional cache expiration time. In case the cache expiration time is not specified, a default value of 30 seconds is used.</p>
<pre><code>public static IWebHost BuildWebHost(string[] args)
{ WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostingContext, config) =&gt; { // Load settings from Azure App Configuration // Set up the provider to listen for changes triggered by a sentinel value var settings = config.Build(); string appConfigurationEndpoint = settings["AzureAppConfigurationEndpoint"]; config.AddAzureAppConfiguration(options =&gt; { options.ConnectWithManagedIdentity(appConfigurationEndpoint) .Use(keyFilter: "WebDemo:*") .ConfigureRefresh((refreshOptions) =&gt; { // Indicates that all settings should be refreshed when the given key has changed refreshOptions.Register(key: "WebDemo:Sentinel", label: LabelFilter.Null, refreshAll: true); }); }); settings = config.Build(); }) .UseStartup&lt;Startup&gt;() .Build();
}
</code></pre>
<p>In order to keep the settings updated and avoid unnecessary calls to the configuration store, an internal cache is used for each setting. Until the cached value of a setting has expired, the refresh operation does not update the value. This happens even when the value has changed in the configuration store. &nbsp;</p>
<h2>Try it now!</h2>
<p>For more information about Azure App Configuration, check out the following resources. You can find step-by-step tutorials that would help you get started with dynamic configuration using the new refresh mechanism within minutes. Please let us know what you think by filing issues on <a href="https://github.com/Azure/AppConfiguration/issues">GitHub</a>.</p>
<p><a href="https://docs.microsoft.com/en-us/azure/azure-app-configuration">Overview: Azure App configuration</a><br /><a href="https://docs.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-aspnet-core">Tutorial: Use dynamic configuration in an ASP.NET Core app</a><br /><a href="https://docs.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-dotnet-core">Tutorial: Use dynamic configuration in a .NET Core app</a><br /><a href="https://devblogs.microsoft.com/aspnet/configuring-a-server-side-blazor-app-with-azure-app-configuration">Related Blog: Configuring a Server-side Blazor app with Azure App Configuration</a></p>
<div class="authorinfoarea">
<div><img src="https://www.sickgaming.net/blog/wp-content/uploads/2019/08/redesigning-configuration-refresh-for-azure-app-configuration-1.jpg" width="96" height="96" alt="Avatar" class="avatar avatar-96 wp-user-avatar wp-user-avatar-96 photo avatar-default"></div>
<div>
<h5></h5>
<p>Software Engineer,&nbsp;Azure App Configuration</p>
<p><strong>Follow </strong>&nbsp;&nbsp;&nbsp;<a class="no-underline stayinformed" aria-label=" LinkedIn profile" target="_blank" href="https://www.linkedin.com/in/abhilasharora" rel="noopener noreferrer"><i class="fa fa-linkedin"></i></a><a class="no-underline stayinformed hvr-pop" aria-label=" RSS Feed" target="_blank" href="https://devblogs.microsoft.com/aspnet/author/abarora/feed/" rel="noopener noreferrer"></a></p>
</p></div>
</p></div>
</div>


https://www.sickgaming.net/blog/2019/08/27/redesigning-configuration-refresh-for-azure-app-configuration/