Skip to content

Commit aa037e5

Browse files
update
1 parent 56f6265 commit aa037e5

File tree

6 files changed

+19
-26
lines changed

6 files changed

+19
-26
lines changed

src/AzureAppConfigurationImpl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import { FeatureFlagTracingOptions } from "./requestTracing/FeatureFlagTracingOp
3434
import { AIConfigurationTracingOptions } from "./requestTracing/AIConfigurationTracingOptions.js";
3535
import { KeyFilter, LabelFilter, SettingSelector } from "./types.js";
3636
import { ConfigurationClientManager } from "./ConfigurationClientManager.js";
37-
import { getFixedBackoffDuration, calculateBackoffDuration } from "./backoffDuration.js";
38-
import { InvalidOperationError, ArgumentError, isFailoverableError, isRetriableError, isArgumentError } from "./error.js";
37+
import { getFixedBackoffDuration, getExponentialBackoffDuration } from "./common/backoffUtils.js";
38+
import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError } from "./error.js";
3939

4040
const MIN_DELAY_FOR_UNHANDLED_FAILURE = 5_000; // 5 seconds
4141

@@ -251,7 +251,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
251251
})
252252
]);
253253
} catch (error) {
254-
if (!isArgumentError(error)) {
254+
if (!isInputError(error)) {
255255
const timeElapsed = Date.now() - startTimestamp;
256256
if (timeElapsed < MIN_DELAY_FOR_UNHANDLED_FAILURE) {
257257
// load() method is called in the application's startup code path.
@@ -365,7 +365,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
365365
this.#isInitialLoadCompleted = true;
366366
break;
367367
} catch (error) {
368-
if (!isRetriableError(error)) {
368+
if (isInputError(error)) {
369369
throw error;
370370
}
371371
if (abortSignal.aborted) {
@@ -375,7 +375,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
375375
let backoffDuration = getFixedBackoffDuration(timeElapsed);
376376
if (backoffDuration === undefined) {
377377
postAttempts += 1;
378-
backoffDuration = calculateBackoffDuration(postAttempts);
378+
backoffDuration = getExponentialBackoffDuration(postAttempts);
379379
}
380380
console.warn(`Failed to load. Error message: ${error.message}. Retrying in ${backoffDuration} ms.`);
381381
await new Promise(resolve => setTimeout(resolve, backoffDuration));

src/ConfigurationClientWrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import { AppConfigurationClient } from "@azure/app-configuration";
5-
import { calculateBackoffDuration } from "./backoffDuration.js";
5+
import { getExponentialBackoffDuration } from "./common/backoffUtils.js";
66

77
export class ConfigurationClientWrapper {
88
endpoint: string;
@@ -21,7 +21,7 @@ export class ConfigurationClientWrapper {
2121
this.backoffEndTime = Date.now();
2222
} else {
2323
this.#failedAttempts += 1;
24-
this.backoffEndTime = Date.now() + calculateBackoffDuration(this.#failedAttempts);
24+
this.backoffEndTime = Date.now() + getExponentialBackoffDuration(this.#failedAttempts);
2525
}
2626
}
2727
}

src/backoffDuration.ts renamed to src/common/backoffUtils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ const MIN_BACKOFF_DURATION = 30_000; // 30 seconds in milliseconds
55
const MAX_BACKOFF_DURATION = 10 * 60 * 1000; // 10 minutes in milliseconds
66
const JITTER_RATIO = 0.25;
77

8-
export function getFixedBackoffDuration(timeElapsed: number): number | undefined {
9-
if (timeElapsed < 100_000) { // 100 seconds in milliseconds
10-
return 5_000; // 5 seconds in milliseconds
8+
export function getFixedBackoffDuration(timeElapsedInMs: number): number | undefined {
9+
if (timeElapsedInMs < 100_000) {
10+
return 5_000;
1111
}
12-
if (timeElapsed < 200_000) { // 200 seconds in milliseconds
13-
return 10_000; // 10 seconds in milliseconds
12+
if (timeElapsedInMs < 200_000) {
13+
return 10_000;
1414
}
15-
if (timeElapsed < 10 * 60 * 1000) { // 10 minutes in milliseconds
15+
if (timeElapsedInMs < 10 * 60 * 1000) {
1616
return MIN_BACKOFF_DURATION;
1717
}
1818
return undefined;
1919
}
2020

21-
export function calculateBackoffDuration(failedAttempts: number) {
21+
export function getExponentialBackoffDuration(failedAttempts: number): number {
2222
if (failedAttempts <= 1) {
2323
return MIN_BACKOFF_DURATION;
2424
}

src/error.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class InvalidOperationError extends Error {
1414
}
1515

1616
/**
17-
* Error thrown when an argument or configuration is invalid.
17+
* Error thrown when an input argument is invalid.
1818
*/
1919
export class ArgumentError extends Error {
2020
constructor(message: string) {
@@ -24,7 +24,7 @@ export class ArgumentError extends Error {
2424
}
2525

2626
/**
27-
* Error thrown when it fails to get the secret from the Key Vault.
27+
* Error thrown when a Key Vault reference cannot be resolved.
2828
*/
2929
export class KeyVaultReferenceError extends Error {
3030
constructor(message: string) {
@@ -50,17 +50,10 @@ export function isFailoverableError(error: any): boolean {
5050
return false;
5151
}
5252

53-
export function isRetriableError(error: any): boolean {
54-
if (isArgumentError(error)) {
55-
return false;
56-
}
57-
return true;
58-
}
59-
6053
/**
6154
* Check if the error is an instance of ArgumentError, TypeError, or RangeError.
6255
*/
63-
export function isArgumentError(error: any): boolean {
56+
export function isInputError(error: any): boolean {
6457
if (error instanceof ArgumentError ||
6558
error instanceof TypeError ||
6659
error instanceof RangeError) {

src/keyvault/AzureKeyVaultKeyValueAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class AzureKeyVaultKeyValueAdapter implements IKeyValueAdapter {
2525
async processKeyValue(setting: ConfigurationSetting): Promise<[string, unknown]> {
2626
// TODO: cache results to save requests.
2727
if (!this.#keyVaultOptions) {
28-
throw new ArgumentError("Failed to process the key vault reference. The keyVaultOptions is not configured.");
28+
throw new ArgumentError("Failed to process the Key Vault reference because Key Vault options are not configured.");
2929
}
3030

3131
const { name: secretName, vaultUrl, sourceId, version } = parseKeyVaultSecretIdentifier(

test/keyvault.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe("key vault reference", function () {
4040
});
4141

4242
it("require key vault options to resolve reference", async () => {
43-
return expect(load(createMockedConnectionString())).eventually.rejectedWith("Failed to process the key vault reference. The keyVaultOptions is not configured.");
43+
return expect(load(createMockedConnectionString())).eventually.rejectedWith("Failed to process the Key Vault reference because Key Vault options are not configured.");
4444
});
4545

4646
it("should resolve key vault reference with credential", async () => {

0 commit comments

Comments
 (0)