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 all 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
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal sealed class ClientRetryPolicy : IDocumentClientRetryPolicy
private Uri locationEndpoint;
private RetryContext retryContext;

private ClientSideRequestStatistics sharedStatistics;
private IClientSideRequestStatistics sharedStatistics;

public ClientRetryPolicy(
GlobalEndpointManager globalEndpointManager,
Expand All @@ -50,7 +50,7 @@ public ClientRetryPolicy(
this.sessionTokenRetryCount = 0;
this.canUseMultipleWriteLocations = false;

this.sharedStatistics = new ClientSideRequestStatistics();
this.sharedStatistics = new CosmosClientSideRequestStatistics();
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Microsoft.Azure.Cosmos/src/DocumentFeedResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal DocumentFeedResponse(
INameValueCollection responseHeaders,
bool useETagAsContinuation = false,
IReadOnlyDictionary<string, QueryMetrics> queryMetrics = null,
ClientSideRequestStatistics requestStats = null,
IClientSideRequestStatistics requestStats = null,
string disallowContinuationTokenMessage = null,
long responseLengthBytes = 0)
: this(result)
Expand All @@ -79,7 +79,7 @@ internal DocumentFeedResponse(
IEnumerable<T> result,
int count,
INameValueCollection responseHeaders,
ClientSideRequestStatistics requestStats,
IClientSideRequestStatistics requestStats,
long responseLengthBytes)
: this(result, count, responseHeaders, false, null, requestStats, responseLengthBytes: responseLengthBytes)
{
Expand All @@ -91,7 +91,7 @@ internal DocumentFeedResponse(
/// <remarks>
/// This value is currently used for tracking replica Uris.
/// </remarks>
internal ClientSideRequestStatistics RequestStatistics { get; private set; }
internal IClientSideRequestStatistics RequestStatistics { get; private set; }

/// <summary>
/// Gets the response length in bytes
Expand Down
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 Diagnostics { get; set; }

/// <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
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<ClientVersion>3.1.1</ClientVersion>
<DirectVersion>3.1.5</DirectVersion>
<DirectVersion>3.1.6</DirectVersion>
<HybridRowVersion>1.0.0-preview</HybridRowVersion>
<DirectPackageName Condition=" '$(SignAssembly)' == 'true' ">Microsoft.Azure.Cosmos.Direct</DirectPackageName>
<DirectPackageName Condition=" '$(SignAssembly)' != 'true' ">Microsoft.Azure.Cosmos.Direct.MyGet</DirectPackageName>
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.Diagnostics = 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 @@ -150,13 +150,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 diagnostics)
{
this.StatusCode = httpStatusCode;
this.Headers = headers;
this.Resource = item;
this.Diagnostics = diagnostics;
}

/// <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.Diagnostics);
});
}

Expand Down
Loading