Reputation: 3068
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
Upvotes: 3
Views: 2154
Reputation: 275
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");
});
}
Upvotes: 3