dotnet-sdk-contrib icon indicating copy to clipboard operation
dotnet-sdk-contrib copied to clipboard

Cannot make FeatureManagement provider work with On/Off features declaration

Open kaluznyt opened this issue 1 year ago • 4 comments

Hi,

I'm encountering an issue with having the OpenFeature / FeatureManagement provider to work with the On/Off features declaration: https://learn.microsoft.com/en-us/azure/azure-app-configuration/feature-management-dotnet-reference?pivots=stable-version#onoff-declaration

featureFlags.json

{
    // Define feature flags in config file
    "FeatureManagement": {
        "FeatureT": true, // On feature
    }
}

Having this code:

var configurationBuilder2 = new ConfigurationBuilder();
configurationBuilder2.AddJsonFile("featureFlags.json");
IConfiguration featureFlagsConfig = configurationBuilder2.Build();

var featureManagementProvider = new FeatureManagementProvider(featureFlagsConfig);
await OpenFeature.Api.Instance.SetProviderAsync(featureManagementProvider);
var client = OpenFeature.Api.Instance.GetClient();

var feature = await client.GetBooleanValue("FeatureT", false);

It always evaluates fo false.

But when provided with this code:

{
  "FeatureManagement": {
    "FeatureT": {
      "Allocation": {
        "DefaultWhenEnabled": "FlagEnabled",
        "DefaultWhenDisabled": "FlagDisabled"
      },
      "Variants": [
        {
          "Name": "FlagEnabled",
          "ConfigurationValue": true
        },
        {
          "Name": "FlagDisabled",
          "ConfigurationValue": false
        }
      ],
      "EnabledFor": [
        {
          "Name": "AlwaysOn"
        }
      ]
    }
  }
}

It works fine.

Basically, we have a lot of boolean flags, which doesn't make sense to introduce that kind of structure per each.

But perhaps I'm missing something.

This if just a first step to migrate from FeatureManagement to OpenFeature, before connecting with third party provider.

Any hints ?

kaluznyt avatar Aug 22 '24 11:08 kaluznyt

@ericpattison is support for this simple configuration perhaps a missing feature?

toddbaert avatar Aug 22 '24 12:08 toddbaert

Guessing the issue might be with handling anything other than boolean, however, I workaround it by implementing a custom FeatureManager that injects IFeatureManager and implements just GetBoolean method, since it's the only feature we need for now.

kaluznyt avatar Aug 22 '24 13:08 kaluznyt

It likely has to do with the fact that FeatureManagement was originally only designed to support Boolean checks. The reason this implementation works is due to a still not fully released feature for what they call "Variants". I'm thinking it should be a simple adjustment to allow for the simpler flags, but it would only work for boolean values since that's the only thing you can do without variants.

ericpattison avatar Aug 22 '24 15:08 ericpattison

Sure, thanks, it was just my thoughts as well while creating a custom provider for it.

kaluznyt avatar Aug 22 '24 15:08 kaluznyt