Skip to content

Commit

Permalink
Fix circular dependencies in @azure/cosmos (#5374)
Browse files Browse the repository at this point in the history
* Fix circular dependencies in @azure/cosmos

* convert RequestCharge header to number
  • Loading branch information
joheredi authored Oct 8, 2019
1 parent 560b14f commit 880dc80
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -198,7 +199,7 @@ export class DefaultQueryExecutionContext implements ExecutionContext {
queryMetrics.vmExecutionTime,
queryMetrics.runtimeExecutionTimes,
queryMetrics.documentWriteTime,
new ClientSideMetrics(responseHeaders[Constants.HttpHeaders.RequestCharge])
new ClientSideMetrics(requestCharge)
);
}

Expand Down
3 changes: 1 addition & 2 deletions sdk/cosmosdb/cosmos/src/queryMetrics/clientSideMetrics.ts
Original file line number Diff line number Diff line change
@@ -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) {}
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmosdb/cosmos/src/request/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -143,6 +142,7 @@ export async function request<T>(requestContext: RequestContext): Promise<Cosmos
}

return RetryUtility.execute({
requestContext
requestContext,
executeRequest
});
}
6 changes: 4 additions & 2 deletions sdk/cosmosdb/cosmos/src/retry/retryUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { StatusCodes, SubStatusCodes } from "../common/statusCodes";
import { Response } from "../request";
import { LocationRouting } from "../request/LocationRouting";
import { RequestContext } from "../request/RequestContext";
import { executeRequest } from "../request/RequestHandler";
import { DefaultRetryPolicy } from "./defaultRetryPolicy";
import { EndpointDiscoveryRetryPolicy } from "./endpointDiscoveryRetryPolicy";
import { ResourceThrottleRetryPolicy } from "./resourceThrottleRetryPolicy";
Expand All @@ -21,6 +20,7 @@ interface ExecuteArgs {
retryContext?: RetryContext;
retryPolicies?: RetryPolicies;
requestContext: RequestContext;
executeRequest: (requestContext: RequestContext) => Promise<Response<any>>;
}

/**
Expand All @@ -41,7 +41,8 @@ interface RetryPolicies {
export async function execute({
retryContext = {},
retryPolicies,
requestContext
requestContext,
executeRequest
}: ExecuteArgs): Promise<Response<any>> {
// TODO: any response
if (!retryPolicies) {
Expand Down Expand Up @@ -121,6 +122,7 @@ export async function execute({
}
await sleep(retryPolicy.retryAfterInMilliseconds);
return execute({
executeRequest,
requestContext,
retryContext,
retryPolicies
Expand Down

0 comments on commit 880dc80

Please sign in to comment.