-
Notifications
You must be signed in to change notification settings - Fork 40
Support both .NET and microsoft schema for feature flags #566
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
Merged
amerjusupovic
merged 8 commits into
preview
from
ajusupovic/support-featuremanagement-dotnet-schema
Jul 10, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a6e57f
adding new private methods for dotnet versus microsoft schema, fixing…
amerjusupovic 0a8d11b
remove unused method
amerjusupovic 0251661
Merge branch 'preview' into ajusupovic/support-featuremanagement-dotn…
amerjusupovic 8e96d6d
remove schema warning, PR comments
amerjusupovic 1f8ddbd
Merge branch 'ajusupovic/support-featuremanagement-dotnet-schema' of …
amerjusupovic 661aa62
unify process feature flag approaches with id, fix schema check
amerjusupovic a602820
fix tests to match changes
amerjusupovic d27c7c2
check for empty variants when deciding schema
amerjusupovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,104 @@ public Task<IEnumerable<KeyValuePair<string, string>>> ProcessKeyValue(Configura | |
|
|
||
| var keyValues = new List<KeyValuePair<string, string>>(); | ||
|
|
||
| // Check if we need to process the feature flag using the microsoft schema | ||
| if ((featureFlag.Variants != null && featureFlag.Variants.Any()) || featureFlag.Allocation != null || featureFlag.Telemetry != null) | ||
| { | ||
| keyValues = ProcessMicrosoftSchemaFeatureFlag(featureFlag, setting, endpoint); | ||
| } | ||
| else | ||
| { | ||
| keyValues = ProcessDotnetSchemaFeatureFlag(featureFlag, setting, endpoint); | ||
| } | ||
|
|
||
| return Task.FromResult<IEnumerable<KeyValuePair<string, string>>>(keyValues); | ||
| } | ||
|
|
||
| public bool CanProcess(ConfigurationSetting setting) | ||
| { | ||
| string contentType = setting?.ContentType?.Split(';')[0].Trim(); | ||
|
|
||
| return string.Equals(contentType, FeatureManagementConstants.ContentType) || | ||
| setting.Key.StartsWith(FeatureManagementConstants.FeatureFlagMarker); | ||
| } | ||
|
|
||
| public bool NeedsRefresh() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public void OnChangeDetected(ConfigurationSetting setting = null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| public void OnConfigUpdated() | ||
| { | ||
| _featureFlagIndex = 0; | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| private List<KeyValuePair<string, string>> ProcessDotnetSchemaFeatureFlag(FeatureFlag featureFlag, ConfigurationSetting setting, Uri endpoint) | ||
| { | ||
| var keyValues = new List<KeyValuePair<string, string>>(); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd suggest we unify the approach. |
||
| if (string.IsNullOrEmpty(featureFlag.Id)) | ||
| { | ||
| return keyValues; | ||
| } | ||
|
|
||
| string featureFlagPath = $"{FeatureManagementConstants.DotnetSchemaSectionName}:{featureFlag.Id}"; | ||
|
|
||
| if (featureFlag.Enabled) | ||
| { | ||
| if (featureFlag.Conditions?.ClientFilters == null || !featureFlag.Conditions.ClientFilters.Any()) | ||
| { | ||
| keyValues.Add(new KeyValuePair<string, string>(featureFlagPath, true.ToString())); | ||
| } | ||
| else | ||
| { | ||
| for (int i = 0; i < featureFlag.Conditions.ClientFilters.Count; i++) | ||
| { | ||
| ClientFilter clientFilter = featureFlag.Conditions.ClientFilters[i]; | ||
|
|
||
| _featureFilterTracing.UpdateFeatureFilterTracing(clientFilter.Name); | ||
|
|
||
| string clientFiltersPath = $"{featureFlagPath}:{FeatureManagementConstants.DotnetSchemaEnabledFor}:{i}"; | ||
|
|
||
| keyValues.Add(new KeyValuePair<string, string>($"{clientFiltersPath}:Name", clientFilter.Name)); | ||
|
|
||
| foreach (KeyValuePair<string, string> kvp in new JsonFlattener().FlattenJson(clientFilter.Parameters)) | ||
| { | ||
| keyValues.Add(new KeyValuePair<string, string>($"{clientFiltersPath}:Parameters:{kvp.Key}", kvp.Value)); | ||
| } | ||
| } | ||
|
|
||
| // | ||
| // process RequirementType only when filters are not empty | ||
| if (featureFlag.Conditions.RequirementType != null) | ||
| { | ||
| keyValues.Add(new KeyValuePair<string, string>( | ||
| $"{featureFlagPath}:{FeatureManagementConstants.DotnetSchemaRequirementType}", | ||
| featureFlag.Conditions.RequirementType)); | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| keyValues.Add(new KeyValuePair<string, string>($"{featureFlagPath}", false.ToString())); | ||
| } | ||
|
|
||
| return keyValues; | ||
| } | ||
|
|
||
| private List<KeyValuePair<string, string>> ProcessMicrosoftSchemaFeatureFlag(FeatureFlag featureFlag, ConfigurationSetting setting, Uri endpoint) | ||
| { | ||
| var keyValues = new List<KeyValuePair<string, string>>(); | ||
|
|
||
| if (string.IsNullOrEmpty(featureFlag.Id)) | ||
| { | ||
| return Task.FromResult<IEnumerable<KeyValuePair<string, string>>>(keyValues); | ||
| return keyValues; | ||
| } | ||
|
|
||
| string featureFlagPath = $"{FeatureManagementConstants.FeatureManagementSectionName}:{FeatureManagementConstants.FeatureFlagsSectionName}:{_featureFlagIndex}"; | ||
|
|
@@ -53,7 +148,7 @@ public Task<IEnumerable<KeyValuePair<string, string>>> ProcessKeyValue(Configura | |
| { | ||
| ClientFilter clientFilter = featureFlag.Conditions.ClientFilters[i]; | ||
|
|
||
| _featureFilterTracing.UpdateFeatureFilterTracing(clientFilter.Name); | ||
| _featureFilterTracing.UpdateFeatureFilterTracing(clientFilter.Name); | ||
|
|
||
| string clientFiltersPath = $"{featureFlagPath}:{FeatureManagementConstants.Conditions}:{FeatureManagementConstants.ClientFilters}:{i}"; | ||
|
|
||
|
|
@@ -70,7 +165,7 @@ public Task<IEnumerable<KeyValuePair<string, string>>> ProcessKeyValue(Configura | |
| if (featureFlag.Conditions.RequirementType != null) | ||
| { | ||
| keyValues.Add(new KeyValuePair<string, string>( | ||
| $"{featureFlagPath}:{FeatureManagementConstants.Conditions}:{FeatureManagementConstants.RequirementType}", | ||
| $"{featureFlagPath}:{FeatureManagementConstants.Conditions}:{FeatureManagementConstants.RequirementType}", | ||
| featureFlag.Conditions.RequirementType)); | ||
| } | ||
| } | ||
|
|
@@ -219,37 +314,7 @@ public Task<IEnumerable<KeyValuePair<string, string>>> ProcessKeyValue(Configura | |
| } | ||
| } | ||
|
|
||
| return Task.FromResult<IEnumerable<KeyValuePair<string, string>>>(keyValues); | ||
| } | ||
|
|
||
| public bool CanProcess(ConfigurationSetting setting) | ||
| { | ||
| string contentType = setting?.ContentType?.Split(';')[0].Trim(); | ||
|
|
||
| return string.Equals(contentType, FeatureManagementConstants.ContentType) || | ||
| setting.Key.StartsWith(FeatureManagementConstants.FeatureFlagMarker); | ||
| } | ||
|
|
||
| public void InvalidateCache(ConfigurationSetting setting = null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| public bool NeedsRefresh() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public void OnChangeDetected(ConfigurationSetting setting = null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| public void OnConfigUpdated() | ||
| { | ||
| _featureFlagIndex = 0; | ||
|
|
||
| return; | ||
| return keyValues; | ||
| } | ||
|
|
||
| private FormatException CreateFeatureFlagFormatException(string jsonPropertyName, string settingKey, string foundJsonValueKind, string expectedJsonValueKind) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We added these fields for .NET schema and then removed the fields when we moved to Microsoft schema in the previous PR.
Now that we're adding support for .NET schema again, do we need to re-add Conditional/AlwaysOn/Status/Disabled fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe those were all as a result of variants, so since the feature management library is only processing flags as .NET schema if they don't include variants, these fields shouldn't be necessary. @zhiyuanliang-ms can you fact check me here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field
AlwaysOnis still being used by .NET schema. ref docIn our preview release, we even support
Onfilter which was introduced by @amer's PR to support variant.A feature flag like this:
{ "id": "AlwaysOnFeature", "enabled": true }will look like this in .NET schema
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But .NET schema also support declaring feature flag in this way:
That's how currently .NET provider does. ref
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. So even though FM library supports "AlwaysOn" feature, we dont need to add that filter in the provider. Enabled/disabled features can be represented as
{"feature1": true}or{"feature2": false}.And FM library is not expecting
Statusfield with .NET schema.