Skip to content

Commit 8c2dbc9

Browse files
Add feature management schema for main branch (#362)
* schema file added * README update * update * update * update README & remove the Microsoft schema file * update readme * update
1 parent e968d52 commit 8c2dbc9

File tree

3 files changed

+139
-13
lines changed

3 files changed

+139
-13
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ The feature management library supports appsettings.json as a feature flag sourc
9191

9292
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.
9393

94+
The detailed schema of the `FeatureManagement` section can be found [here](./schemas/FeatureManagement.Dotnet.v1.0.0.schema.json).
95+
9496
**Advanced:** The usage of colon ':' in feature flag names is forbidden.
9597

9698
#### On/Off Declaration
@@ -121,7 +123,7 @@ The `RequirementType` property of a feature flag is used to determine if the fil
121123

122124
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.
123125

124-
```
126+
``` JavaScript
125127
"FeatureW": {
126128
"RequirementType": "All",
127129
"EnabledFor": [
@@ -144,6 +146,36 @@ A `RequirementType` of `All` changes the traversal. First, if there are no filte
144146

145147
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.
146148

149+
#### Microsoft Feature Management Schema
150+
151+
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.
152+
153+
```JavaScript
154+
{
155+
"feature_management": {
156+
"feature_flags": [
157+
{
158+
"id": "FeatureT",
159+
"enabled": true,
160+
"conditions": {
161+
"client_filters": [
162+
{
163+
"name": "Microsoft.TimeWindow",
164+
"parameters": {
165+
"Start": "Mon, 01 May 2023 13:59:59 GMT",
166+
"End": "Sat, 01 July 2023 00:00:00 GMT"
167+
}
168+
}
169+
]
170+
}
171+
}
172+
]
173+
}
174+
}
175+
```
176+
177+
**Note:** If the `feature_management` section can be found in the configuration, the `FeatureManagement` section will be ignored.
178+
147179
## Consumption
148180

149181
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.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"definitions": {},
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"type": "object",
5+
"title": "The .NET Feature Management Schema",
6+
"required": [],
7+
"patternProperties": {
8+
"^[^:]*$": {
9+
"description": "Declares a feature flag.",
10+
"anyOf": [
11+
{
12+
"type": "boolean",
13+
"title": "On/Off Feature Flag",
14+
"description": "A feature flag that always returns the same value."
15+
},
16+
{
17+
"type": "object",
18+
"title": "Conditional Feature Flag",
19+
"description": "A feature flag which value is dynamic based on a set of feature filters",
20+
"required": [
21+
"EnabledFor"
22+
],
23+
"properties": {
24+
"RequirementType": {
25+
"type": "string",
26+
"title": "Requirement Type",
27+
"description": "Determines whether any or all registered feature filters must be enabled for the feature to be considered enabled.",
28+
"enum": [
29+
"Any",
30+
"All"
31+
],
32+
"default": "Any"
33+
},
34+
"EnabledFor": {
35+
"oneOf": [
36+
{
37+
"type": "array",
38+
"title": "Feature Filter Collection",
39+
"description": "Feature filters that are evaluated to conditionally enable the flag.",
40+
"items": {
41+
"type": "object",
42+
"title": "Feature Filter Declaration",
43+
"required": [
44+
"Name"
45+
],
46+
"properties": {
47+
"Name": {
48+
"type": "string",
49+
"title": "Feature Filter Name",
50+
"description": "The name used to refer to and require a feature filter.",
51+
"default": "",
52+
"examples": [
53+
"Percentage",
54+
"TimeWindow"
55+
],
56+
"pattern": "^[^:]*$"
57+
},
58+
"Parameters": {
59+
"type": "object",
60+
"title": "Feature Filter Parameters",
61+
"description": "Custom parameters for a given feature filter. A feature filter can require any set of parameters of any type.",
62+
"required": [],
63+
"patternProperties": {
64+
"^.*$": {
65+
"anyOf": [
66+
{
67+
"type": "string"
68+
},
69+
{
70+
"type": "null"
71+
},
72+
{
73+
"type": "object"
74+
},
75+
{
76+
"type": "number"
77+
},
78+
{
79+
"type": "array"
80+
},
81+
{
82+
"type": "boolean"
83+
}
84+
]
85+
}
86+
}
87+
}
88+
}
89+
}
90+
},
91+
{
92+
"type": "boolean"
93+
}
94+
]
95+
},
96+
"additionalProperties": false
97+
}
98+
}
99+
]
100+
}
101+
}
102+
}

src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,11 @@ private FeatureDefinition ParseFeatureDefinition(IConfigurationSection configura
192192
We support
193193
194194
myFeature: {
195-
enabledFor: [ "myFeatureFilter1", "myFeatureFilter2" ]
195+
enabledFor: [{name: "myFeatureFilter1"}, {name: "myFeatureFilter2"}]
196196
},
197197
myDisabledFeature: {
198198
enabledFor: [ ]
199199
},
200-
myFeature2: {
201-
enabledFor: "myFeatureFilter1;myFeatureFilter2"
202-
},
203-
myDisabledFeature2: {
204-
enabledFor: ""
205-
},
206-
myFeature3: "myFeatureFilter1;myFeatureFilter2",
207-
myDisabledFeature3: "",
208200
myAlwaysEnabledFeature: true,
209201
myAlwaysDisabledFeature: false // removing this line would be the same as setting it to false
210202
myAlwaysEnabledFeature2: {
@@ -214,9 +206,9 @@ We support
214206
enabledFor: false
215207
},
216208
myAllRequiredFilterFeature: {
217-
requirementType: "all"
218-
enabledFor: [ "myFeatureFilter1", "myFeatureFilter2" ],
219-
},
209+
requirementType: "all",
210+
enabledFor: [{name: "myFeatureFilter1"}, {name: "myFeatureFilter2"}]
211+
}
220212
221213
*/
222214

0 commit comments

Comments
 (0)