From fa99c54efc8db09cb28a0360b2e8d611888fe434 Mon Sep 17 00:00:00 2001 From: "Craig Boger (from Dev Box)" Date: Mon, 3 Mar 2025 16:28:22 -0800 Subject: [PATCH] Cleaning up logging and fixing endpoint discovery bug. --- src/Common/CosmosClient.ts | 40 +------------------------ src/Common/ErrorHandlingUtils.ts | 2 -- src/Common/dataAccess/updateDocument.ts | 4 --- 3 files changed, 1 insertion(+), 45 deletions(-) diff --git a/src/Common/CosmosClient.ts b/src/Common/CosmosClient.ts index 8af3702df..3850ff600 100644 --- a/src/Common/CosmosClient.ts +++ b/src/Common/CosmosClient.ts @@ -107,10 +107,7 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => { export const requestPlugin: Cosmos.Plugin = async (requestContext, diagnosticNode, next) => { requestContext.endpoint = new URL(configContext.PROXY_PATH, window.location.href).href; - console.log(`REQUEST CONTEXT ENDPOINT: ${JSON.stringify(requestContext.endpoint)}`); requestContext.headers["x-ms-proxy-target"] = endpoint(); - console.log(`REQUEST CONTEXT PROXY: ${JSON.stringify(requestContext.headers["x-ms-proxy-target"])}`); - console.log(`WRITE ENABLED ON ENDPOINT: ${userContext.writeEnabledInSelectedRegion}`); return await next(requestContext); }; @@ -195,46 +192,14 @@ export function client(): Cosmos.CosmosClient { _defaultHeaders["x-ms-cosmos-priority-level"] = PriorityLevel.Default; } - // Parsing out endpoint from diagnostics. Used to find address I need to add to firewall rule. - function parseEndpointFromDiag(json: string): string { - const suffix: string = ".documents.azure.com"; - const start: number = json.indexOf("//") + "//".length; - const end: number = json.indexOf(suffix) + suffix.length; - const endpoint: string = json.substring(start, end); - - return endpoint; - } - // Used to check current client region configuration. - async function fetchConnectedRegions(client: Cosmos.CosmosClient) { - // Check currently connected regions. - try { - // const someMoreThings = await client.databases.readAll().fetchAll(); - // console.log(`Current list of databases: ${JSON.stringify(someMoreThings)}`); - const currentReadRegion = await client.getReadEndpoint(); - console.log(`Current read endpoint: ${JSON.stringify(currentReadRegion)}`); - const currentReadRegions = await client.getReadEndpoints(); - console.log(`Current account endpoints: ${JSON.stringify(currentReadRegions)}`); - // Getting primary region IP that needs to be blocked. - // retrieve the regional endpoint of the account - const regionalWriteEndpoint = await client.getWriteEndpoint(); - console.log(`Current write endpoint: ${JSON.stringify(regionalWriteEndpoint)}`); - const parsedWriteEndpoint = parseEndpointFromDiag(JSON.stringify(regionalWriteEndpoint)); - console.log(`Current parsed write endpoint: ${JSON.stringify(parsedWriteEndpoint)}`); - // const writeHostAddress = await findHostAddress(parsedWriteEndpoint); - // console.log(`Current write host address: ${JSON.stringify(writeHostAddress)}`); - } catch (error) { - console.error("Error getting read endpoints:", error); - } - } - const options: Cosmos.CosmosClientOptions = { endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called key: userContext.dataPlaneRbacEnabled ? "" : userContext.masterKey, - diagnosticLevel: Cosmos.CosmosDbDiagnosticLevel.debugUnsafe, tokenProvider, userAgentSuffix: "Azure Portal", defaultHeaders: _defaultHeaders, connectionPolicy: { + enableEndpointDiscovery: userContext.selectedRegionalEndpoint ? false : true, retryOptions: { maxRetryAttemptCount: LocalStorageUtility.getEntryNumber(StorageKey.RetryAttempts), fixedRetryIntervalInMilliseconds: LocalStorageUtility.getEntryNumber(StorageKey.RetryInterval), @@ -255,8 +220,5 @@ export function client(): Cosmos.CosmosClient { _client = new Cosmos.CosmosClient(options); - // Log debug vals - // fetchConnectedRegions(_client).catch((error) => console.error(error)); - return _client; } diff --git a/src/Common/ErrorHandlingUtils.ts b/src/Common/ErrorHandlingUtils.ts index 4476a0476..b80011218 100644 --- a/src/Common/ErrorHandlingUtils.ts +++ b/src/Common/ErrorHandlingUtils.ts @@ -57,8 +57,6 @@ const replaceKnownError = (errorMessage: string): string => { errorMessage === "signal is aborted without reason" ) { return "User aborted query."; - } else if (errorMessage?.indexOf("The requested operation cannot be performed at this region") >= 0) { - return "Please select another region for this operation."; } return errorMessage; diff --git a/src/Common/dataAccess/updateDocument.ts b/src/Common/dataAccess/updateDocument.ts index c6941798e..dd97b46de 100644 --- a/src/Common/dataAccess/updateDocument.ts +++ b/src/Common/dataAccess/updateDocument.ts @@ -32,10 +32,6 @@ export const updateDocument = async ( logConsoleInfo(`Successfully updated ${entityName} ${documentId.id()}`); return response?.resource; } catch (error) { - // // If error has diagnostic information, log it. - // if (error && error.diagnostics) { - // console.error("Diagnostics:", error.diagnostics); - // } handleError(error, "UpdateDocument", `Failed to update ${entityName} ${documentId.id()}`); throw error; } finally {