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 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ private async Task<ResponseMessage> ExecuteNextHelperAsync(CancellationToken can

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

return response;
Expand Down Expand Up @@ -296,7 +292,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 @@ -7,27 +7,9 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Contains the cosmos diagnostic information for the current request to Azure Cosmos DB service.
/// </summary>
public class CosmosDiagnostics
public abstract class CosmosDiagnostics
{
internal PointOperationStatistics pointOperationStatistics { get; set; }
internal QueryOperationStatistics queryOperationStatistics { get; set; }

/// <summary>
/// Gets the string field <see cref="Microsoft.Azure.Cosmos.CosmosDiagnostics"/> instance in the Azure DocumentDB database service.
/// </summary>
/// <returns>The string field <see cref="Microsoft.Azure.Cosmos.CosmosDiagnostics"/> instance in the Azure DocumentDB database service.</returns>
public override string ToString()
{
if (this.pointOperationStatistics != null)
{
return this.pointOperationStatistics.ToString();
}
else if (this.queryOperationStatistics != null)
{
return this.queryOperationStatistics.ToString();
}

return string.Empty;
}
// For now only ToString() will be used, having child concrete PointOperationStatistics
// and QueryOperationStatistics
simplynaveen20 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Cosmos
{
using Microsoft.Azure.Documents;

internal class PointOperationStatistics
internal sealed class PointOperationStatistics : CosmosDiagnostics
{
private ClientSideRequestStatistics clientSideRequestStatistics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos
using System.Collections.Generic;
using Newtonsoft.Json;

internal class QueryOperationStatistics
internal sealed class QueryOperationStatistics : CosmosDiagnostics
{
public QueryOperationStatistics(IReadOnlyDictionary<string, QueryMetrics> queryMetrics = null)
{
Expand Down
5 changes: 1 addition & 4 deletions Microsoft.Azure.Cosmos/src/Util/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ internal static ResponseMessage ToCosmosResponseMessage(this DocumentServiceResp

if (response.RequestStats != null)
{
cosmosResponse.cosmosDiagnostics = new CosmosDiagnostics()
{
pointOperationStatistics = new PointOperationStatistics(response.RequestStats)
};
cosmosResponse.cosmosDiagnostics = new PointOperationStatistics(response.RequestStats);
}

return cosmosResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,41 @@ public async Task PointOperationDiagnostic()
//Checking point operation diagnostics on typed operations
ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity();
ItemResponse<ToDoActivity> createResponse = await this.Container.CreateItemAsync<ToDoActivity>(item: testItem);
Assert.IsNotNull(createResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(createResponse.cosmosDiagnostics);

ItemResponse<ToDoActivity> readResponse = await this.Container.ReadItemAsync<ToDoActivity>(id: testItem.id, partitionKey: new PartitionKey(testItem.status));
Assert.IsNotNull(readResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(readResponse.cosmosDiagnostics);

testItem.description = "NewDescription";
ItemResponse<ToDoActivity> replaceResponse = await this.Container.ReplaceItemAsync<ToDoActivity>(item: testItem, id: testItem.id, partitionKey: new PartitionKey(testItem.status));
Assert.AreEqual(replaceResponse.Resource.description, "NewDescription");
Assert.IsNotNull(replaceResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(replaceResponse.cosmosDiagnostics);

ItemResponse<ToDoActivity> deleteResponse = await this.Container.DeleteItemAsync<ToDoActivity>(partitionKey: new Cosmos.PartitionKey(testItem.status), id: testItem.id);
Assert.IsNotNull(deleteResponse);
Assert.IsNotNull(deleteResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(deleteResponse.cosmosDiagnostics);

//Checking point operation diagnostics on stream operations
ResponseMessage createStreamResponse = await this.Container.CreateItemStreamAsync(
partitionKey: new PartitionKey(testItem.status),
streamPayload: TestCommon.Serializer.ToStream<ToDoActivity>(testItem));
Assert.IsNotNull(createStreamResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(createStreamResponse.cosmosDiagnostics);

ResponseMessage readStreamResponse = await this.Container.ReadItemStreamAsync(
id: testItem.id,
partitionKey: new PartitionKey(testItem.status));
Assert.IsNotNull(readStreamResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(readStreamResponse.cosmosDiagnostics);

ResponseMessage replaceStreamResponse = await this.Container.ReplaceItemStreamAsync(
streamPayload: TestCommon.Serializer.ToStream<ToDoActivity>(testItem),
id: testItem.id,
partitionKey: new PartitionKey(testItem.status));
Assert.IsNotNull(replaceStreamResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(replaceStreamResponse.cosmosDiagnostics);

ResponseMessage deleteStreamResponse = await this.Container.DeleteItemStreamAsync(
id: testItem.id,
partitionKey: new PartitionKey(testItem.status));
Assert.IsNotNull(deleteStreamResponse.cosmosDiagnostics.pointOperationStatistics);
Assert.IsNotNull(deleteStreamResponse.cosmosDiagnostics);
}

[TestMethod]
Expand All @@ -102,7 +102,7 @@ public async Task QueryOperationDiagnostic()
if (feedIterator.HasMoreResults)
{
FeedResponse<ToDoActivity> iter = await feedIterator.ReadNextAsync();
Assert.IsTrue(iter.cosmosDiagnostics.queryOperationStatistics.queryMetrics.Values.First().OutputDocumentCount > 0);
Assert.IsTrue(((QueryOperationStatistics)iter.cosmosDiagnostics).queryMetrics.Values.First().OutputDocumentCount > 0);
}

sql = new QueryDefinition("select * from ToDoActivity t ORDER BY t.cost");
Expand All @@ -112,7 +112,7 @@ public async Task QueryOperationDiagnostic()
if (feedIterator.HasMoreResults)
{
FeedResponse<ToDoActivity> iter = await feedIterator.ReadNextAsync();
Assert.IsTrue(iter.cosmosDiagnostics.queryOperationStatistics.queryMetrics.Values.First().OutputDocumentCount > 0);
Assert.IsTrue(((QueryOperationStatistics)iter.cosmosDiagnostics).queryMetrics.Values.First().OutputDocumentCount > 0);
}

sql = new QueryDefinition("select DISTINCT t.cost from ToDoActivity t");
Expand All @@ -122,8 +122,8 @@ public async Task QueryOperationDiagnostic()
if (feedIterator.HasMoreResults)
{
FeedResponse<ToDoActivity> iter = await feedIterator.ReadNextAsync();
Assert.IsNotNull(iter.cosmosDiagnostics.queryOperationStatistics);
Assert.AreEqual(1, iter.cosmosDiagnostics.queryOperationStatistics.queryMetrics.Values.First().OutputDocumentCount);
Assert.IsNotNull((QueryOperationStatistics)iter.cosmosDiagnostics);
Assert.AreEqual(1, ((QueryOperationStatistics)iter.cosmosDiagnostics).queryMetrics.Values.First().OutputDocumentCount);
}

//No query metrics return from server if user explicitly set PopulateQueryMetrics = false
Expand All @@ -135,8 +135,8 @@ public async Task QueryOperationDiagnostic()
if (feedIterator.HasMoreResults)
{
FeedResponse<ToDoActivity> iter = await feedIterator.ReadNextAsync();
Assert.IsNotNull(iter.cosmosDiagnostics.queryOperationStatistics);
Assert.AreEqual(0, iter.cosmosDiagnostics.queryOperationStatistics.queryMetrics.Values.First().OutputDocumentCount);
Assert.IsNotNull((QueryOperationStatistics)iter.cosmosDiagnostics);
Assert.AreEqual(0, ((QueryOperationStatistics)iter.cosmosDiagnostics).queryMetrics.Values.First().OutputDocumentCount);
requestOptions.PopulateQueryMetrics = true;
}

Expand All @@ -147,7 +147,7 @@ public async Task QueryOperationDiagnostic()
if (feedIterator.HasMoreResults)
{
FeedResponse<ToDoActivity> iter = await feedIterator.ReadNextAsync();
Assert.IsTrue(iter.cosmosDiagnostics.queryOperationStatistics.queryMetrics.Values.First().OutputDocumentCount > 0);
Assert.IsTrue(((QueryOperationStatistics)iter.cosmosDiagnostics).queryMetrics.Values.First().OutputDocumentCount > 0);
}

//Checking query metrics on stream query
Expand All @@ -159,7 +159,7 @@ public async Task QueryOperationDiagnostic()
if (iterator.HasMoreResults)
{
ResponseMessage responseMessage = await iterator.ReadNextAsync();
Assert.IsTrue(responseMessage.cosmosDiagnostics.queryOperationStatistics.queryMetrics.Values.First().OutputDocumentCount > 0);
Assert.IsTrue(((QueryOperationStatistics)responseMessage.cosmosDiagnostics).queryMetrics.Values.First().OutputDocumentCount > 0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1481,18 +1481,7 @@
},
"CosmosDiagnostics": {
"Subclasses": {},
"Members": {
"System.String ToString()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "System.String ToString()"
},
"Void .ctor()": {
"Type": "Constructor",
"Attributes": [],
"MethodInfo": "Void .ctor()"
}
},
"Members": {},
"NestedTypes": {}
},
"CosmosException": {
Expand Down