简体   繁体   中英

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

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: 在此处输入图像描述

but whenever I call my endpoint to get all the feature flags with values, the one that has label defined is get ignored; 在此处输入图像描述

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

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");
                    });
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM