3

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

GoldenAge
  • 2,918
  • 5
  • 25
  • 63

1 Answers1

3

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");
                    });
                }
David Boss
  • 175
  • 6
  • yeah but when I define a new feature flag with the label "blah" in Azure and then I want to dynamically query my backend API for it I need to make a change to the code first to be able to retrieve it, right? `opt.Label` is just a `string` field so what should I do if I have many different labels in my feature flags? Just list them after the comma? like opt.Label = "label1,label2,label3..." ? – GoldenAge Oct 07 '21 at 16:52
  • you could add all your labels in the UseFeatureFlags() method call. But that is not very scalable. So we use labels to define the same Flag in different environment with the label representing the environment. Not sure what you use labels for. From all I have read it is to distinguish the same Flag for different circumstances. If you have labels on individual flags that are not the same I would reconsider your use of labels. Or just add them all to the method call. – David Boss Oct 08 '21 at 20:12
  • Ok, now I get it. Thanks for the explanation. I can accept this as an answer, thx! – GoldenAge Oct 09 '21 at 03:06