whatisthejava
whatisthejava

Reputation: 503

Refreshing Azure App Configuration Based on Label

I have created an Azure App Configuration and added several Feature Gates to it Following the documentation I added a different label to each one to represent a different environment.

The following snippet in Program.cs works when I do not define labels and the features

 config.AddAzureAppConfiguration(options =>
                        {
                            options.Connect(connectionString)
                            .Select(KeyFilter.Any)
                                   .ConfigureRefresh(refresh =>
                                        refresh.Register(KeyFilter.Any, true)
                                          .SetCacheExpiration(TimeSpan.FromSeconds(10)));

                            options.UseFeatureFlags();

                        });
                    });

By works i mean The features load and changing the feature in the Azur App Config causes the changes to hot change within 10 - 15 seconds.

For each Feature I have the following labels "Development", "Staging", "Production"

I can make the correct keys load on start up by using the following code

 config.AddAzureAppConfiguration(options =>
                        {
                            options.Connect(connectionString)
                            .Select(KeyFilter.Any, "Staging") // For example 
                                   .ConfigureRefresh(refresh =>
                                        refresh.Register(KeyFilter.Any, true)
                                          .SetCacheExpiration(TimeSpan.FromSeconds(10)));

                            options.UseFeatureFlags();

                        });
                    });

This will load the correct keys, but updating the values in the Azure portal doesnt refresh.

Tried several different techniques, but the refresh never updates if i have specified a label.

Is this a limitation or is my terminology wrong.

I have also tried several other things such as

refresh.Register(KeyFilter.Any,"Staging", true)
refresh.Register("SpecificKey","Staging", true)

But the refresh doesnt seem to work.

Any help would be great

Thank you

Added a bit more investigation

Here is an example of my app store, I am only using FeatureGates My App Store

When I have any label on the refresh stops working although the initial load works.

Here is my current config code

                 config.AddAzureAppConfiguration(options =>
                        {
                            options.Connect(connectionString);
                            options.Select(KeyFilter.Any, "Staging");
                            options.UseFeatureFlags(featureFlagOptions =>
                            {
                                featureFlagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(30);
                            });

                        });

If I remove the label "Staging" from the feature gates and the code then every 30 seconds my app refreshes.

I have also demonstrated this behaviour on a console app which i will upload

Has anyone found a way to get featuremanagement flags to auto refresh if you have a label on them ?

Upvotes: 1

Views: 1157

Answers (1)

Zhenlan Wang
Zhenlan Wang

Reputation: 1543

Did you miss below in the document?

When no parameter is passed to the UseFeatureFlags method, it loads all feature flags with no label in your App Configuration store. The default refresh expiration of feature flags is 30 seconds. You can customize this behavior via the FeatureFlagOptions parameter. For example, the following code snippet loads only feature flags that start with TestApp: in their key name and have the label dev. The code also changes the refresh expiration time to 5 minutes. Note that this refresh expiration time is separate from that for regular key-values.

options.UseFeatureFlags(featureFlagOptions =>
{
    featureFlagOptions.Select("TestApp:*", "dev");
    featureFlagOptions.CacheExpirationInterval = TimeSpan.FromMinutes(5);
});

Upvotes: -1

Related Questions