Azure/AppConfiguration-DotnetProvider

Unexpected behavior using refresh with wildcard

Closed this issue · 5 comments

I've seen no documentation on whether this can't be done

builder.AddAzureAppConfiguration(options =>
{
    options.Connect(connectionString)
        .Select("TestKey*")
        .ConfigureRefresh(refresh =>
        {
            refresh.Register("TestKey*");
        });
});

Reproduce

Copy example
Change code

.ConfigureRefresh(refresh =>
{
    refresh.Register("TestApp:Settings*")
           .SetCacheExpiration(TimeSpan.FromSeconds(10));
});

The refresh will not trigger any changes and no error is thrown

Expected

Either an actual error saying that the refresh configuration is invalid or the correct refresh of all the group keys.

Actual

Nothing. No changes are triggered. It looks as if an exception is actually thrown.

Service request failed.
Status: 404 (Not Found)

Headers:
Server: openresty/1.21.4.1
Date: Sat, 28 Jan 2023 18:30:58 GMT
Connection: keep-alive
Sync-Token: zAJw6V16=OToxOSM0MDkwMzQ1;sn=4090345
x-ms-request-id: b3aca001-5864-4709-a2bd-eb076d59ea38
x-ms-client-request-id: 239589d3-ba95-49e1-9d43-e36d72d72b47
x-ms-correlation-request-id: b3aca001-5864-4709-a2bd-eb076d59ea38
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: REDACTED
Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 0

I observed this error in the debugger when forcing a second call to the refresher

await _refresher.TryRefreshAsync();

You can register an individual key to monitor for changes, not a group of keys.

When you call refresh. Register("TestKey*"), it monitors a key with the exact name "TestKey*" instead of "keys starting with 'TestKey'". You got a 404 response because that key doesn't exist in your App Configuration store.

API reference doc:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.azureappconfiguration.azureappconfigurationrefreshoptions.register?view=azure-dotnet

Yes, I linked to the example with the key sentinel for refresh.

As you say, the refresh can't be done with groups but that is not said anywhere. Maybe it should be added on the docs, or enforced through code. I guess it should be a rather simple change: validatidate the refresh key so it does not contain the "any" character.

Could the validation be added so no one else fails on this?

A clarification in doc could be helpful. TestKey* is a valid key, so failing that could be a breaking change for somebody.

Sorry for the late response. Yes a clarification in the docs would be enough.

Thank you

@amerjusupovic, can we update the intellisense of the Register API to clarify that it accepts a single key-value and it cannot be a filtering of a collection of key-values?