Skip to content

Commit

Permalink
Merge branch 'Azure:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryGao authored Jun 7, 2023
2 parents d06150d + 4dae449 commit afbcdb7
Show file tree
Hide file tree
Showing 42 changed files with 456 additions and 174 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
# PRLabel: %Cognitive - Language
/sdk/cognitivelanguage/ @minhanh-phan @deyaaeldeen

# PRLabel: %OpenAI
/sdk/openai/ @deyaaeldeen @minhanh-phan

# PRLabel: %Schema Registry
/sdk/schemaregistry/ @deyaaeldeen

Expand Down
3 changes: 1 addition & 2 deletions eng/emitter-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"main": "dist/src/index.js",
"dependencies": {
"@azure-tools/typespec-ts": "0.13.0",
"@typespec/versioning": "0.44.0"
"@azure-tools/typespec-ts": "latest"
}
}
23 changes: 15 additions & 8 deletions sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export interface Agent {
// @public (undocumented)
export type AggregateType = "Average" | "Count" | "Max" | "Min" | "Sum";

// @public (undocumented)
export type BulkOperationResponse = OperationResponse[] & {
diagnostics: CosmosDiagnostics;
};

// @public (undocumented)
export const BulkOperationType: {
readonly Create: "Create";
Expand Down Expand Up @@ -175,7 +180,7 @@ export class ClientContext {
diagnosticContext?: CosmosDiagnosticContext;
}): Promise<Response_2<T & Resource>>;
// (undocumented)
queryPartitionKeyRanges(collectionLink: string, query?: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<PartitionKeyRange>;
queryPartitionKeyRanges(collectionLink: string, diagnosticContext: CosmosDiagnosticContext, query?: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<PartitionKeyRange>;
// (undocumented)
read<T>({ path, resourceType, resourceId, options, partitionKey, diagnosticContext, }: {
path: string;
Expand Down Expand Up @@ -814,14 +819,16 @@ export interface FeedOptions extends SharedOptions {

// @public (undocumented)
export class FeedResponse<TResource> {
constructor(resources: TResource[], headers: CosmosHeaders, hasMoreResults: boolean);
constructor(resources: TResource[], headers: CosmosHeaders, hasMoreResults: boolean, diagnostics: CosmosDiagnostics);
// (undocumented)
get activityId(): string;
// (undocumented)
get continuation(): string;
// (undocumented)
get continuationToken(): string;
// (undocumented)
readonly diagnostics: CosmosDiagnostics;
// (undocumented)
readonly hasMoreResults: boolean;
// (undocumented)
get indexMetrics(): string;
Expand Down Expand Up @@ -958,7 +965,7 @@ export class ItemResponse<T extends ItemDefinition> extends ResourceResponse<T &
export class Items {
constructor(container: Container, clientContext: ClientContext);
batch(operations: OperationInput[], partitionKey?: string, options?: RequestOptions): Promise<Response_2<OperationResponse[]>>;
bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise<OperationResponse[]>;
bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise<BulkOperationResponse>;
changeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
changeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
changeFeed<T>(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
Expand Down Expand Up @@ -1333,7 +1340,7 @@ export interface QueryInfo {
// @public
export class QueryIterator<T> {
// Warning: (ae-forgotten-export) The symbol "FetchFunctionCallback" needs to be exported by the entry point index.d.ts
constructor(clientContext: ClientContext, query: SqlQuerySpec | string, options: FeedOptions, fetchFunctions: FetchFunctionCallback | FetchFunctionCallback[], resourceLink?: string, resourceType?: ResourceType);
constructor(clientContext: ClientContext, query: SqlQuerySpec | string, options: FeedOptions, fetchFunctions: FetchFunctionCallback | FetchFunctionCallback[], diagnosticContext?: CosmosDiagnosticContext, resourceLink?: string, resourceType?: ResourceType);
fetchAll(): Promise<FeedResponse<T>>;
fetchNext(): Promise<FeedResponse<T>>;
getAsyncIterator(): AsyncIterable<FeedResponse<T>>;
Expand Down Expand Up @@ -1588,11 +1595,11 @@ export interface Resource {

// @public (undocumented)
export class ResourceResponse<TResource> {
constructor(resource: TResource | undefined, headers: CosmosHeaders_2, statusCode: StatusCode, diagnostics?: CosmosDiagnostics, substatus?: SubStatusCode);
constructor(resource: TResource | undefined, headers: CosmosHeaders_2, statusCode: StatusCode, diagnostics: CosmosDiagnostics, substatus?: SubStatusCode);
// (undocumented)
get activityId(): string;
// (undocumented)
readonly diagnostics?: CosmosDiagnostics;
readonly diagnostics: CosmosDiagnostics;
// (undocumented)
get etag(): string;
// (undocumented)
Expand Down Expand Up @@ -1642,7 +1649,7 @@ interface Response_2<T> {
// (undocumented)
code?: number;
// (undocumented)
diagnostics?: CosmosDiagnostics;
diagnostics: CosmosDiagnostics;
// (undocumented)
headers: CosmosHeaders;
// (undocumented)
Expand Down Expand Up @@ -2202,7 +2209,7 @@ export class Users {

// Warnings were encountered during analysis:
//
// src/ClientContext.ts:90:5 - (ae-forgotten-export) The symbol "CosmosDiagnosticContext" needs to be exported by the entry point index.d.ts
// src/ClientContext.ts:91:5 - (ae-forgotten-export) The symbol "CosmosDiagnosticContext" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
16 changes: 13 additions & 3 deletions sdk/cosmosdb/cosmos/src/ClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { BulkOptions } from "./utils/batch";
import { sanitizeEndpoint } from "./utils/checkURL";
import { AzureLogger, createClientLogger } from "@azure/logger";
import { CosmosDiagnosticContext } from "./CosmosDiagnosticsContext";
import { MetadataLookUpType } from "./CosmosDiagnostics";

const logger: AzureLogger = createClientLogger("ClientContext");

Expand Down Expand Up @@ -229,22 +230,31 @@ export class ClientContext {

public queryPartitionKeyRanges(
collectionLink: string,
diagnosticContext: CosmosDiagnosticContext,
query?: string | SqlQuerySpec,
options?: FeedOptions
): QueryIterator<PartitionKeyRange> {
const path = getPathFromLink(collectionLink, ResourceType.pkranges);
const id = getIdFromLink(collectionLink);
const cb: FetchFunctionCallback = (innerOptions) => {
return this.queryFeed({
const cb: FetchFunctionCallback = async (
innerOptions,
diagnosticCtx: CosmosDiagnosticContext
) => {
const response = await this.queryFeed({
path,
resourceType: ResourceType.pkranges,
resourceId: id,
resultFn: (result) => result.PartitionKeyRanges,
query,
options: innerOptions,
});
diagnosticCtx.recordMetaDataLookup(
response.diagnostics,
MetadataLookUpType.PartitionKeyRangeLookUp
);
return response;
};
return new QueryIterator<PartitionKeyRange>(this, query, options, cb);
return new QueryIterator<PartitionKeyRange>(this, query, options, cb, diagnosticContext);
}

public async delete<T>({
Expand Down
19 changes: 19 additions & 0 deletions sdk/cosmosdb/cosmos/src/CosmosDiagnosticsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ export class CosmosDiagnosticContext {
this.locationEndpointsContacted.set(location.databaseAccountEndpoint, location);
}

public reset(): void {
this.requestStartTimeUTCinMs = getCurrentTimestampInMs();
this.requestEndTimeUTCinMs = getCurrentTimestampInMs();
this.retryStartTimeUTCinMs = 0;
this.headers = {};
this.retryAttemptNumber = 0;
this.failedAttempts = [];
this.metadataLookups = [];
this.requestPayloadLength = 0;
this.responsePayloadLength = 0;
this.locationEndpointsContacted = new Map();
}

public resetAndGetDiagnostics(): CosmosDiagnostics {
const diagnostic = this.getDiagnostics();
this.reset();
return diagnostic;
}

public getDiagnostics(): CosmosDiagnostics {
this.recordSessionEnd();
return new CosmosDiagnostics(
Expand Down
19 changes: 19 additions & 0 deletions sdk/cosmosdb/cosmos/src/client/ClientUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { MetadataLookUpType } from "../CosmosDiagnostics";
import { CosmosDiagnosticContext } from "../CosmosDiagnosticsContext";
import { PartitionKeyDefinition } from "../documents";
import { Container } from "./Container";

export async function readAndRecordPartitionKeyDefinition(container: Container): Promise<{
diagnosticContext: CosmosDiagnosticContext;
partitionKeyDefinition: PartitionKeyDefinition;
}> {
const diagnosticContext: CosmosDiagnosticContext = new CosmosDiagnosticContext();

const { resource: partitionKeyDefinition, diagnostics } =
await container.readPartitionKeyDefinition();
diagnosticContext.recordMetaDataLookup(diagnostics, MetadataLookUpType.PartitionKeyRangeLookUp);
return { diagnosticContext, partitionKeyDefinition };
}
8 changes: 7 additions & 1 deletion sdk/cosmosdb/cosmos/src/client/Container/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Offer, OfferDefinition } from "../Offer";
import { OfferResponse } from "../Offer/OfferResponse";
import { Resource } from "../Resource";
import { getEmptyCosmosDiagnostics } from "../../CosmosDiagnostics";
import { CosmosDiagnosticContext } from "../../CosmosDiagnosticsContext";

/**
* Operations for reading, replacing, or deleting a specific, existing container by id.
Expand Down Expand Up @@ -266,7 +267,12 @@ export class Container {

public readPartitionKeyRanges(feedOptions?: FeedOptions): QueryIterator<PartitionKeyRange> {
feedOptions = feedOptions || {};
return this.clientContext.queryPartitionKeyRanges(this.url, undefined, feedOptions);
return this.clientContext.queryPartitionKeyRanges(
this.url,
new CosmosDiagnosticContext(),
undefined,
feedOptions
);
}

/**
Expand Down
34 changes: 22 additions & 12 deletions sdk/cosmosdb/cosmos/src/client/Item/Item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { ClientContext } from "../../ClientContext";
import { CosmosDiagnosticContext } from "../../CosmosDiagnosticsContext";
import {
createDocumentUri,
getIdFromLink,
Expand All @@ -13,6 +14,7 @@ import { PartitionKey } from "../../documents";
import { extractPartitionKey, undefinedPartitionKey } from "../../extractPartitionKey";
import { RequestOptions, Response } from "../../request";
import { PatchRequestBody } from "../../utils/patch";
import { readAndRecordPartitionKeyDefinition } from "../ClientUtils";
import { Container } from "../Container";
import { Resource } from "../Resource";
import { ItemDefinition } from "./ItemDefinition";
Expand Down Expand Up @@ -74,10 +76,11 @@ export class Item {
public async read<T extends ItemDefinition = any>(
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
let diagnosticContext: CosmosDiagnosticContext;
if (this.partitionKey === undefined) {
const { resource: partitionKeyDefinition } =
await this.container.readPartitionKeyDefinition();
this.partitionKey = undefinedPartitionKey(partitionKeyDefinition);
const partitionKeyResponse = await readAndRecordPartitionKeyDefinition(this.container);
this.partitionKey = undefinedPartitionKey(partitionKeyResponse.partitionKeyDefinition);
diagnosticContext = partitionKeyResponse.diagnosticContext;
}

const path = getPathFromLink(this.url);
Expand All @@ -90,6 +93,7 @@ export class Item {
resourceId: id,
options,
partitionKey: this.partitionKey,
diagnosticContext,
});
} catch (error: any) {
if (error.code !== StatusCodes.NotFound) {
Expand Down Expand Up @@ -139,10 +143,11 @@ export class Item {
body: T,
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
let diagnosticContext: CosmosDiagnosticContext;
if (this.partitionKey === undefined) {
const { resource: partitionKeyDefinition } =
await this.container.readPartitionKeyDefinition();
this.partitionKey = extractPartitionKey(body, partitionKeyDefinition);
const partitionKeyResponse = await readAndRecordPartitionKeyDefinition(this.container);
this.partitionKey = extractPartitionKey(body, partitionKeyResponse.partitionKeyDefinition);
diagnosticContext = partitionKeyResponse.diagnosticContext;
}

const err = {};
Expand All @@ -160,6 +165,7 @@ export class Item {
resourceId: id,
options,
partitionKey: this.partitionKey,
diagnosticContext,
});
return new ItemResponse(
response.result,
Expand All @@ -182,10 +188,11 @@ export class Item {
public async delete<T extends ItemDefinition = any>(
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
let diagnosticContext: CosmosDiagnosticContext;
if (this.partitionKey === undefined) {
const { resource: partitionKeyDefinition } =
await this.container.readPartitionKeyDefinition();
this.partitionKey = undefinedPartitionKey(partitionKeyDefinition);
const partitionKeyResponse = await readAndRecordPartitionKeyDefinition(this.container);
this.partitionKey = undefinedPartitionKey(partitionKeyResponse.partitionKeyDefinition);
diagnosticContext = partitionKeyResponse.diagnosticContext;
}

const path = getPathFromLink(this.url);
Expand All @@ -197,6 +204,7 @@ export class Item {
resourceId: id,
options,
partitionKey: this.partitionKey,
diagnosticContext,
});
return new ItemResponse(
response.result,
Expand All @@ -220,10 +228,11 @@ export class Item {
body: PatchRequestBody,
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
let diagnosticContext: CosmosDiagnosticContext;
if (this.partitionKey === undefined) {
const { resource: partitionKeyDefinition } =
await this.container.readPartitionKeyDefinition();
this.partitionKey = extractPartitionKey(body, partitionKeyDefinition);
const partitionKeyResponse = await readAndRecordPartitionKeyDefinition(this.container);
this.partitionKey = extractPartitionKey(body, partitionKeyResponse.partitionKeyDefinition);
diagnosticContext = partitionKeyResponse.diagnosticContext;
}

const path = getPathFromLink(this.url);
Expand All @@ -236,6 +245,7 @@ export class Item {
resourceId: id,
options,
partitionKey: this.partitionKey,
diagnosticContext,
});
return new ItemResponse(
response.result,
Expand Down
Loading

0 comments on commit afbcdb7

Please sign in to comment.