Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circular dependencies in @azure/cosmos #5374

Merged
merged 2 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,12 @@ export class Items {
query<T>(query: string | SqlQuerySpec, options: FeedOptions): QueryIterator<T>;
readAll(options?: FeedOptions): QueryIterator<ItemDefinition>;
readAll<T extends ItemDefinition>(options?: FeedOptions): QueryIterator<T>;
readChangeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
// Warning: (ae-forgotten-export) The symbol "ChangeFeedOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ChangeFeedIterator" needs to be exported by the entry point index.d.ts
readChangeFeed(partitionKey: string | number | boolean, changeFeedOptions: ChangeFeedOptions): ChangeFeedIterator<any>;
readChangeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
readChangeFeed<T>(partitionKey: string | number | boolean, changeFeedOptions: ChangeFeedOptions): ChangeFeedIterator<T>;
readChangeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
upsert(body: any, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>;
upsert<T extends ItemDefinition>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>;
}
Expand Down
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