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

Adding basic request diagnostics for V3 #615

Merged
merged 26 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e7c3424
inital commit
simplynaveen20 Jul 31, 2019
0a0f200
making cosmosDiagnostic public
simplynaveen20 Jul 31, 2019
1b75148
bumping direct version
simplynaveen20 Jul 31, 2019
431de60
Merge branch 'master' into users/nakumar/requestDiagnosticsV3
simplynaveen20 Aug 1, 2019
1478d41
removing formatting of json
simplynaveen20 Aug 1, 2019
464eccf
merging with master
simplynaveen20 Aug 16, 2019
94bf545
removing extra line
simplynaveen20 Aug 16, 2019
34774d3
Merge branch 'master' into users/nakumar/requestDiagnosticsV3
simplynaveen20 Aug 19, 2019
0367e03
updating per new changes with clientsiderequestdiagnostics
simplynaveen20 Aug 19, 2019
bd317ad
Merge branch 'master' into users/nakumar/requestDiagnosticsV3
simplynaveen20 Aug 21, 2019
567521a
using to string on CLientSideRequestDiagnostics
simplynaveen20 Aug 21, 2019
06613ae
updating DOtNetSDKAPI
simplynaveen20 Aug 21, 2019
feaef5e
updating DotNetSDKAPI.json
simplynaveen20 Aug 21, 2019
179281f
moving cosmosDiagnostic as abstract clas
simplynaveen20 Aug 21, 2019
4d82e31
adding abstract tostring
simplynaveen20 Aug 22, 2019
8fb181c
updating change log
simplynaveen20 Aug 22, 2019
baace6c
removing query metrics from header
simplynaveen20 Aug 22, 2019
af0b757
removing populateQueryOption flag from request option
simplynaveen20 Aug 26, 2019
04855e7
merging with master
simplynaveen20 Aug 27, 2019
9ce1424
updating contract
simplynaveen20 Aug 27, 2019
250d43e
Merge branch 'master' into users/nakumar/requestDiagnosticsV3
simplynaveen20 Aug 27, 2019
f84aa5e
Merge branch 'master' into users/nakumar/requestDiagnosticsV3
j82w Aug 29, 2019
00dd4c3
upgrading direct to 3.1.6 to leverage IClientSideRequestDiagnostics
simplynaveen20 Aug 29, 2019
ac5b28f
Merge branch 'master' into users/nakumar/requestDiagnosticsV3
simplynaveen20 Aug 30, 2019
cd411e1
changing name of cosmosDiagnostics to diagnostics
simplynaveen20 Aug 30, 2019
9a42e92
moving diagnostics to Diagnostics
simplynaveen20 Aug 30, 2019
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
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public virtual Stream Content
/// </summary>
public virtual RequestMessage RequestMessage { get; internal set; }

/// <summary>
/// Gets the cosmos diagnostic information for the current request to Azure Cosmos DB service
/// </summary>
public CosmosDiagnostics cosmosDiagnostics { get; set; }
simplynaveen20 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets the internal error object.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ internal CosmosQueryResponseMessageHeaders CloneKnownProperties(
RetryAfterLiteral = this.RetryAfterLiteral,
SubStatusCodeLiteral = this.SubStatusCodeLiteral,
ContentType = this.ContentType,
QueryMetricsText = QueryMetricsText
};
}

Expand Down Expand Up @@ -106,6 +107,7 @@ internal static CosmosQueryResponseMessageHeaders ConvertToQueryHeaders(
RetryAfterLiteral = sourceHeaders.RetryAfterLiteral,
SubStatusCodeLiteral = sourceHeaders.SubStatusCodeLiteral,
ContentType = sourceHeaders.ContentType,
QueryMetricsText = sourceHeaders.QueryMetricsText
};
}
}
Expand Down
3 changes: 3 additions & 0 deletions Microsoft.Azure.Cosmos/src/Headers/Headers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ internal string RetryAfterLiteral
[CosmosKnownHeaderAttribute(HeaderName = HttpConstants.HttpHeaders.PageSize)]
internal string PageSize { get; set; }

[CosmosKnownHeaderAttribute(HeaderName = HttpConstants.HttpHeaders.QueryMetrics)]
internal string QueryMetricsText { get; set; }
simplynaveen20 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Creates a new instance of <see cref="Headers"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ public CosmosQueryResponseMessageHeaders GetResponseHeaders()

this.SetQueryMetrics();

IReadOnlyDictionary<string, QueryMetrics> groupedQueryMetrics = this.GetQueryMetrics();
if (groupedQueryMetrics != null && groupedQueryMetrics.Count != 0)
{
responseHeaders[HttpConstants.HttpHeaders.QueryMetrics] = QueryMetrics
.CreateFromIEnumerable(groupedQueryMetrics.Values)
.ToDelimitedString();
}

responseHeaders.RequestCharge = this.requestChargeTracker.GetAndResetCharge();

return responseHeaders;
Expand Down Expand Up @@ -392,6 +384,7 @@ public override async Task<QueryResponse> DrainAsync(int maxElements, Cancellati
result: results,
count: results.Count,
responseHeaders: this.GetResponseHeaders(),
queryMetrics: this.GetQueryMetrics(),
responseLengthBytes: this.GetAndResetResponseLengthBytes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ private async Task<ResponseMessage> ExecuteNextHelperAsync(CancellationToken can
}
}

if (response?.queryMetrics != null && response?.queryMetrics.Count > 0)
{
response.cosmosDiagnostics = new QueryOperationStatistics(response.queryMetrics);
}

return response;
}

Expand Down Expand Up @@ -307,7 +312,7 @@ private async Task<CosmosQueryExecutionContext> CreateItemQueryExecutionContextA
rewrittenComosQueryContext = this.cosmosQueryContext;
}

return await CreateSpecializedDocumentQueryExecutionContextAsync(
return await this.CreateSpecializedDocumentQueryExecutionContextAsync(
rewrittenComosQueryContext,
partitionedQueryExecutionInfo,
targetRanges,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public override async Task<QueryResponse> DrainAsync(int maxElements, Cancellati
PartitionedQueryMetrics partitionedQueryMetrics = new PartitionedQueryMetrics();
ResourceType resourceType = ResourceType.Document;
string containerRid = null;

while (!this.IsDone)
simplynaveen20 marked this conversation as resolved.
Show resolved Hide resolved
{
QueryResponse result = await base.DrainAsync(int.MaxValue, token);
Expand Down Expand Up @@ -150,13 +149,14 @@ public override async Task<QueryResponse> DrainAsync(int maxElements, Cancellati
count: finalResult.Count,
responseLengthBytes: responseLengthBytes,
responseHeaders: new CosmosQueryResponseMessageHeaders(
continauationToken: null,
disallowContinuationTokenMessage: null,
resourceType: resourceType,
continauationToken: null,
disallowContinuationTokenMessage: null,
resourceType: resourceType,
containerRid: containerRid)
{
RequestCharge = requestCharge
});
},
queryMetrics: this.GetQueryMetrics());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public override async Task<QueryResponse> DrainAsync(int maxElements, Cancellati
distinctResults,
distinctResults.Count,
cosmosQueryResponse.ResponseLengthBytes,
cosmosQueryResponse.QueryHeaders.CloneKnownProperties(updatedContinuationToken, disallowContinuationTokenMessage));
cosmosQueryResponse.QueryHeaders.CloneKnownProperties(updatedContinuationToken, disallowContinuationTokenMessage),
cosmosQueryResponse.queryMetrics);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public override async Task<QueryResponse> DrainAsync(int maxElements, Cancellati
result: documentsAfterSkip,
count: documentsAfterSkip.Count(),
responseHeaders: sourcePage.QueryHeaders.CloneKnownProperties(updatedContinuationToken, sourcePage.QueryHeaders.DisallowContinuationTokenMessage),
queryMetrics: sourcePage.queryMetrics,
responseLengthBytes: sourcePage.ResponseLengthBytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public override async Task<QueryResponse> DrainAsync(int maxElements, Cancellati
takedDocuments,
takedDocuments.Count,
results.ResponseLengthBytes,
results.QueryHeaders.CloneKnownProperties(updatedContinuationToken, results.QueryHeaders.DisallowContinuationTokenMessage));
results.QueryHeaders.CloneKnownProperties(updatedContinuationToken, results.QueryHeaders.DisallowContinuationTokenMessage),
results.queryMetrics);
}

private enum TakeEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ public override async Task<QueryResponse> ExecuteNextAsync(CancellationToken tok
dynamics,
queryResponse.Count,
queryResponse.ResponseLengthBytes,
queryResponse.QueryHeaders.CloneKnownProperties());
queryResponse.QueryHeaders.CloneKnownProperties(),
queryMetrics: queryResponse.queryMetrics);
}
catch (Exception)
{
Expand Down
18 changes: 9 additions & 9 deletions Microsoft.Azure.Cosmos/src/Query/QueryMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public long OutputDocumentCount
/// <summary>
/// Gets the size of documents outputted in bytes during query in the Azure DocumentDB database service.
/// </summary>
internal long OutputDocumentSize
public long OutputDocumentSize
{
get
{
Expand All @@ -168,7 +168,7 @@ internal long OutputDocumentSize
/// <summary>
/// Gets the total query time in the Azure DocumentDB database service.
/// </summary>
internal TimeSpan TotalQueryExecutionTime
public TimeSpan TotalQueryExecutionTime
{
get
{
Expand Down Expand Up @@ -212,7 +212,7 @@ public long Retries
/// <summary>
/// Gets the query index lookup time in the Azure DocumentDB database service.
/// </summary>
internal TimeSpan IndexLookupTime
public TimeSpan IndexLookupTime
{
get
{
Expand All @@ -223,7 +223,7 @@ internal TimeSpan IndexLookupTime
/// <summary>
/// Gets the document loading time during query in the Azure DocumentDB database service.
/// </summary>
internal TimeSpan DocumentLoadTime
public TimeSpan DocumentLoadTime
{
get
{
Expand All @@ -234,7 +234,7 @@ internal TimeSpan DocumentLoadTime
/// <summary>
/// Gets the query runtime execution times during query in the Azure DocumentDB database service.
/// </summary>
internal RuntimeExecutionTimes RuntimeExecutionTimes
public RuntimeExecutionTimes RuntimeExecutionTimes
{
get
{
Expand All @@ -245,7 +245,7 @@ internal RuntimeExecutionTimes RuntimeExecutionTimes
/// <summary>
/// Gets the output writing/serializing time during query in the Azure DocumentDB database service.
/// </summary>
internal TimeSpan DocumentWriteTime
public TimeSpan DocumentWriteTime
{
get
{
Expand Down Expand Up @@ -281,7 +281,7 @@ public double IndexHitRatio
/// <summary>
/// Gets the Index Hit Document Count.
/// </summary>
internal long IndexHitDocumentCount
public long IndexHitDocumentCount
{
get
{
Expand All @@ -292,7 +292,7 @@ internal long IndexHitDocumentCount
/// <summary>
/// Gets the VMExecution Time.
/// </summary>
internal TimeSpan VMExecutionTime
public TimeSpan VMExecutionTime
{
get
{
Expand Down Expand Up @@ -560,7 +560,7 @@ public TimeSpan WriteOutputTime
/// <summary>
/// Gets the query runtime execution times during query in the Azure DocumentDB database service.
/// </summary>
internal RuntimeExecutionTimes RuntimeExecutionTimes
public RuntimeExecutionTimes RuntimeExecutionTimes
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ internal override void PopulateRequestOptions(RequestMessage request)
request.Headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, this.CosmosSerializationOptions.ContentSerializationFormat);
}

request.Headers.Add(HttpConstants.HttpHeaders.PopulateQueryMetrics, bool.TrueString);

base.PopulateRequestOptions(request);
}

Expand All @@ -220,7 +222,7 @@ internal QueryRequestOptions Clone()
EnableCrossPartitionSkipTake = this.EnableCrossPartitionSkipTake,
EnableGroupBy = this.EnableGroupBy,
Properties = this.Properties,
IsEffectivePartitionKeyRouting = this.IsEffectivePartitionKeyRouting
IsEffectivePartitionKeyRouting = this.IsEffectivePartitionKeyRouting,
};

return queryRequestOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ protected ItemResponse()
internal ItemResponse(
HttpStatusCode httpStatusCode,
Headers headers,
T item)
T item,
CosmosDiagnostics cosmosDiagnostics)
{
this.StatusCode = httpStatusCode;
this.Headers = headers;
this.Resource = item;
this.cosmosDiagnostics = cosmosDiagnostics;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal FeedResponse<T> CreateQueryFeedResponse<T>(
if (queryResponse != null)
{
return QueryResponse<T>.CreateResponse<T>(
responseMessage: queryResponse,
cosmosQueryResponse: queryResponse,
jsonSerializer: this.cosmosSerializer);
}

Expand All @@ -56,7 +56,8 @@ internal Task<ItemResponse<T>> CreateItemResponseAsync<T>(
return new ItemResponse<T>(
cosmosResponseMessage.StatusCode,
cosmosResponseMessage.Headers,
item);
item,
cosmosResponseMessage.cosmosDiagnostics);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private QueryResponse(
int count,
long responseLengthBytes,
CosmosQueryResponseMessageHeaders responseHeaders,
IReadOnlyDictionary<string, QueryMetrics> queryMetrics,
HttpStatusCode statusCode,
RequestMessage requestMessage,
string errorMessage,
Expand All @@ -42,6 +43,7 @@ private QueryResponse(
this.CosmosElements = result;
this.Count = count;
this.ResponseLengthBytes = responseLengthBytes;
this.queryMetrics = queryMetrics;
}

public int Count { get; }
Expand Down Expand Up @@ -72,6 +74,8 @@ private QueryResponse(
/// </remarks>
internal ClientSideRequestStatistics RequestStatistics { get; }

internal IReadOnlyDictionary<string, QueryMetrics> queryMetrics { get; set; }

internal virtual CosmosSerializationFormatOptions CosmosSerializationOptions { get; set; }

internal bool GetHasMoreResults()
Expand All @@ -83,7 +87,8 @@ internal static QueryResponse CreateSuccess(
IEnumerable<CosmosElement> result,
int count,
long responseLengthBytes,
CosmosQueryResponseMessageHeaders responseHeaders)
CosmosQueryResponseMessageHeaders responseHeaders,
IReadOnlyDictionary<string, QueryMetrics> queryMetrics = null)
{
if (count < 0)
{
Expand All @@ -100,6 +105,7 @@ internal static QueryResponse CreateSuccess(
count: count,
responseLengthBytes: responseLengthBytes,
responseHeaders: responseHeaders,
queryMetrics: queryMetrics,
statusCode: HttpStatusCode.OK,
errorMessage: null,
error: null,
Expand All @@ -120,6 +126,7 @@ internal static QueryResponse CreateFailure(
count: 0,
responseLengthBytes: 0,
responseHeaders: responseHeaders,
queryMetrics: null,
statusCode: statusCode,
errorMessage: errorMessage,
error: error,
Expand All @@ -144,11 +151,13 @@ private QueryResponse(
HttpStatusCode httpStatusCode,
IEnumerable<CosmosElement> cosmosElements,
CosmosQueryResponseMessageHeaders responseMessageHeaders,
CosmosDiagnostics cosmosDiagnostics,
CosmosSerializer jsonSerializer,
CosmosSerializationFormatOptions serializationOptions)
{
this.cosmosElements = cosmosElements;
this.QueryHeaders = responseMessageHeaders;
this.cosmosDiagnostics = cosmosDiagnostics;
this.jsonSerializer = jsonSerializer;
this.serializationOptions = serializationOptions;
this.StatusCode = httpStatusCode;
Expand Down Expand Up @@ -189,21 +198,6 @@ public override IEnumerable<T> Resource
}
}

internal static QueryResponse<TInput> CreateResponse<TInput>(
ResponseMessage responseMessage,
CosmosSerializer jsonSerializer)
{
QueryResponse queryResponse = responseMessage as QueryResponse;
if (queryResponse == null)
{
throw new ArgumentException($"{nameof(responseMessage)} must be of type query response.");
}

return QueryResponse<TInput>.CreateResponse<TInput>(
queryResponse,
jsonSerializer);
}

internal static QueryResponse<TInput> CreateResponse<TInput>(
QueryResponse cosmosQueryResponse,
CosmosSerializer jsonSerializer)
Expand All @@ -216,10 +210,10 @@ internal static QueryResponse<TInput> CreateResponse<TInput>(
httpStatusCode: cosmosQueryResponse.StatusCode,
cosmosElements: cosmosQueryResponse.CosmosElements,
responseMessageHeaders: cosmosQueryResponse.QueryHeaders,
cosmosDiagnostics: cosmosQueryResponse.cosmosDiagnostics,
jsonSerializer: jsonSerializer,
serializationOptions: cosmosQueryResponse.CosmosSerializationOptions);
}

return queryResponse;
}
}
Expand Down
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public static implicit operator T(Response<T> response)
/// </remarks>
public abstract string ETag { get; }

/// <summary>
/// Gets the cosmos diagnostics information for the current request to Azure Cosmos DB service
/// </summary>
public CosmosDiagnostics cosmosDiagnostics { get; set; }
simplynaveen20 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets the maximum size limit for this entity from the Azure Cosmos DB service.
/// </summary>
Expand Down
Loading