Skip to content

Commit 33a5964

Browse files
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-JavaScriptProvider into zhiyuanliang/enforce-api-version-for-cdn
2 parents 6fe042a + 92d6531 commit 33a5964

File tree

12 files changed

+76
-42
lines changed

12 files changed

+76
-42
lines changed

.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
"@typescript-eslint"
3434
],
3535
"rules": {
36+
"keyword-spacing": [
37+
"error",
38+
{
39+
"before": true,
40+
"after": true
41+
}
42+
],
3643
"quotes": [
3744
"error",
3845
"double",

package-lock.json

Lines changed: 4 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/app-configuration-provider",
3-
"version": "2.0.0-preview.1",
3+
"version": "2.0.0",
44
"description": "The JavaScript configuration provider for Azure App Configuration",
55
"main": "dist/index.js",
66
"module": "./dist-esm/index.js",

rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dts from "rollup-plugin-dts";
44

55
export default [
66
{
7-
external: ["@azure/app-configuration", "@azure/keyvault-secrets", "@azure/core-rest-pipeline", "crypto", "dns/promises"],
7+
external: ["@azure/app-configuration", "@azure/keyvault-secrets", "@azure/core-rest-pipeline", "crypto", "dns/promises", "@microsoft/feature-management"],
88
input: "src/index.ts",
99
output: [
1010
{

src/AzureAppConfigurationImpl.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
CONDITIONS_KEY_NAME,
3434
CLIENT_FILTERS_KEY_NAME
3535
} from "./featureManagement/constants.js";
36+
import { FM_PACKAGE_NAME } from "./requestTracing/constants.js";
3637
import { AzureKeyVaultKeyValueAdapter } from "./keyvault/AzureKeyVaultKeyValueAdapter.js";
3738
import { RefreshTimer } from "./refresh/RefreshTimer.js";
3839
import { RequestTracingOptions, getConfigurationSettingWithTrace, listConfigurationSettingsWithTrace, requestTracingEnabled } from "./requestTracing/utils.js";
@@ -73,6 +74,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
7374
#isInitialLoadCompleted: boolean = false;
7475
#isFailoverRequest: boolean = false;
7576
#featureFlagTracing: FeatureFlagTracingOptions | undefined;
77+
#fmVersion: string | undefined;
7678

7779
// Refresh
7880
#refreshInProgress: boolean = false;
@@ -198,7 +200,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
198200
replicaCount: this.#clientManager.getReplicaCount(),
199201
isFailoverRequest: this.#isFailoverRequest,
200202
isCdnUsed: this.#isCdnUsed,
201-
featureFlagTracing: this.#featureFlagTracing
203+
featureFlagTracing: this.#featureFlagTracing,
204+
fmVersion: this.#fmVersion
202205
};
203206
}
204207

@@ -241,6 +244,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
241244
* @internal
242245
*/
243246
async load() {
247+
await this.#inspectFmPackage();
244248
await this.#loadSelectedAndWatchedKeyValues();
245249

246250
if (this.#featureFlagEnabled) {
@@ -357,6 +361,21 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
357361
return new Disposable(remove);
358362
}
359363

364+
/**
365+
* Inspects the feature management package version.
366+
*/
367+
async #inspectFmPackage() {
368+
if (this.#requestTracingEnabled && !this.#fmVersion) {
369+
try {
370+
// get feature management package version
371+
const fmPackage = await import(FM_PACKAGE_NAME);
372+
this.#fmVersion = fmPackage?.VERSION;
373+
} catch (error) {
374+
// ignore the error
375+
}
376+
}
377+
}
378+
360379
async #refreshTasks(): Promise<void> {
361380
const refreshTasks: Promise<boolean>[] = [];
362381
if (this.#refreshEnabled) {
@@ -975,14 +994,13 @@ function getValidKeyValueSelectors(selectors?: SettingSelector[]): SettingSelect
975994

976995
function getValidFeatureFlagSelectors(selectors?: SettingSelector[]): SettingSelector[] {
977996
if (selectors === undefined || selectors.length === 0) {
978-
// selectors must be explicitly provided.
979-
throw new Error("Feature flag selectors must be provided.");
980-
} else {
981-
selectors.forEach(selector => {
982-
selector.keyFilter = `${featureFlagPrefix}${selector.keyFilter}`;
983-
});
984-
return getValidSelectors(selectors);
997+
// Default selector: key: *, label: \0
998+
return [{ keyFilter: `${featureFlagPrefix}${KeyFilter.Any}`, labelFilter: LabelFilter.Null }];
985999
}
1000+
selectors.forEach(selector => {
1001+
selector.keyFilter = `${featureFlagPrefix}${selector.keyFilter}`;
1002+
});
1003+
return getValidSelectors(selectors);
9861004
}
9871005

9881006
function isFailoverableError(error: any): boolean {

src/ConfigurationClientManager.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ export class ConfigurationClientManager {
8585
this.#isFailoverable = false;
8686
return;
8787
}
88+
if (this.#dns) {
89+
return;
90+
}
8891

8992
try {
9093
this.#dns = await import("dns/promises");
91-
}catch (error) {
94+
} catch (error) {
9295
this.#isFailoverable = false;
9396
console.warn("Failed to load the dns module:", error.message);
9497
return;
@@ -140,13 +143,16 @@ export class ConfigurationClientManager {
140143

141144
async #discoverFallbackClients(host: string) {
142145
let result;
146+
let timeout;
143147
try {
144148
result = await Promise.race([
145-
new Promise((_, reject) => setTimeout(() => reject(new Error("SRV record query timed out.")), SRV_QUERY_TIMEOUT)),
149+
new Promise((_, reject) => timeout = setTimeout(() => reject(new Error("SRV record query timed out.")), SRV_QUERY_TIMEOUT)),
146150
this.#querySrvTargetHost(host)
147151
]);
148152
} catch (error) {
149153
throw new Error(`Failed to build fallback clients, ${error.message}`);
154+
} finally {
155+
clearTimeout(timeout);
150156
}
151157

152158
const srvTargetHosts = shuffleList(result) as string[];

src/featureManagement/FeatureFlagOptions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ import { SettingSelector } from "../types.js";
1010
export interface FeatureFlagOptions {
1111
/**
1212
* Specifies whether feature flags will be loaded from Azure App Configuration.
13-
1413
*/
1514
enabled: boolean;
1615

1716
/**
18-
* Specifies the selectors used to filter feature flags.
17+
* Specifies what feature flags to include in the configuration provider.
1918
*
2019
* @remarks
2120
* keyFilter of selector will be prefixed with "appconfig.featureflag/" when request is sent.
22-
* If no selectors are specified then no feature flags will be retrieved.
21+
* If no selectors are specified then all feature flags with no label will be included.
2322
*/
2423
selectors?: SettingSelector[];
2524

src/requestTracing/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export const FAILOVER_REQUEST_TAG = "Failover";
5656
export const FEATURES_KEY = "Features";
5757
export const LOAD_BALANCE_CONFIGURED_TAG = "LB";
5858

59+
// Feature management package
60+
export const FM_PACKAGE_NAME = "@microsoft/feature-management";
61+
export const FM_VERSION_KEY = "FMJsVer";
62+
5963
// Feature flag usage tracing
6064
export const FEATURE_FILTER_TYPE_KEY = "Filter";
6165
export const CUSTOM_FILTER_KEY = "CSTM";

src/requestTracing/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
REPLICA_COUNT_KEY,
2929
FAILOVER_REQUEST_TAG,
3030
FEATURES_KEY,
31-
LOAD_BALANCE_CONFIGURED_TAG
31+
LOAD_BALANCE_CONFIGURED_TAG,
32+
FM_VERSION_KEY
3233
} from "./constants";
3334

3435
export interface RequestTracingOptions {
@@ -39,6 +40,7 @@ export interface RequestTracingOptions {
3940
isFailoverRequest: boolean;
4041
isCdnUsed: boolean;
4142
featureFlagTracing: FeatureFlagTracingOptions | undefined;
43+
fmVersion: string | undefined;
4244
}
4345

4446
// Utils
@@ -127,6 +129,9 @@ export function createCorrelationContextHeader(requestTracingOptions: RequestTra
127129
if (requestTracingOptions.replicaCount > 0) {
128130
keyValues.set(REPLICA_COUNT_KEY, requestTracingOptions.replicaCount.toString());
129131
}
132+
if (requestTracingOptions.fmVersion) {
133+
keyValues.set(FM_VERSION_KEY, requestTracingOptions.fmVersion);
134+
}
130135

131136
// Compact tags: Features=LB+...
132137
if (appConfigOptions?.loadBalancingEnabled) {

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
export const VERSION = "2.0.0-preview.1";
4+
export const VERSION = "2.0.0";

0 commit comments

Comments
 (0)