open-feature / dotnet-sdk-contrib

OpenFeature Providers and Hooks for .NET
https://openfeature.dev
Apache License 2.0
30 stars 22 forks source link

Cannot make FeatureManagement provider work with On/Off features declaration #263

Open kaluznyt opened 3 months ago

kaluznyt commented 3 months ago

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 ?

toddbaert commented 3 months ago

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

kaluznyt commented 3 months ago

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.

ericpattison commented 3 months ago

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.

kaluznyt commented 3 months ago

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