Skip to content

Commit 3f93172

Browse files
Merge pull request #163 from Azure/main
Merge main to release/v2
2 parents e3a5903 + b2f7727 commit 3f93172

File tree

12 files changed

+72
-41
lines changed

12 files changed

+72
-41
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.2",
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";
@@ -65,6 +66,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
6566
#isInitialLoadCompleted: boolean = false;
6667
#isFailoverRequest: boolean = false;
6768
#featureFlagTracing: FeatureFlagTracingOptions | undefined;
69+
#fmVersion: string | undefined;
6870

6971
// Refresh
7072
#refreshInProgress: boolean = false;
@@ -184,7 +186,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
184186
initialLoadCompleted: this.#isInitialLoadCompleted,
185187
replicaCount: this.#clientManager.getReplicaCount(),
186188
isFailoverRequest: this.#isFailoverRequest,
187-
featureFlagTracing: this.#featureFlagTracing
189+
featureFlagTracing: this.#featureFlagTracing,
190+
fmVersion: this.#fmVersion
188191
};
189192
}
190193

@@ -226,6 +229,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
226229
* Loads the configuration store for the first time.
227230
*/
228231
async load() {
232+
await this.#inspectFmPackage();
229233
await this.#loadSelectedAndWatchedKeyValues();
230234
if (this.#featureFlagEnabled) {
231235
await this.#loadFeatureFlags();
@@ -316,6 +320,21 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
316320
return new Disposable(remove);
317321
}
318322

323+
/**
324+
* Inspects the feature management package version.
325+
*/
326+
async #inspectFmPackage() {
327+
if (this.#requestTracingEnabled && !this.#fmVersion) {
328+
try {
329+
// get feature management package version
330+
const fmPackage = await import(FM_PACKAGE_NAME);
331+
this.#fmVersion = fmPackage?.VERSION;
332+
} catch (error) {
333+
// ignore the error
334+
}
335+
}
336+
}
337+
319338
async #refreshTasks(): Promise<void> {
320339
const refreshTasks: Promise<boolean>[] = [];
321340
if (this.#refreshEnabled) {
@@ -898,14 +917,13 @@ function getValidKeyValueSelectors(selectors?: SettingSelector[]): SettingSelect
898917

899918
function getValidFeatureFlagSelectors(selectors?: SettingSelector[]): SettingSelector[] {
900919
if (selectors === undefined || selectors.length === 0) {
901-
// selectors must be explicitly provided.
902-
throw new Error("Feature flag selectors must be provided.");
903-
} else {
904-
selectors.forEach(selector => {
905-
selector.keyFilter = `${featureFlagPrefix}${selector.keyFilter}`;
906-
});
907-
return getValidSelectors(selectors);
920+
// Default selector: key: *, label: \0
921+
return [{ keyFilter: `${featureFlagPrefix}${KeyFilter.Any}`, labelFilter: LabelFilter.Null }];
908922
}
923+
selectors.forEach(selector => {
924+
selector.keyFilter = `${featureFlagPrefix}${selector.keyFilter}`;
925+
});
926+
return getValidSelectors(selectors);
909927
}
910928

911929
function isFailoverableError(error: any): boolean {

src/ConfigurationClientManager.ts

Lines changed: 4 additions & 1 deletion
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;

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
@@ -55,6 +55,10 @@ export const FAILOVER_REQUEST_TAG = "Failover";
5555
export const FEATURES_KEY = "Features";
5656
export const LOAD_BALANCE_CONFIGURED_TAG = "LB";
5757

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

src/requestTracing/utils.ts

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

3334
export interface RequestTracingOptions {
@@ -37,6 +38,7 @@ export interface RequestTracingOptions {
3738
replicaCount: number;
3839
isFailoverRequest: boolean;
3940
featureFlagTracing: FeatureFlagTracingOptions | undefined;
41+
fmVersion: string | undefined;
4042
}
4143

4244
// Utils
@@ -119,6 +121,9 @@ export function createCorrelationContextHeader(requestTracingOptions: RequestTra
119121
if (requestTracingOptions.replicaCount > 0) {
120122
keyValues.set(REPLICA_COUNT_KEY, requestTracingOptions.replicaCount.toString());
121123
}
124+
if (requestTracingOptions.fmVersion) {
125+
keyValues.set(FM_VERSION_KEY, requestTracingOptions.fmVersion);
126+
}
122127

123128
// Compact tags: Features=LB+...
124129
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.2";
4+
export const VERSION = "2.0.0";

0 commit comments

Comments
 (0)