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

Support both .NET and microsoft schema for feature flags #566

Merged

Conversation

amerjusupovic
Copy link
Member

@amerjusupovic amerjusupovic commented Jun 26, 2024

@amerjusupovic amerjusupovic linked an issue Jun 28, 2024 that may be closed by this pull request
@avanigupta
Copy link
Member

We might want to update/remove this warning:

public const string FeatureManagementMicrosoftSchemaVersionWarning = "Your application may be using an older version of " +

@@ -44,5 +44,10 @@ internal class FeatureManagementConstants
public const string ETag = "ETag";
public const string FeatureFlagId = "FeatureFlagId";
public const string FeatureFlagReference = "FeatureFlagReference";

// Dotnet schema keys
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field AlwaysOn is still being used by .NET schema. ref doc

In our preview release, we even support On filter 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

"AlwaysOnFeature": {
  "EnabledFor": [
     {"Name": "AlwaysOn"}
  ]
}

Copy link
Contributor

@zhiyuanliang-ms zhiyuanliang-ms Jul 9, 2024

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:

"AlwaysOnFeature": true

That's how currently .NET provider does. ref

these fields shouldn't be necessary

Yes.

Copy link
Member

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 Status field with .NET schema.

@@ -26,13 +27,107 @@ public FeatureManagementKeyValueAdapter(FeatureFilterTracing featureFilterTracin

public Task<IEnumerable<KeyValuePair<string, string>>> ProcessKeyValue(ConfigurationSetting setting, Uri endpoint, Logger logger, CancellationToken cancellationToken)
{
_isMicrosoftSchema = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm expecting this to be on a per flag basis.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise adding an unrelated flag that has variants will cause old flags that are working to break.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessKeyValue is invoked once per flag. So each flag will either use .NET schema or MS schema. Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The code would function correctly. I was thrown off because instance state is being used to flow a condition that's only relevant to the method invocation. To avoid that, the decision of which schema to use should be done by the one who calls parse feature flag and does not need to be saved as instance state.

private List<KeyValuePair<string, string>> ProcessDotnetSchemaFeatureFlag(FeatureFlag featureFlag, ConfigurationSetting setting, Uri endpoint)
{
var keyValues = new List<KeyValuePair<string, string>>();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessMicrosoftSchemaFeatureFlag does


            if (string.IsNullOrEmpty(featureFlag.Id))
            {
                return keyValues;
            }

I'd suggest we unify the approach.

Copy link
Member

@jimmyca15 jimmyca15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per flag schema state

@@ -30,9 +30,104 @@ public FeatureManagementKeyValueAdapter(FeatureFilterTracing featureFilterTracin

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.Allocation != null || featureFlag.Telemetry != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to treat null and empty the same. Similarly to how client_filters are treated.

@amerjusupovic amerjusupovic merged commit 8a00750 into preview Jul 10, 2024
2 checks passed
@amerjusupovic amerjusupovic deleted the ajusupovic/support-featuremanagement-dotnet-schema branch July 10, 2024 17:41
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

Successfully merging this pull request may close these issues.

Support Microsoft feature flag schema
4 participants