diff --git a/README.md b/README.md index f7434116..0081da9a 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,8 @@ The feature management library supports appsettings.json as a feature flag sourc The `FeatureManagement` section of the json document is used by convention to load feature flag settings. In the section above, we see that we have provided three different features. Features define their feature filters using the `EnabledFor` property. In the feature filters for `FeatureT` we see `AlwaysOn`. This feature filter is built-in and if specified will always enable the feature. The `AlwaysOn` feature filter does not require any configuration, so it only has the `Name` property. `FeatureU` has no filters in its `EnabledFor` property and thus will never be enabled. Any functionality that relies on this feature being enabled will not be accessible as long as the feature filters remain empty. However, as soon as a feature filter is added that enables the feature it can begin working. `FeatureV` specifies a feature filter named `TimeWindow`. This is an example of a configurable feature filter. We can see in the example that the filter has a `Parameters` property. This is used to configure the filter. In this case, the start and end times for the feature to be active are configured. +The detailed schema of the `FeatureManagement` section can be found [here](./schemas/FeatureManagement.Dotnet.v1.0.0.schema.json). + **Advanced:** The usage of colon ':' in feature flag names is forbidden. #### On/Off Declaration @@ -121,7 +123,7 @@ The `RequirementType` property of a feature flag is used to determine if the fil A `RequirementType` of `All` changes the traversal. First, if there are no filters, the feature will be disabled. Then, the feature-filters are traversed until one of the filters decides that the feature should be disabled. If no filter indicates that the feature should be disabled, then it will be considered enabled. -``` +``` JavaScript "FeatureW": { "RequirementType": "All", "EnabledFor": [ @@ -144,6 +146,36 @@ A `RequirementType` of `All` changes the traversal. First, if there are no filte In the above example, `FeatureW` specifies a `RequirementType` of `All`, meaning all of its filters must evaluate to true for the feature to be enabled. In this case, the feature will be enabled for 50% of users during the specified time window. +#### Microsoft Feature Management Schema + +The feature management library also supports the usage of the [`Microsoft Feature Management schema`](https://github.com/Azure/AppConfiguration/blob/main/docs/FeatureManagement/FeatureManagement.v1.0.0.schema.json) to declare feature flags. This schema is language agnostic in origin and is supported by all Microsoft feature management libraries. + +```JavaScript +{ + "feature_management": { + "feature_flags": [ + { + "id": "FeatureT", + "enabled": true, + "conditions": { + "client_filters": [ + { + "name": "Microsoft.TimeWindow", + "parameters": { + "Start": "Mon, 01 May 2023 13:59:59 GMT", + "End": "Sat, 01 July 2023 00:00:00 GMT" + } + } + ] + } + } + ] + } +} +``` + +**Note:** If the `feature_management` section can be found in the configuration, the `FeatureManagement` section will be ignored. + ## Consumption The basic form of feature management is checking if a feature flag is enabled and then performing actions based on the result. This is done through the `IFeatureManager`'s `IsEnabledAsync` method. diff --git a/schemas/FeatureManagement.Dotnet.v1.0.0.schema.json b/schemas/FeatureManagement.Dotnet.v1.0.0.schema.json new file mode 100644 index 00000000..430a68b5 --- /dev/null +++ b/schemas/FeatureManagement.Dotnet.v1.0.0.schema.json @@ -0,0 +1,102 @@ +{ + "definitions": {}, + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "The .NET Feature Management Schema", + "required": [], + "patternProperties": { + "^[^:]*$": { + "description": "Declares a feature flag.", + "anyOf": [ + { + "type": "boolean", + "title": "On/Off Feature Flag", + "description": "A feature flag that always returns the same value." + }, + { + "type": "object", + "title": "Conditional Feature Flag", + "description": "A feature flag which value is dynamic based on a set of feature filters", + "required": [ + "EnabledFor" + ], + "properties": { + "RequirementType": { + "type": "string", + "title": "Requirement Type", + "description": "Determines whether any or all registered feature filters must be enabled for the feature to be considered enabled.", + "enum": [ + "Any", + "All" + ], + "default": "Any" + }, + "EnabledFor": { + "oneOf": [ + { + "type": "array", + "title": "Feature Filter Collection", + "description": "Feature filters that are evaluated to conditionally enable the flag.", + "items": { + "type": "object", + "title": "Feature Filter Declaration", + "required": [ + "Name" + ], + "properties": { + "Name": { + "type": "string", + "title": "Feature Filter Name", + "description": "The name used to refer to and require a feature filter.", + "default": "", + "examples": [ + "Percentage", + "TimeWindow" + ], + "pattern": "^[^:]*$" + }, + "Parameters": { + "type": "object", + "title": "Feature Filter Parameters", + "description": "Custom parameters for a given feature filter. A feature filter can require any set of parameters of any type.", + "required": [], + "patternProperties": { + "^.*$": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + }, + { + "type": "object" + }, + { + "type": "number" + }, + { + "type": "array" + }, + { + "type": "boolean" + } + ] + } + } + } + } + } + }, + { + "type": "boolean" + } + ] + }, + "additionalProperties": false + } + } + ] + } + } +} \ No newline at end of file diff --git a/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs b/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs index 6e940760..4ec5d69c 100644 --- a/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs +++ b/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs @@ -192,19 +192,11 @@ private FeatureDefinition ParseFeatureDefinition(IConfigurationSection configura We support myFeature: { - enabledFor: [ "myFeatureFilter1", "myFeatureFilter2" ] + enabledFor: [{name: "myFeatureFilter1"}, {name: "myFeatureFilter2"}] }, myDisabledFeature: { enabledFor: [ ] }, - myFeature2: { - enabledFor: "myFeatureFilter1;myFeatureFilter2" - }, - myDisabledFeature2: { - enabledFor: "" - }, - myFeature3: "myFeatureFilter1;myFeatureFilter2", - myDisabledFeature3: "", myAlwaysEnabledFeature: true, myAlwaysDisabledFeature: false // removing this line would be the same as setting it to false myAlwaysEnabledFeature2: { @@ -214,9 +206,9 @@ We support enabledFor: false }, myAllRequiredFilterFeature: { - requirementType: "all" - enabledFor: [ "myFeatureFilter1", "myFeatureFilter2" ], - }, + requirementType: "all", + enabledFor: [{name: "myFeatureFilter1"}, {name: "myFeatureFilter2"}] + } */