From 880dc809b20dd85c129951fdd4fa50eeb64ccdbd Mon Sep 17 00:00:00 2001 From: Jose Manuel Heredia Hidalgo Date: Tue, 8 Oct 2019 16:15:46 -0700 Subject: [PATCH] Fix circular dependencies in @azure/cosmos (#5374) * Fix circular dependencies in @azure/cosmos * convert RequestCharge header to number --- .../queryExecutionContext/defaultQueryExecutionContext.ts | 3 ++- sdk/cosmosdb/cosmos/src/queryMetrics/clientSideMetrics.ts | 3 +-- sdk/cosmosdb/cosmos/src/request/RequestHandler.ts | 6 +++--- sdk/cosmosdb/cosmos/src/retry/retryUtility.ts | 6 ++++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sdk/cosmosdb/cosmos/src/queryExecutionContext/defaultQueryExecutionContext.ts b/sdk/cosmosdb/cosmos/src/queryExecutionContext/defaultQueryExecutionContext.ts index 92d4ced87654..e719aefe3df8 100644 --- a/sdk/cosmosdb/cosmos/src/queryExecutionContext/defaultQueryExecutionContext.ts +++ b/sdk/cosmosdb/cosmos/src/queryExecutionContext/defaultQueryExecutionContext.ts @@ -185,6 +185,7 @@ export class DefaultQueryExecutionContext implements ExecutionContext { // Add the request charge to the query metrics so that we can have per partition request charge. if (Constants.HttpHeaders.RequestCharge in responseHeaders) { + const requestCharge = Number(responseHeaders[Constants.HttpHeaders.RequestCharge]) || 0; queryMetrics = new QueryMetrics( queryMetrics.retrievedDocumentCount, queryMetrics.retrievedDocumentSize, @@ -198,7 +199,7 @@ export class DefaultQueryExecutionContext implements ExecutionContext { queryMetrics.vmExecutionTime, queryMetrics.runtimeExecutionTimes, queryMetrics.documentWriteTime, - new ClientSideMetrics(responseHeaders[Constants.HttpHeaders.RequestCharge]) + new ClientSideMetrics(requestCharge) ); } diff --git a/sdk/cosmosdb/cosmos/src/queryMetrics/clientSideMetrics.ts b/sdk/cosmosdb/cosmos/src/queryMetrics/clientSideMetrics.ts index c20a2e7bb7f1..ebe2e714f678 100644 --- a/sdk/cosmosdb/cosmos/src/queryMetrics/clientSideMetrics.ts +++ b/sdk/cosmosdb/cosmos/src/queryMetrics/clientSideMetrics.ts @@ -1,6 +1,5 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getRequestChargeIfAny } from "../queryExecutionContext/headerUtils"; export class ClientSideMetrics { constructor(public readonly requestCharge: number) {} @@ -15,7 +14,7 @@ export class ClientSideMetrics { throw new Error("clientSideMetrics has null or undefined item(s)"); } - requestCharge += getRequestChargeIfAny(clientSideMetrics.requestCharge); + requestCharge += clientSideMetrics.requestCharge; } return new ClientSideMetrics(requestCharge); diff --git a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts index a369633c3121..fdb1398006fd 100644 --- a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts +++ b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts @@ -17,8 +17,7 @@ import { TimeoutError } from "./TimeoutError"; /** @hidden */ const log = logger("RequestHandler"); -/** @hidden */ -export async function executeRequest(requestContext: RequestContext) { +async function executeRequest(requestContext: RequestContext) { return executePlugins(requestContext, httpRequest, PluginOn.request); } @@ -143,6 +142,7 @@ export async function request(requestContext: RequestContext): Promise Promise>; } /** @@ -41,7 +41,8 @@ interface RetryPolicies { export async function execute({ retryContext = {}, retryPolicies, - requestContext + requestContext, + executeRequest }: ExecuteArgs): Promise> { // TODO: any response if (!retryPolicies) { @@ -121,6 +122,7 @@ export async function execute({ } await sleep(retryPolicy.retryAfterInMilliseconds); return execute({ + executeRequest, requestContext, retryContext, retryPolicies