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

Duplicate Keys with different Labels #43

Closed
kamalsivalingam opened this issue Mar 10, 2019 · 2 comments
Closed

Duplicate Keys with different Labels #43

kamalsivalingam opened this issue Mar 10, 2019 · 2 comments
Assignees
Labels
more info Further information is requested

Comments

@kamalsivalingam
Copy link

kamalsivalingam commented Mar 10, 2019

If I add two entries with the same Key but different value and Label, I am not able to access these duplicate Keys from the .Net Core App/Azure Function.

What is the use of Label? Is this similar to Version?
If that is the case, still shouldn't all the Keys with different values still be accessible?

@zhenlan
Copy link
Contributor

zhenlan commented Mar 10, 2019

Thanks for trying this out @kamalsivalingam.

By default, the config provider of the App Configuration will load keys with no labels for simplicity. When labels are used, they can be loaded with the Use function. The example below loads all keys with the label mylabel.

configBuilder.AddAzureAppConfiguration(options =>
{
    options.Connect(configuration["connection_string"])
           .Use(KeyFilter.Any, "mylabel")
});

Labels provide an extra dimension to key-values, so each key can have multiple values at the same time. It can be used to differentiate config for different environments (dev, test, ...), different microservices (app1, app2, ...), different regions and so on so forth. We also expect it will be a very typical use of labels for versioning. For example, I have config labeled with v1 and v2. In my app, I want the v2 config overwrites the v1 config when they have the same key. Then I will have something like this

configBuilder.AddAzureAppConfiguration(options =>
{
    options.Connect(configuration["connection_string"])
           .Use(KeyFilter.Any, "v1")
           .Use(KeyFilter.Any, "v2")
});

Please check out the AzureAppConfigurationOptions class, which provides APIs for filtering key-values, watching for changes, connecting with managed identity and so on.

Hope this helps. Please let me know if you have any other questions.

@zhenlan zhenlan added the more info Further information is requested label Mar 10, 2019
@zhenlan zhenlan self-assigned this Mar 11, 2019
@zhenlan zhenlan closed this as completed Apr 1, 2019
@sabbadino
Copy link

I've added 2 keys with same name (poc-api:myvalue), one with label "Development", the other with no label.

With this code :

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((hostingContext, config) =>
            {
                var settings = config.Build();
                config.AddAzureAppConfiguration(options =>
                {
                    options.Connect(settings["ConnectionStrings:AppConfiguration"])
                        .Use(KeyFilter.Any, LabelFilter.Null)
                        .Use(KeyFilter.Any, "Development")
                        .UseFeatureFlags(optionsff =>
                        {
                            optionsff.PollInterval = new TimeSpan(0, 0, 5);
                        }); 
                    options.Watch("poc-api:myvalue",new TimeSpan(0,0,5));
                    
                }); ;
            })
            .UseStartup<Startup>();

It seems I cannot get the value for the key with label "Development", i always get the one without the label

using

<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="1.0.0-preview-008920001-990" />

Code "Inspired" by
https://docs.microsoft.com/en-us/azure/azure-app-configuration/howto-best-practices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants