Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings for different environment don't transform correctly #74

Open
tmarkovski opened this issue Jun 2, 2020 · 5 comments
Open

Settings for different environment don't transform correctly #74

tmarkovski opened this issue Jun 2, 2020 · 5 comments

Comments

@tmarkovski
Copy link

tmarkovski commented Jun 2, 2020

I have a Development and Staging setup. For some business reasons, I'd like to disable certain features entirely, while enable them with predefined criteria for other environments.

For example, my appsettings.json file may have something like this

"FeatureManagement": {
    "FeatureA": {
      "EnabledFor": [
        {
          "Name": "ProductPlan",
          "Parameters": {
            "AllowedPlans": [
              "Developer",
              "Production",
              "Enterprise"
            ]
          }
        }
      ]
    }
  }

However, I'd like entirely disable this for my Staging configuration.
In my appsettings.Staging.json I would like to completely disable the feature

"FeatureManagement": {
    "FeatureA": false
  }

It appears that this is not possible. I also tried specifying different subset in the AllowedPlans, but that didn't work either - the environment specific settings file was never processed.
Other settings in it work fine.

Is this an expected behavior? Any help would be appreciated. Thanks

@leonids2005
Copy link

leonids2005 commented Jun 3, 2020

We have similar requirements (sort of :) ) and we decided to use filter in a specific way and added IsEnabled field which controls a feature status.

{
  "FeatureManagement": {
    "FeatureA": {
      "EnabledFor": [
        {
          "Name": "ProductPlan",
          "Parameters": {
            "IsEnabled": true,
            "AllowedPlans": [
              "Developer",
              "Production",
              "Enterprise"
            ]
          }
        }
      ]
    }
  }
}

@josephwoodward
Copy link
Contributor

josephwoodward commented Jun 4, 2020

It strikes me that being able to override any feature as per @tmarkovski's approach should work.

Having looked through the source it looks like it comes down to this line where it requires the feature to be enabled otherwise it'll check for conditional features and find the settings loaded from appsettings.json.

Here's a draft PR that enable supporting such an option.

@tmarkovski
Copy link
Author

Thanks @josephwoodward . I just assumed environment specific setting should work similarly as other settings. Your approach looks on point, thank you.

@jimmyca15
Copy link
Member

@tmarkovski I haven't seen this encountered yet but it is indeed an issue. A contributing factor to this issue is that when .NET Core composes the settings obtained from multiple json files it does not necessarily overwrite existing fields. This same behavior is going to cause a problem with the fix proposed by JosephWoodward. For example, if we start to short circuit evaluation because a feature is set to false how would we override it in a staging configuration? We would need to set the false to something else, maybe 'true'?

"FeatureManagement": {
    "FeatureA": true,
    "FeatureA": {
      "EnabledFor": [
        {
          "Name": "ProductPlan",
          "Parameters": {
            "AllowedPlans": [
              "Developer",
              "Production",
              "Enterprise"
            ]
          }
        }
      ]
    }
  }

But there are two problems with that.

  1. It looks odd to define FeatureA twice like that.
  2. 'true' would turn the feature on always, so really we would need to specify a value like "undefined" or really anything other than true or false.

This will need some thought to fix correctly and may require a change to the feature definition schema.

For now, the best way to address it without introducing another oddity is to do something like @leonids2005 is doing.

@leonids2005
Copy link

leonids2005 commented Jun 8, 2020

Sorry, my fault , I was not very attentive to change your definition

it should be

{
  "FeatureManagement": {
    "FeatureA": {
      "EnabledFor": [
        {
          "Name": "ProductPlan",
          "Parameters": {
            "IsEnabled": true,
            "AllowedPlans": [
              "Developer",
              "Production",
              "Enterprise"
            ]
          }
        }
      ]
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants