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 prefix filtering and prefix trimming from feature flags #234

Merged
merged 6 commits into from
Mar 26, 2021

Conversation

avanigupta
Copy link
Member

@avanigupta avanigupta commented Mar 8, 2021

In response to customer issue #163, this PR introduces two new APIs for using feature flags.

1. FeatureFlagOptions Select(string featureFlagFilter, string labelFilter) 

Call this method to selectively load feature flags based on key and label filters. This method can be called multiple times within a UseFeatureFlags call.

Usage example:

var configuration = new ConfigurationBuilder()
    .AddAzureAppConfiguration(options =>
    {
        options.Connect(connectionString);

        options.UseFeatureFlags(featureFlagOptions =>
        {
            featureFlagOptions.Select("MyFeature", "MyLabel");  // requests a single feature flag whose key is MyFeature and label is MyLabel 
            featureFlagOptions.Select("App1/*", "Label1");  // requests all feature flags whose key starts with App1/ and label is Label1 
            featureFlagOptions.CacheExpirationInterval = cacheExpirationTimeSpan;
        });
    })
    .Build();
2. FeatureFlagOptions TrimFeatureFlagPrefix(string prefix)

Trims the provided prefix from the keys of all feature flags retrieved from Azure App Configuration. Follows the same pattern as our existing TrimKeyPrefix API.

Usage example:

var configuration = new ConfigurationBuilder()
    .AddAzureAppConfiguration(options =>
    {
        options.Connect(connectionString);

        // Load feature flags with a specific prefix and label 
        options.UseFeatureFlags(featureFlagOptions =>
        {
            featureFlagOptions.Select("App1/*", "Label1");  // requests all feature flags whose key starts with App1/ and label is Label1 
            featureFlagOptions.Select("*");   // requests all feature flags whose label is null

            featureFlagOptions.TrimFeatureFlagPrefix("App1/");   // Trim "App1/" prefix from all feature flags
            featureFlagOptions.TrimFeatureFlagPrefix("Common/");  // Trim "Common/" prefix from all feature flags
        });
    })
    .Build();

@avanigupta avanigupta force-pushed the avanigupta/PrefixFilteringFeatureFlags branch from e4b6e32 to 5acf31a Compare March 20, 2021 01:00
@drago-draganov
Copy link
Contributor

Trim for feature flag is a bit confusing. Feature flags already have system required prefix.
Also Trim was introduced when the KV object model wasn't publicly available. Now we plan to add Map function and let customer code transform that way they see it fit. I don't think we should add any fixed transformations going forward.

@avanigupta
Copy link
Member Author

Trim for feature flag is a bit confusing. Feature flags already have system required prefix.
Also Trim was introduced when the KV object model wasn't publicly available. Now we plan to add Map function and let customer code transform that way they see it fit. I don't think we should add any fixed transformations going forward.

I think both solutions try to solve different problems. The Map API would let users transform their ConfigurationSetting object and can definitely be used to trim feature flag prefixes. But we also want to make sure that a ConfigurationSetting is processed by only one adapter - either our internal adapter, or user defined adapter in Map method. So if someone wants to trim a prefix from feature flags using Map API, they will have to let go of the built-in flattening of feature flags that we provide with our internal Feature Flag adapter.

For example, if I have this feature flag in AppConfig:

Key = .appconfig.featureflag/test_feature1
Value = {"id":"test_feature1","description":"","enabled":true,"conditions":{"client_filters":[{"name":"Microsoft.Targeting","parameters":{"Audience":{"Users":[],"Groups":[],"DefaultRolloutPercentage":50}}}]}}

TrimFeatureFlagPrefix("test_") would trim the prefix from the feature flag name while preserving the rest of the structure of feature flags:

FeatureManagement:feature1 =
FeatureManagement:feature1:EnabledFor =
FeatureManagement:feature1:EnabledFor:0 =
FeatureManagement:feature1:EnabledFor:0:Parameters =
FeatureManagement:feature1:EnabledFor:0:Parameters:Audience =
FeatureManagement:feature1:EnabledFor:0:Parameters:Audience:DefaultRolloutPercentage = 50
FeatureManagement:feature1:EnabledFor:0:Name = Microsoft.Targeting

@avanigupta
Copy link
Member Author

Trim for feature flag is a bit confusing. Feature flags already have system required prefix.
Also Trim was introduced when the KV object model wasn't publicly available. Now we plan to add Map function and let customer code transform that way they see it fit. I don't think we should add any fixed transformations going forward.

Discussed offline with @drago-draganov .
The TrimFeatureFlagPrefix API can be introduced for convenience and symmetry with TrimKeyPrefix API. In future, we can internally translate it to behave like a special case of the upcoming Map API.

@avanigupta avanigupta merged commit c45335f into main Mar 26, 2021
@avanigupta avanigupta deleted the avanigupta/PrefixFilteringFeatureFlags branch March 26, 2021 00:22
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.

5 participants