Skip to content

Commit b5f26c4

Browse files
update
1 parent ca056b9 commit b5f26c4

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/afd/constants.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 SERVER_TIMESTAMP_HEADER = "x-ms-date";
4+
export const X_MS_DATE_HEADER = "x-ms-date";

src/appConfigurationImpl.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { ConfigurationClientManager } from "./configurationClientManager.js";
6868
import { getFixedBackoffDuration, getExponentialBackoffDuration } from "./common/backoffUtils.js";
6969
import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError } from "./common/errors.js";
7070
import { ErrorMessages } from "./common/errorMessages.js";
71-
import { SERVER_TIMESTAMP_HEADER } from "./afd/constants.js";
71+
import { X_MS_DATE_HEADER } from "./afd/constants.js";
7272

7373
const MIN_DELAY_FOR_UNHANDLED_FAILURE = 5_000; // 5 seconds
7474

@@ -745,13 +745,16 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
745745

746746
let i = 0;
747747
for await (const page of pageIterator) {
748-
const timestamp = this.#getResponseTimestamp(page);
748+
const serverResponseTime = this.#getMsDateHeader(page);
749749
if (i >= pageWatchers.length) {
750750
return true;
751751
}
752752

753753
const lastServerResponseTime = pageWatchers[i].lastServerResponseTime;
754-
const isUpToDate = lastServerResponseTime ? timestamp > lastServerResponseTime : true;
754+
let isUpToDate = true;
755+
if (lastServerResponseTime !== undefined && serverResponseTime !== undefined) {
756+
isUpToDate = serverResponseTime > lastServerResponseTime;
757+
}
755758
if (isUpToDate && page._response.status === 200 && page.etag !== pageWatchers[i].etag) {
756759
return true;
757760
}
@@ -802,7 +805,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
802805

803806
const items: ConfigurationSetting[] = [];
804807
for await (const page of pageIterator) {
805-
pageWatchers.push({ etag: page.etag, lastServerResponseTime: this.#getResponseTimestamp(page) });
808+
pageWatchers.push({ etag: page.etag, lastServerResponseTime: this.#getMsDateHeader(page) });
806809
items.push(...page.items);
807810
}
808811
return { items, pageWatchers };
@@ -1132,16 +1135,22 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
11321135
}
11331136

11341137
/**
1135-
* Extracts the response timestamp from the headers. If not found, returns the current time.
1138+
* Extracts the response timestamp (x-ms-date) from the response headers. If not found, returns the current time.
11361139
*/
1137-
#getResponseTimestamp(response: GetConfigurationSettingResponse | ListConfigurationSettingPage | RestError): Date {
1140+
#getMsDateHeader(response: GetConfigurationSettingResponse | ListConfigurationSettingPage | RestError): Date {
11381141
let header: string | undefined;
11391142
if (isRestError(response)) {
1140-
header = response.response?.headers?.get(SERVER_TIMESTAMP_HEADER) ?? undefined;
1143+
header = response.response?.headers?.get(X_MS_DATE_HEADER);
11411144
} else {
1142-
header = response._response?.headers?.get(SERVER_TIMESTAMP_HEADER) ?? undefined;
1145+
header = response._response?.headers?.get(X_MS_DATE_HEADER);
1146+
}
1147+
if (header !== undefined) {
1148+
const date = new Date(header);
1149+
if (!isNaN(date.getTime())) {
1150+
return date;
1151+
}
11431152
}
1144-
return header ? new Date(header) : new Date();
1153+
return new Date();
11451154
}
11461155
}
11471156

src/requestTracing/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ function createCorrelationContextHeader(requestTracingOptions: RequestTracingOpt
117117
Host: identify with defined envs
118118
Env: identify by env `NODE_ENV` which is a popular but not standard. Usually, the value can be "development", "production".
119119
ReplicaCount: identify how many replicas are found
120-
Features: LB
120+
Features: LB+AI+AICC+AFD
121121
Filter: CSTM+TIME+TRGT
122122
MaxVariants: identify the max number of variants feature flag uses
123123
FFFeatures: Seed+Telemetry
124124
UsersKeyVault
125125
Failover
126-
AFD
127126
*/
128127
const keyValues = new Map<string, string | undefined>();
129128
const tags: string[] = [];
@@ -155,9 +154,6 @@ function createCorrelationContextHeader(requestTracingOptions: RequestTracingOpt
155154
if (requestTracingOptions.isFailoverRequest) {
156155
tags.push(FAILOVER_REQUEST_TAG);
157156
}
158-
if (requestTracingOptions.isAfdUsed) {
159-
tags.push(AFD_USED_TAG);
160-
}
161157
if (requestTracingOptions.replicaCount > 0) {
162158
keyValues.set(REPLICA_COUNT_KEY, requestTracingOptions.replicaCount.toString());
163159
}
@@ -189,7 +185,8 @@ export function requestTracingEnabled(): boolean {
189185

190186
function usesAnyTracingFeature(requestTracingOptions: RequestTracingOptions): boolean {
191187
return (requestTracingOptions.appConfigOptions?.loadBalancingEnabled ?? false) ||
192-
(requestTracingOptions.aiConfigurationTracing?.usesAnyTracingFeature() ?? false);
188+
(requestTracingOptions.aiConfigurationTracing?.usesAnyTracingFeature() ?? false) ||
189+
requestTracingOptions.isAfdUsed;
193190
}
194191

195192
function createFeaturesString(requestTracingOptions: RequestTracingOptions): string {
@@ -203,6 +200,9 @@ function createFeaturesString(requestTracingOptions: RequestTracingOptions): str
203200
if (requestTracingOptions.aiConfigurationTracing?.usesAIChatCompletionConfiguration) {
204201
tags.push(AI_CHAT_COMPLETION_CONFIGURATION_TAG);
205202
}
203+
if (requestTracingOptions.isAfdUsed) {
204+
tags.push(AFD_USED_TAG);
205+
}
206206
return tags.join(DELIMITER);
207207
}
208208

test/afd.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { AppConfigurationClient } from "@azure/app-configuration";
1111
import { load, loadFromAzureFrontDoor } from "../src/index.js";
1212
import { ErrorMessages } from "../src/common/errorMessages.js";
1313
import { createMockedKeyValue, createMockedFeatureFlag, HttpRequestHeadersPolicy, getCachedIterator, sinon, restoreMocks, createMockedConnectionString, createMockedAzureFrontDoorEndpoint, sleepInMs } from "./utils/testHelper.js";
14-
import { SERVER_TIMESTAMP_HEADER } from "../src/afd/constants.js";
14+
import { X_MS_DATE_HEADER } from "../src/afd/constants.js";
1515
import { isBrowser } from "../src/requestTracing/utils.js";
1616

1717
function createTimestampHeaders(timestamp: string | Date) {
1818
const value = timestamp instanceof Date ? timestamp.toUTCString() : new Date(timestamp).toUTCString();
1919
return {
20-
get: (name: string) => name.toLowerCase() === SERVER_TIMESTAMP_HEADER ? value : undefined
20+
get: (name: string) => name.toLowerCase() === X_MS_DATE_HEADER ? value : undefined
2121
};
2222
}
2323

0 commit comments

Comments
 (0)