-
Notifications
You must be signed in to change notification settings - Fork 2
Support dynamic refresh #21
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
Merged
Merged
Changes from 38 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
c8ab1c9
Support dynamic refresh
Eskibear b282211
etag-based refresh
Eskibear 32ebd48
Merge remote-tracking branch 'origin/main' into dynamic-refresh
Eskibear 8ba1252
rewrite refresh.test with TS
Eskibear 261e72f
add refreshOptions.enabled
Eskibear 7ccf26f
prepend _ to private members for clarity
Eskibear d3a6279
Merge remote-tracking branch 'origin/main' into dynamic-refresh
Eskibear 6522085
Update mocked func for app-configuration v1.5.0
Eskibear 47e5c34
remove workaround for null label
Eskibear 7b8c9b9
also trace requests for refresh
Eskibear 1b64fb7
add more test cases for unexpected refreshOptions
Eskibear 061fadf
Merge branch 'main' into dynamic-refresh
Eskibear 179ce3e
revert renaming private fields with _ prefix
Eskibear 841baa1
Merge branch 'main' into dynamic-refresh
Eskibear 03d53b9
add backoff timer
Eskibear dc8b087
Merge branch 'main' into dynamic-refresh
Eskibear 431e91e
backoff when error occurs during refresh
Eskibear af9ea33
update comment docs
Eskibear 677eaa0
fix backoff end time on reset
Eskibear 8e1c1a4
make backoff time calc clearer
Eskibear 1da9647
Block wildcard chars in watched settings
Eskibear 13e06a5
Apply wording suggestions
Eskibear e72887a
Remove LinkedList and update onRefreshListeners to use an array
Eskibear 7514768
Merge remote-tracking branch 'origin/main' into dynamic-refresh
Eskibear 2b867e9
fix error message in test case
Eskibear 46cf7b9
adopt private properties
Eskibear 5b3ab06
Refactor refresh timer method name
Eskibear 18bbd4e
explain refresh scenario in example comments
Eskibear 9f32ceb
Merge remote-tracking branch 'origin/main' into dynamic-refresh
Eskibear 8e1a2ab
Add timeout to dynamic refresh test
Eskibear 0e347be
Fix refresh timer logic in AzureAppConfigurationImpl.ts
Eskibear 46be338
support refresh on watched setting deletion
Eskibear c8c8d8e
Remove unused variable
Eskibear 7663a27
export type Disposable
Eskibear ead82d0
add detailed description for refresh timer
Eskibear e0c9736
Refactor RefreshTimer class to use efficient power of two calculation
Eskibear 0486c10
rename variable name for clarity
Eskibear fe3614f
remove redundant code
Eskibear 1099ec7
Merge branch 'main' into dynamic-refresh
Eskibear 98b12e2
limit max exponential to 30 and remove utils no longer needed
Eskibear 506c8a6
throw error on refresh when refresh is not enabled
Eskibear 5d80ccc
load watched settings if not coverred by selectors
Eskibear e311ce9
add comments for the Map key trick
Eskibear e3ed82f
deduce type from state isInitialLoadCompleted
Eskibear d838076
revert unnecessary whitespace change
Eskibear e03036d
simplify request tracing header utils
Eskibear 97e0350
Exclude watched settings from configuration
Eskibear d0440dc
Change sentinels to array type to ensure correctness
Eskibear 4bc37e1
remove unnecessary check, as key is non-null
Eskibear 8acf87b
Do not refresh when watched setting remains not loaded
Eskibear fd60862
simplify nested if blocks
Eskibear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import * as dotenv from "dotenv"; | ||
import { promisify } from "util"; | ||
dotenv.config(); | ||
const sleepInMs = promisify(setTimeout); | ||
|
||
/** | ||
* This example retrives all settings with key following pattern "app.settings.*", i.e. starting with "app.settings.". | ||
* With the option `trimKeyPrefixes`, it trims the prefix "app.settings." from keys for simplicity. | ||
* Value of config "app.settings.message" will be printed. | ||
* It also watches for changes to the key "app.settings.sentinel" and refreshes the configuration when it changes. | ||
* | ||
avanigupta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Below environment variables are required for this example: | ||
* - APPCONFIG_CONNECTION_STRING | ||
*/ | ||
|
||
import { load } from "@azure/app-configuration-provider"; | ||
const connectionString = process.env.APPCONFIG_CONNECTION_STRING; | ||
const settings = await load(connectionString, { | ||
selectors: [{ | ||
keyFilter: "app.settings.*" | ||
}], | ||
trimKeyPrefixes: ["app.settings."], | ||
refreshOptions: { | ||
watchedSettings: [{ key: "app.settings.sentinel" }], | ||
refreshIntervalInMs: 10 * 1000 // Default value is 30 seconds, shorted for this sample | ||
} | ||
}); | ||
|
||
console.log("Using Azure portal or CLI, update the `app.settings.message` value, and then update the `app.settings.sentinel` value in your App Configuration store.") | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
// Refreshing the configuration setting | ||
await settings.refresh(); | ||
|
||
// Current value of message | ||
console.log(settings.get("message")); | ||
|
||
// Waiting before the next refresh | ||
await sleepInMs(5000); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { Disposable } from "./common/disposable"; | ||
|
||
export type AzureAppConfiguration = { | ||
// methods for advanced features, e.g. refresh() | ||
/** | ||
* API to trigger refresh operation. | ||
*/ | ||
refresh(): Promise<void>; | ||
|
||
/** | ||
* API to register callback listeners, which will be called only when a refresh operation successfully updates key-values. | ||
* | ||
* @param listener - Callback funtion to be registered. | ||
* @param thisArg - Optional. Value to use as `this` when executing callback. | ||
*/ | ||
onRefresh(listener: () => any, thisArg?: any): Disposable; | ||
} & ReadonlyMap<string, any>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { WatchedSetting } from "./WatchedSetting"; | ||
|
||
export const DefaultRefreshIntervalInMs = 30 * 1000; | ||
export const MinimumRefreshIntervalInMs = 1 * 1000; | ||
|
||
export interface RefreshOptions { | ||
/** | ||
* Specifies whether the provider should automatically refresh when the configuration is changed. | ||
*/ | ||
enabled: boolean; | ||
avanigupta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Specifies the minimum time that must elapse before checking the server for any new changes. | ||
* Default value is 30 seconds. Must be greater than 1 second. | ||
* Any refresh operation triggered will not update the value for a key until after the interval. | ||
*/ | ||
refreshIntervalInMs?: number; | ||
Eskibear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* One or more configuration settings to be watched for changes on the server. | ||
* Any modifications to watched settings will refresh all settings loaded by the configuration provider. | ||
*/ | ||
watchedSettings?: WatchedSetting[]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
/** | ||
* Fields that uniquely identify a watched configuration setting. | ||
*/ | ||
export interface WatchedSetting { | ||
/** | ||
* The key for this setting. | ||
*/ | ||
key: string; | ||
|
||
/** | ||
* The label for this setting. | ||
* Leaving this undefined means this setting does not have a label. | ||
*/ | ||
label?: string; | ||
Eskibear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export class Disposable { | ||
Eskibear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private disposed = false; | ||
constructor(private callOnDispose: () => any) { } | ||
|
||
dispose() { | ||
if (!this.disposed) { | ||
this.callOnDispose(); | ||
} | ||
this.disposed = true; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.