-
Notifications
You must be signed in to change notification settings - Fork 2
Load From Azure Front Door #123
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
base: preview
Are you sure you want to change the base?
Load From Azure Front Door #123
Conversation
I reverted the original commit of adding loadFromCdn (#130) to unblock doing release for EXP telemetry changes.
This PR will contains all changes of the complete solution of loading from cdn. |
…avaScriptProvider into zhiyuanliang/enforce-api-version-for-cdn
…avaScriptProvider into zhiyuanliang/enforce-api-version-for-cdn
1eaa43e
to
62ac2b9
Compare
…avaScriptProvider into zhiyuanliang/register-all-refresh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new API (loadFromCdn) to support loading configuration key-values from a CDN while breaking the CDN cache by appending a query parameter based on etag changes. It also refactors internal selector management in AzureAppConfigurationImpl and adjusts related tests and exports to support the CDN scenario.
- Adds loadFromCdn API and its supporting pipeline policy and tests.
- Refactors selector collections in AzureAppConfigurationImpl to handle CDN-specific logic.
- Updates test helpers and exports to integrate and validate CDN behavior.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
test/utils/testHelper.ts | Updates function signature for load balance mode to pass pages instead of emptyPages. |
test/requestTracing.test.ts | Adds tests to verify the CDN tag in the correlation-context header. |
test/loadBalance.test.ts | Modifies load balance tests to use the updated API with mocked key-value pages. |
test/exportedApi.ts | Re-exports the new loadFromCdn API. |
src/requestTracing/utils.ts | Incorporates the new isCdnUsed flag and CDN tag into request tracing header creation. |
src/load.ts | Implements the loadFromCdn API and introduces an emptyTokenCredential for CDN requests. |
src/index.ts | Updates exported APIs to include loadFromCdn. |
src/common/utils.ts | Adds getCryptoModule for cross-environment crypto support. |
src/EtagUrlPipelinePolicy.ts | Creates a policy to append an etag query parameter for breaking the CDN cache. |
src/AzureAppConfigurationImpl.ts | Refactors selector management and integrates CDN handling into configuration loading. |
package.json | Bumps @azure/app-configuration dependency version. |
Comments suppressed due to low confidence (2)
src/AzureAppConfigurationImpl.ts:771
- [nitpick] Consider renaming the loop variable 'i' to 'pageIndex' or another more descriptive name to improve code readability.
let i = 0;
src/load.ts:52
- [nitpick] Update the function documentation to clearly explain the purpose of the additional boolean flag (indicating if the empty token credential was used) when calling AzureAppConfigurationImpl.
const appConfiguration = new AzureAppConfigurationImpl(clientManager, options, credentialOrOptions === emptyTokenCredential);
…avaScriptProvider into zhiyuanliang/enforce-api-version-for-cdn
4a2eebd
to
a30b421
Compare
…thub.com/Azure/AppConfiguration-JavaScriptProvider into zhiyuanliang/enforce-api-version-for-cdn
let listOptions: ListConfigurationSettingsOptions = { | ||
keyFilter: selector.keyFilter, | ||
labelFilter: selector.labelFilter | ||
}; | ||
|
||
// If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL | ||
if (this.#isCdnUsed && selectorCollection.cdnToken) { | ||
listOptions = { | ||
...listOptions, | ||
requestOptions: { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: selectorCollection.cdnToken }} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit- but you don't need to change it since you're following a common pattern.
I just don't like enforcing immutability like this because it makes a shallow copy and I think it makes the code uglier. listOptions is always new in this snippet and not exposed to any other code between construction and this mutation. But I bet a linter would still want to enforce full immutability.
Here's an alternative to avoid the shallow copy while still being immutable, but it's harder to read.
let listOptions: ListConfigurationSettingsOptions = { | |
keyFilter: selector.keyFilter, | |
labelFilter: selector.labelFilter | |
}; | |
// If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL | |
if (this.#isCdnUsed && selectorCollection.cdnToken) { | |
listOptions = { | |
...listOptions, | |
requestOptions: { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: selectorCollection.cdnToken }} | |
}; | |
} | |
let listOptions: ListConfigurationSettingsOptions = { | |
keyFilter: selector.keyFilter, | |
labelFilter: selector.labelFilter, | |
// If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL | |
...((this.#isCdnUsed && selectorCollection.cdnToken) && { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: selectorCollection.cdnToken }}) | |
}; |
or could just ignore "pure immutability" and do (my preference if the linter doesn't complain)
listOptions.requestOptions = { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: selectorCollection.cdnToken }};
// If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL | ||
listOptions = { | ||
...listOptions, | ||
requestOptions: { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: selectorCollection.cdnToken } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line/logic is repeated a lot. Maybe a helper that adds the option if passed a cdnToken would be better?
…avaScriptProvider into zhiyuanliang/enforce-api-version-for-cdn
Why this PR?
This feature is targeted on the CDN story.
This PR adds a new API
loadFromAzureFrontDoor
which allows user to load key values from the Azure Front Door. The Azure Front Door will forward the request to App Config and use managed identity for authentication.For CDN scenario, the recommended way for dynamic refresh is "watch all". We introduced key value collection monitoring based refresh in #133 .
The implementation is aligned with #601
Visible changes
No conditional request will be sent when CDN is used.
To break cdn cache, we will use a pipeline policy to append query param
_=<last-changed-etag>
to all the request sending to cdn.Example: