Add more feature flags by label after app is running
Our feature flags are not in the configuration explorer, so to listen to multiple labels, I chain the options.UseFeatureFlags method.
builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(connectionString);
options.UseFeatureFlags(featureOptions =>
{
featureOptions.Label = "someLabel";
}).UseFeatureFlags(featureOptions =>
{
featureOptions.Label = "anotherLabel";
});
});
That is done in the Program.cs. Sometimes a new label will be added while this application is already running and this application will need to listen to all feature flags that have the new label. I figured we could utilize a configuration key and have it hold an array of strings (aka labels) and periodically check this configuration key for changes. If there is a new label, then have the application start listening to all feature flags with that label.
One, is there a way to basically append UseFeatureFlags with a new label after the application is running?
Two, if so, is there a built in way to check for changes in the configuration key and if so, append the UseFeatureFlags? I know right now, there's ConfigureRefresh that you can register a sentinel that refreshes the cache of feature flags. Is there something similar that I can attach some code to when the interval expires?
This looks to be continuing this discussion in this issue in the Microsoft/FeatureManagement-Dotnet repo.
In that discussion, the issue was brought up about the possible indeterministic behavior of selecting multiple labels without specifying ordering. I do hear you that it is blocking your scenario, but I would like to understand the scenario a bit better to make sure to come to the right solution.
My first question is, how is label being used here? I'm wondering if label is being used in such a way that including it as a key namespace would be a better option. In that case, a solution would already be present.
What I mean is that if you have data like the following
| key | (flag name) | value | label |
|---|---|---|---|
| .appconfig.featureflag/beta | beta | true | testapp |
| .appconfig.featureflag/alpha | alpha | false | otherapp |
It may be a solution to instead have
| key | (flag name) | value | label |
|---|---|---|---|
| .appconfig.featureflag/testapp/beta | testapp/beta | true | ( no label ) |
| .appconfig.featureflag/otherapp/alpha | otherapp/alpha | false | ( no label ) |
and watch all feature flags with no label.
It sort of is a continuation as it is dealing with the same API, but is a different question because of the indeterministic behavior of doing some sort of select all feature flags, I thought that a good deterministic workaround would be, as labels are added, we would UseFeatureFlag with the new label. Granted, we could just rebuild the application when a new label was added, then we just loop over the configuration key value the labels are stored in and chain UseFeatureFlag. But, we would like to not do that and instead periodically check the configuration key value, similarly to checking a sentinel, and if it changed, somehow add another UseFeatureFlag with that new label while the application ran. Any shared flag names would be overwritten by the latest added label. In our case, this would not be an issue as we have a UI sitting on top of the feature flags that has constraints to not allow duplicate flag names regardless of a differing label. We did not want any chance of feature flags overwriting each other.
In our system, we would use labels to scope features to applications. So, a given application would only need to listen to itself and any flag with the label "global".
This API is different as it is basically a middleman for our SPAs and our Azure feature flags. So, it needs to know about all of the flags. We decided to create it for two reasons, one, we did not want to expose even the readonly connection string to our Azure feature flags (probably too paranoid), and two (and more importantly), we wanted to take advantage of the built in caching and sentinels the you guys have supplied in your nuget packages.
Also, I don't know if you saw in the other discussion, but our feature flags are not merged into our configurations. So, I don't think utilizing the key namespace solution is an option.
Also, I don't know if you saw in the other discussion, but our feature flags are not merged into our configurations. So, I don't think utilizing the key namespace solution is an option.
I'm not quite sure what you mean here. The namespace solution seems more appealing to me the more I look at this situation. I don't get the blocker about merging flags with configuration.
@steven-rothwell please let us know when you have more to share. Closing for now.