Merge Microsoft feature flags #551
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why this PR?
#507
There is a well-known pitfall when merging array value in configuration system in .NET.
We presented a solution in v4.2.1: concatenate feature flag arrays and let the last feature definition win.
However, a customer raised a concern that this behavior change will break their current usage. The customer’s team distributed a base appsettings file in the docker image. Developers just want to toggle the feature flag and what they do is to use another configuration source and update the “enabled” field for certain feature flags.
Base appsettings.json:
People may want to use the following appsetting.development.json file to toggle the “FeatureB” flag:
However, in 4.2.1, our concat ff arrays behavior will produce the following configuration:
The merge result that customer wanted
In addition, some customers may have the following usage:
appsettings.json
appsettings.Production.json
In short, what people is a layering-manner merge behavior.
Visible Changes
This PR is built on Merge feature flags from different configuration source #536 and Bug fix - Respect root configuration fallback #547. The
ConfigurationFeatureDefinitionProvider
will not only readfeature_flags
array from differentConfigurationProvider
, but also it will maintain a dictionary where key is feature name and value isList<IConfigurationSection>
that contains feature definition from different configuration source. In this case,ConfigurationFeatureDefinitionProvider
can merge them in an intuitive manner:The later feature definition will override the previous feature defintion. The granularity of the override behavior is at the property level within the FeatureDefinition class. For example:
The above configuration will produce such a feature definition after merging:
For more information, please go to testcases.
A lock is used in the
EnsureInit
method.