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

Consider the ability to allocate variants based on custom filters #460

Open
CuddleBunny opened this issue Jun 14, 2024 · 5 comments · May be fixed by #506
Open

Consider the ability to allocate variants based on custom filters #460

CuddleBunny opened this issue Jun 14, 2024 · 5 comments · May be fixed by #506
Labels
enhancement New feature or request

Comments

@CuddleBunny
Copy link

Variants are going to be a huge boon to this library and I'm excited to leverage them. I often find myself creating custom filters that evaluate based on the application state rather than the traditional user centric targeting scenarios. It would be great if we could allocate variants based on these filters. Perhaps something like:

  "FeatureManagement":
  {
      "MyVariantFeatureFlag":
      {   
          "Allocation": {
              "DefaultWhenEnabled": "Small",
              "AllocatedFor": [
                  {
                      "Name": "CustomFilter",
                      "Parameters": {
                          "SomeParam": "SomeValue"
                      },
                      "Variant": "Big"
                  }
              ]
          },
          "Variants": [
              { 
                  "Name": "Big"
              },  
              { 
                  "Name": "Small"
              } 
          ]
      }
  }
@jimmyca15
Copy link
Member

jimmyca15 commented Jun 14, 2024

It's an interesting idea. With your suggestion, what would you expect the interface of "CustomFilter" to look like?

@CuddleBunny
Copy link
Author

@jimmyca15 - I haven't gone too deep on the allocation code after I saw it was all private and I couldn't extend it myself. Could it be as simple as:

public interface IContextualVariantFeatureFilter<TContext> : IContextualFeatureFilter<TContext> {
    string Variant { get; set; }
}

@zhiyuanliang-ms zhiyuanliang-ms added the enhancement New feature or request label Jun 17, 2024
@zhiyuanliang-ms
Copy link
Contributor

Hi, @CuddleBunny Thank you for your suggestion. This is an interesting idea.

But, there is one thing I want to call out here. For the code snippet you provided here, I found that you were using .NET Feature Management schema to declare a variant feature flag. We had a PR to remove the variant & telemetry support from the .NET FM schema. The reason is that, starting from v4.0.0, we are going to embrace the Microsoft Feature Management schema which will replace .NET FM schema to be the primary schema for the .NET feature management library. Please see here and #408.

Now, our latest releases have fully supported the Microsoft FM schema. The latest preview release 4.0.0-preview3 can still recognize the variant feature flag specified in .NET schema but our next preview release will only recognize variant feature flag specified in Microsoft FM schema.

Besides, all the example projects in preview branch and example code snippets in our public doc for preview version have been changed to Microsoft FM schema. You can have a look at them. Thank you so much!

@CuddleBunny
Copy link
Author

@zhiyuanliang-ms - I saw the PR for the schema changes but hadn't looked into it yet. The docs I found for variants was in the release/v4 branch. I see that they were changed in the preview branch. If I understand the new schema correctly, the result would be something like the following, but I suspect the underlying code wouldn't change much?

{
    "feature_management": {
        "feature_flags": [
            {
                "id": "MyVariantFeatureFlag",
                "enabled": true,
                "allocation": {
                    "default_when_enabled": "Small",
                    "client_filters": [
                        {
                            "name": "CustomFilter",
                            "parameters": {
                                "SomeParam": "SomeValue"
                            },
                            "variant": "Big"
                        }
                    ]
                },
                "variants": [
                    {
                        "name": "Big"
                    },
                    {
                        "name": "Small"
                    }
                ]
            }
        ]
    }
}

@zhiyuanliang-ms
Copy link
Contributor

zhiyuanliang-ms commented Jun 17, 2024

@CuddleBunny The new variant feature flag configuration you provided is correct.

I suspect the underlying code wouldn't change much

You are right. The code didn't change much.

@CuddleBunny CuddleBunny linked a pull request Sep 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants