Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public ServerSideMetricsInternal(

public int? PartitionKeyRangeId { get; set; }

public double? RequestCharge { get; set; }

public static ServerSideMetricsInternal Create(IEnumerable<ServerSideMetricsInternal> serverSideMetricsEnumerable)
{
ServerSideMetricsInternalAccumulator accumulator = new ServerSideMetricsInternalAccumulator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideM
{
queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.FeedRange = currentTrace.Name;
queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.PartitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(currentTrace);
queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.RequestCharge = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.PartitionKeyRangeId != null
? WalkTraceTreeForRequestCharge(currentTrace)
: WalkTraceTreeForRequestChargeGateway(currentTrace);

accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics);
return;
}
Expand Down Expand Up @@ -142,5 +146,66 @@ public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideM

return null;
}

private static double? WalkTraceTreeForRequestCharge(ITrace currentTrace)
{
if (currentTrace == null)
{
return null;
}

foreach (Object datum in currentTrace.Data.Values)
{
if (datum is ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum)
{
if (clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList.Count > 0)
{
return clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList[0].StoreResult.RequestCharge;
}
else
{
return null;
}
}
}

foreach (ITrace childTrace in currentTrace.Children)
{
double? requestCharge = WalkTraceTreeForRequestCharge(childTrace);
if (requestCharge != null)
{
return requestCharge;
}
}

return null;
}

private static double? WalkTraceTreeForRequestChargeGateway(ITrace currentTrace)
{
if (currentTrace == null)
{
return null;
}

foreach (Object datum in currentTrace.Data.Values)
{
if (datum is PointOperationStatisticsTraceDatum pointOperationStatisticsTraceDatum)
{
return pointOperationStatisticsTraceDatum.RequestCharge;
}
}

foreach (ITrace childTrace in currentTrace.Children)
{
double? requestCharge = WalkTraceTreeForRequestChargeGateway(childTrace);
if (requestCharge != null)
{
return requestCharge;
}
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ public abstract class ServerSidePartitionedMetrics
/// Only has a value in direct mode. When using gateway mode, this is null.
/// </remarks>
public abstract int? PartitionKeyRangeId { get; }

/// <summary>
/// Gets the request charge for the operation.
/// </summary>
public abstract double? RequestCharge { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos
internal class ServerSidePartitionedMetricsInternal : ServerSidePartitionedMetrics
{
internal ServerSidePartitionedMetricsInternal(ServerSideMetricsInternal serverSideMetricsInternal)
: this(serverSideMetricsInternal, serverSideMetricsInternal.FeedRange, serverSideMetricsInternal.PartitionKeyRangeId)
: this(serverSideMetricsInternal, serverSideMetricsInternal.FeedRange, serverSideMetricsInternal.PartitionKeyRangeId, serverSideMetricsInternal.RequestCharge)
{
}

Expand All @@ -22,11 +22,13 @@ internal ServerSidePartitionedMetricsInternal(ServerSideMetricsInternal serverSi
/// <param name="serverSideMetricsInternal"></param>
/// <param name="feedRange"></param>
/// <param name="partitionKeyRangeId"></param>
internal ServerSidePartitionedMetricsInternal(ServerSideMetricsInternal serverSideMetricsInternal, string feedRange, int? partitionKeyRangeId)
/// <param name="requestCharge"></param>
internal ServerSidePartitionedMetricsInternal(ServerSideMetricsInternal serverSideMetricsInternal, string feedRange, int? partitionKeyRangeId, double? requestCharge)
{
this.ServerSideMetricsInternal = serverSideMetricsInternal;
this.FeedRange = feedRange;
this.PartitionKeyRangeId = partitionKeyRangeId;
this.RequestCharge = requestCharge;
}

public ServerSideMetricsInternal ServerSideMetricsInternal { get; }
Expand All @@ -36,5 +38,7 @@ internal ServerSidePartitionedMetricsInternal(ServerSideMetricsInternal serverSi
public override string FeedRange { get; }

public override int? PartitionKeyRangeId { get; }

public override double? RequestCharge { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
using System.Reflection;
using System.Text.RegularExpressions;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Cosmos.Query.Core.Metrics;

[TestClass]
public class CosmosItemTests : BaseCosmosClientHelper
Expand Down Expand Up @@ -1287,6 +1286,7 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max

ServerSideCumulativeMetrics metrics = response.Diagnostics.GetQueryMetrics();
Assert.IsTrue(metrics.PartitionedMetrics.Count > 0);
Assert.IsTrue(metrics.PartitionedMetrics[0].RequestCharge > 0);
Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero);
Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTime > TimeSpan.Zero);

Expand Down Expand Up @@ -1381,6 +1381,7 @@ public async Task ItemMultiplePartitionQuery()
{
Assert.IsNotNull(partitionedMetrics);
Assert.IsNotNull(partitionedMetrics.PartitionKeyRangeId);
Assert.IsTrue(partitionedMetrics.RequestCharge > 0);
}

if (metrics.CumulativeMetrics.RetrievedDocumentCount >= 1)
Expand Down Expand Up @@ -1460,6 +1461,7 @@ public async Task ItemSinglePartitionQueryGateway()
{
Assert.IsNotNull(partitionedMetrics);
Assert.IsNull(partitionedMetrics.PartitionKeyRangeId);
Assert.IsTrue(partitionedMetrics.RequestCharge > 0);
}

if (metrics.CumulativeMetrics.RetrievedDocumentCount >= 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9397,6 +9397,16 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.Double] get_RequestCharge()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "System.Nullable`1[System.Double] get_RequestCharge();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.Double] RequestCharge": {
"Type": "Property",
"Attributes": [],
"MethodInfo": "System.Nullable`1[System.Double] RequestCharge;CanRead:True;CanWrite:False;System.Nullable`1[System.Double] get_RequestCharge();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.Int32] get_PartitionKeyRangeId()": {
"Type": "Method",
"Attributes": [],
Expand Down