Azure App Configuration Feature Flag with Label is not retrieved by Microsoft.FeatureManagement.FeatureManager

1.7k Views Asked by At

I started using Azure App Configuration service and Feature Flags functionality in my project. The thing that I saw is whenever I define a new feature flag and set some value for the label field then it's not retrieved by the _featureManager.GetFeatureNamesAsync(); for some reason. I created a FeatureFlagManager for sake of feature flag management, which looks like this:

public class FeatureFlagManager: IFeatureFlagManager
{
    private readonly IFeatureManager _featureManager;

    public FeatureFlagManager(IFeatureManager featureManager)
    {
        _featureManager = featureManager;
    }

    public async Task<IEnumerable<FeatureFlag>> GetFeatureFlags()
    {
        var featureList = new List<FeatureFlag>();           
        var featureNames = _featureManager.GetFeatureNamesAsync();

        await foreach (var name in featureNames)
        {
            var isEnabled = await _featureManager.IsEnabledAsync(name);
            featureList.Add(new FeatureFlag()
            {
                FeatureName = name,
                IsEnabled = isEnabled
            });
        }

        return featureList;
    }
}

The REST API endpoint:

[HttpGet]
[Route("featureFlags")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<FeatureFlag>))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetFeatureFlags()
{
    using (new Tracer(Logger, $"{nameof(ConfigurationController)}.{nameof(GetFeatureFlags)}"))
    {
        return Ok(await _featureFlagManager.GetFeatureFlags());

    }
}

I have 5 feature flags defined in the Azure Configuration: enter image description here

but whenever I call my endpoint to get all the feature flags with values, the one that has label defined is get ignored;enter image description here

Is there any reason why it works this way or am I missing something? The other thing that I noticed is once you create a new feature flag in Azure and define a label, there is no further option to edit it. Cheers

1

There are 1 best solutions below

3
On BEST ANSWER

In program.cs you need to tell the configuration to return the Flags with labels.

                    if (!string.IsNullOrEmpty(settings["AppConfigConnectionString"]))
                {
                    builder.AddAzureAppConfiguration(options => {
                        options.Connect(settings["AppConfigConnectionString"]);
                        options.UseFeatureFlags(opt => opt.Label = "WHAT_EVER_LABEL_YOU_WANT");
                    });
                }