From f440f1b175558895da7836c3f2bd77fc87595a0d Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 20 Jul 2023 20:00:38 -0700 Subject: [PATCH 01/43] initial commit --- .../src/Diagnostics/CosmosDiagnostics.cs | 10 ++ .../src/Diagnostics/CosmosTraceDiagnostics.cs | 32 ++++ .../Core/Metrics/BackendAccumulatedMetrics.cs | 140 ++++++++++++++++++ .../Core/Metrics/RuntimeExecutionTimes.cs | 6 +- .../Metrics/BackendAccumulatedMetricsTests.cs | 13 ++ 5 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs create mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs index cb3ffe6c04..4c753b0b27 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs @@ -43,6 +43,16 @@ public virtual int GetFailedRequestCount() throw new NotImplementedException($"{nameof(CosmosDiagnostics)}.{nameof(GetFailedRequestCount)}"); } + /// + /// This represents the accumulated backend query metrics for the request. + /// + /// The string represemation of the query metrics dictionary. + public virtual BackendAccumulatedMetrics GetQueryMetrics() + { + // Default implementation avoids breaking change for users upgrading. + throw new NotImplementedException($"{nameof(CosmosDiagnostics)}.{nameof(GetQueryMetrics)}"); + } + /// /// Gets the string field instance in the Azure CosmosDB database service. /// diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 07e340f0ac..5c610de166 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -9,6 +9,7 @@ namespace Microsoft.Azure.Cosmos.Diagnostics using System.Linq; using System.Text; using Microsoft.Azure.Cosmos.Json; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; using Microsoft.Azure.Cosmos.Tracing; using Microsoft.Azure.Cosmos.Tracing.TraceData; using static Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum; @@ -49,11 +50,42 @@ public override TimeSpan GetClientElapsedTime() return this.Value?.Summary?.RegionsContacted; } + public override BackendAccumulatedMetrics GetQueryMetrics() + { + QueryMetrics queryMetrics = QueryMetrics.Empty; + this.WalkTraceTreeForQueryMetrics(this.Value, ref queryMetrics); + return new BackendAccumulatedMetrics(queryMetrics); + } + internal bool IsGoneExceptionHit() { return this.WalkTraceTreeForGoneException(this.Value); } + private bool WalkTraceTreeForQueryMetrics(ITrace currentTrace, ref QueryMetrics queryMetrics) + { + if (currentTrace == null) + { + return false; + } + + foreach (object datums in currentTrace.Data.Values) + { + if (datums is QueryMetricsTraceDatum queryMetricsTraceDatum) + { + queryMetrics += queryMetricsTraceDatum.QueryMetrics; + return true; + } + } + + foreach (ITrace childTrace in currentTrace.Children) + { + this.WalkTraceTreeForQueryMetrics(childTrace, ref queryMetrics); + } + + return false; + } + private bool WalkTraceTreeForGoneException(ITrace currentTrace) { if (currentTrace == null) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs new file mode 100644 index 0000000000..b377e6b713 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs @@ -0,0 +1,140 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos +{ + using System; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; + + /// + /// Exposed metrics received for queries from the backend. + /// + public sealed class BackendAccumulatedMetrics + { + internal BackendAccumulatedMetrics(QueryMetrics queryMetrics) + { + this.RetrievedDocumentCount = queryMetrics.BackendMetrics.RetrievedDocumentCount; + this.RetrievedDocumentSize = queryMetrics.BackendMetrics.RetrievedDocumentSize; + this.OutputDocumentCount = queryMetrics.BackendMetrics.OutputDocumentCount; + this.OutputDocumentSize = queryMetrics.BackendMetrics.OutputDocumentSize; + this.IndexHitRatio = queryMetrics.BackendMetrics.IndexHitRatio; + this.TotalTime = queryMetrics.BackendMetrics.TotalTime; + this.QueryCompilationTime = queryMetrics.BackendMetrics.QueryPreparationTimes.QueryCompilationTime; + this.LogicalPlanBuildTime = queryMetrics.BackendMetrics.QueryPreparationTimes.LogicalPlanBuildTime; + this.PhysicalPlanBuildTime = queryMetrics.BackendMetrics.QueryPreparationTimes.PhysicalPlanBuildTime; + this.QueryOptimizationTime = queryMetrics.BackendMetrics.QueryPreparationTimes.QueryOptimizationTime; + this.IndexLookupTime = queryMetrics.BackendMetrics.IndexLookupTime; + this.DocumentLoadTime = queryMetrics.BackendMetrics.DocumentLoadTime; + this.VMExecutionTime = queryMetrics.BackendMetrics.VMExecutionTime; + this.SystemFunctionExecutionTime = queryMetrics.BackendMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime; + this.UserDefinedFunctionExecutionTime = queryMetrics.BackendMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime; + this.QueryEngineExecutionTime = queryMetrics.BackendMetrics.RuntimeExecutionTimes.QueryEngineExecutionTime; + this.DocumentWriteTime = queryMetrics.BackendMetrics.DocumentWriteTime; + } + + /// + /// Gets the total query time in the Azure Cosmos database service. + /// + public TimeSpan TotalTime { get; } + + /// + /// Gets the query compile time in the Azure DocumentDB database service. + /// + public TimeSpan QueryCompilationTime { get; } + + /// + /// Gets the query logical plan build time in the Azure DocumentDB database service. + /// + public TimeSpan LogicalPlanBuildTime { get; } + + /// + /// Gets the query physical plan build time in the Azure DocumentDB database service. + /// + public TimeSpan PhysicalPlanBuildTime { get; } + + /// + /// Gets the query optimization time in the Azure DocumentDB database service. + /// + public TimeSpan QueryOptimizationTime { get; } + + /// + /// Gets the number of documents retrieved during query in the Azure Cosmos database service. + /// + public long RetrievedDocumentCount { get; } + + /// + /// Gets the size of documents retrieved in bytes during query in the Azure Cosmos DB service. + /// + public long RetrievedDocumentSize { get; } + + /// + /// Gets the number of documents returned by query in the Azure Cosmos DB service. + /// + public long OutputDocumentCount { get; } + + /// + /// Gets the size of documents outputted in bytes during query in the Azure Cosmos database service. + /// + public long OutputDocumentSize { get; } + + /// + /// Gets the query QueryPreparationTimes in the Azure Cosmos database service. + /// + public TimeSpan QueryPreparationTimes { get; } + + /// + /// Gets the query index lookup time in the Azure Cosmos database service. + /// + public TimeSpan IndexLookupTime { get; } + + /// + /// Gets the document loading time during query in the Azure Cosmos database service. + /// + public TimeSpan DocumentLoadTime { get; } + + /// + /// Gets the query runtime execution times during query in the Azure Cosmos database service. + /// + public TimeSpan RuntimeExecutionTimes { get; } + + /// + /// Gets the output writing/serializing time during query in the Azure Cosmos database service. + /// + public TimeSpan DocumentWriteTime { get; } + + /// + /// Gets the index hit ratio by query in the Azure Cosmos database service. + /// + public double IndexHitRatio { get; } + + /// + /// Gets the VMExecution Time. + /// + public TimeSpan VMExecutionTime { get; } + + /// + /// Gets the query system function execution time in the Azure Cosmos DB service. + /// + public TimeSpan SystemFunctionExecutionTime { get; } + + /// + /// Gets the query user defined function execution time in the Azure Cosmos DB service. + /// + public TimeSpan UserDefinedFunctionExecutionTime { get; } + + /// + /// Gets the total query runtime execution time in the Azure Cosmos DB service. + /// + public TimeSpan QueryEngineExecutionTime { get; } + + /// + /// String representation of the QueryBackendMetrics. + /// + /// Metric text + public override string ToString() + { + return $"totalExecutionTimeInMs={this.TotalTime.TotalMilliseconds};queryCompileTimeInMs={this.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={this.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={this.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={this.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={this.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={this.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={this.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={this.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={this.RetrievedDocumentCount};retrievedDocumentSize={this.RetrievedDocumentSize};outputDocumentCount={this.OutputDocumentCount};outputDocumentSize={this.OutputDocumentSize};writeOutputTimeInMs={this.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={this.IndexHitRatio}"; + } + + } +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs index 0fd8dc22f0..9a4dadc6f3 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs @@ -62,9 +62,9 @@ public Accumulator(TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExe this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTimes; } - public TimeSpan QueryEngineExecutionTime { get; set; } - public TimeSpan SystemFunctionExecutionTime { get; set; } - public TimeSpan UserDefinedFunctionExecutionTime { get; set; } + public TimeSpan QueryEngineExecutionTime { get; } + public TimeSpan SystemFunctionExecutionTime { get; } + public TimeSpan UserDefinedFunctionExecutionTime { get; } public Accumulator Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs new file mode 100644 index 0000000000..7b05c1fd71 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs @@ -0,0 +1,13 @@ +namespace Microsoft.Azure.Cosmos.Tests.Query.Metrics +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + + internal class BackendAccumulatedMetricsTests + { + //TODO + } +} From b287e27542663a1913163b46eefa93ac496a5a87 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 21 Jul 2023 16:38:54 -0700 Subject: [PATCH 02/43] some pr comments, WIP --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 5c610de166..b44edc8325 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -62,19 +62,19 @@ internal bool IsGoneExceptionHit() return this.WalkTraceTreeForGoneException(this.Value); } - private bool WalkTraceTreeForQueryMetrics(ITrace currentTrace, ref QueryMetrics queryMetrics) + private void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ref QueryMetrics queryMetrics) { if (currentTrace == null) { - return false; + return; } - foreach (object datums in currentTrace.Data.Values) + foreach (object datum in currentTrace.Data.Values) { - if (datums is QueryMetricsTraceDatum queryMetricsTraceDatum) + if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) { queryMetrics += queryMetricsTraceDatum.QueryMetrics; - return true; + return; } } @@ -83,7 +83,7 @@ private bool WalkTraceTreeForQueryMetrics(ITrace currentTrace, ref QueryMetrics this.WalkTraceTreeForQueryMetrics(childTrace, ref queryMetrics); } - return false; + return; } private bool WalkTraceTreeForGoneException(ITrace currentTrace) @@ -93,9 +93,9 @@ private bool WalkTraceTreeForGoneException(ITrace currentTrace) return false; } - foreach (object datums in currentTrace.Data.Values) + foreach (object datum in currentTrace.Data.Values) { - if (datums is ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum) + if (datum is ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum) { foreach (StoreResponseStatistics responseStatistics in clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList) { From 82b9871ec6ef004e1ee54cc4d6f5f9fef6ec26eb Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 24 Jul 2023 13:57:55 -0700 Subject: [PATCH 03/43] Refactor --- .../src/Diagnostics/CosmosDiagnostics.cs | 3 +- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 21 ++- .../Core/Metrics/BackendAccumulatedMetrics.cs | 140 ------------------ .../src/Query/Core/Metrics/BackendMetrics.cs | 27 ++-- .../Core/Metrics/QueryPreparationTimes.cs | 13 +- .../Core/Metrics/RuntimeExecutionTimes.cs | 13 +- .../Metrics/BackendAccumulatedMetricsTests.cs | 13 -- 7 files changed, 30 insertions(+), 200 deletions(-) delete mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs delete mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs index 4c753b0b27..43b5224837 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs @@ -5,6 +5,7 @@ namespace Microsoft.Azure.Cosmos { using System; using System.Collections.Generic; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Contains the cosmos diagnostic information for the current request to Azure Cosmos DB service. @@ -47,7 +48,7 @@ public virtual int GetFailedRequestCount() /// This represents the accumulated backend query metrics for the request. /// /// The string represemation of the query metrics dictionary. - public virtual BackendAccumulatedMetrics GetQueryMetrics() + public virtual BackendMetrics GetQueryMetrics() { // Default implementation avoids breaking change for users upgrading. throw new NotImplementedException($"{nameof(CosmosDiagnostics)}.{nameof(GetQueryMetrics)}"); diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index b44edc8325..03e7859a7e 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -6,7 +6,6 @@ namespace Microsoft.Azure.Cosmos.Diagnostics { using System; using System.Collections.Generic; - using System.Linq; using System.Text; using Microsoft.Azure.Cosmos.Json; using Microsoft.Azure.Cosmos.Query.Core.Metrics; @@ -50,11 +49,11 @@ public override TimeSpan GetClientElapsedTime() return this.Value?.Summary?.RegionsContacted; } - public override BackendAccumulatedMetrics GetQueryMetrics() + public override BackendMetrics GetQueryMetrics() { - QueryMetrics queryMetrics = QueryMetrics.Empty; - this.WalkTraceTreeForQueryMetrics(this.Value, ref queryMetrics); - return new BackendAccumulatedMetrics(queryMetrics); + BackendMetrics.Accumulator accumulator = this.WalkTraceTreeForQueryMetrics(this.Value, new BackendMetrics.Accumulator()); + return BackendMetrics.Accumulator.ToBackendMetrics(accumulator); + } internal bool IsGoneExceptionHit() @@ -62,28 +61,28 @@ internal bool IsGoneExceptionHit() return this.WalkTraceTreeForGoneException(this.Value); } - private void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ref QueryMetrics queryMetrics) + private BackendMetrics.Accumulator WalkTraceTreeForQueryMetrics(ITrace currentTrace, BackendMetrics.Accumulator accumulator) { if (currentTrace == null) { - return; + return accumulator; } foreach (object datum in currentTrace.Data.Values) { if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) { - queryMetrics += queryMetricsTraceDatum.QueryMetrics; - return; + accumulator = accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.BackendMetrics); + return accumulator; } } foreach (ITrace childTrace in currentTrace.Children) { - this.WalkTraceTreeForQueryMetrics(childTrace, ref queryMetrics); + accumulator = this.WalkTraceTreeForQueryMetrics(childTrace, accumulator); } - return; + return accumulator; } private bool WalkTraceTreeForGoneException(ITrace currentTrace) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs deleted file mode 100644 index b377e6b713..0000000000 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendAccumulatedMetrics.cs +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ -namespace Microsoft.Azure.Cosmos -{ - using System; - using Microsoft.Azure.Cosmos.Query.Core.Metrics; - - /// - /// Exposed metrics received for queries from the backend. - /// - public sealed class BackendAccumulatedMetrics - { - internal BackendAccumulatedMetrics(QueryMetrics queryMetrics) - { - this.RetrievedDocumentCount = queryMetrics.BackendMetrics.RetrievedDocumentCount; - this.RetrievedDocumentSize = queryMetrics.BackendMetrics.RetrievedDocumentSize; - this.OutputDocumentCount = queryMetrics.BackendMetrics.OutputDocumentCount; - this.OutputDocumentSize = queryMetrics.BackendMetrics.OutputDocumentSize; - this.IndexHitRatio = queryMetrics.BackendMetrics.IndexHitRatio; - this.TotalTime = queryMetrics.BackendMetrics.TotalTime; - this.QueryCompilationTime = queryMetrics.BackendMetrics.QueryPreparationTimes.QueryCompilationTime; - this.LogicalPlanBuildTime = queryMetrics.BackendMetrics.QueryPreparationTimes.LogicalPlanBuildTime; - this.PhysicalPlanBuildTime = queryMetrics.BackendMetrics.QueryPreparationTimes.PhysicalPlanBuildTime; - this.QueryOptimizationTime = queryMetrics.BackendMetrics.QueryPreparationTimes.QueryOptimizationTime; - this.IndexLookupTime = queryMetrics.BackendMetrics.IndexLookupTime; - this.DocumentLoadTime = queryMetrics.BackendMetrics.DocumentLoadTime; - this.VMExecutionTime = queryMetrics.BackendMetrics.VMExecutionTime; - this.SystemFunctionExecutionTime = queryMetrics.BackendMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime; - this.UserDefinedFunctionExecutionTime = queryMetrics.BackendMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime; - this.QueryEngineExecutionTime = queryMetrics.BackendMetrics.RuntimeExecutionTimes.QueryEngineExecutionTime; - this.DocumentWriteTime = queryMetrics.BackendMetrics.DocumentWriteTime; - } - - /// - /// Gets the total query time in the Azure Cosmos database service. - /// - public TimeSpan TotalTime { get; } - - /// - /// Gets the query compile time in the Azure DocumentDB database service. - /// - public TimeSpan QueryCompilationTime { get; } - - /// - /// Gets the query logical plan build time in the Azure DocumentDB database service. - /// - public TimeSpan LogicalPlanBuildTime { get; } - - /// - /// Gets the query physical plan build time in the Azure DocumentDB database service. - /// - public TimeSpan PhysicalPlanBuildTime { get; } - - /// - /// Gets the query optimization time in the Azure DocumentDB database service. - /// - public TimeSpan QueryOptimizationTime { get; } - - /// - /// Gets the number of documents retrieved during query in the Azure Cosmos database service. - /// - public long RetrievedDocumentCount { get; } - - /// - /// Gets the size of documents retrieved in bytes during query in the Azure Cosmos DB service. - /// - public long RetrievedDocumentSize { get; } - - /// - /// Gets the number of documents returned by query in the Azure Cosmos DB service. - /// - public long OutputDocumentCount { get; } - - /// - /// Gets the size of documents outputted in bytes during query in the Azure Cosmos database service. - /// - public long OutputDocumentSize { get; } - - /// - /// Gets the query QueryPreparationTimes in the Azure Cosmos database service. - /// - public TimeSpan QueryPreparationTimes { get; } - - /// - /// Gets the query index lookup time in the Azure Cosmos database service. - /// - public TimeSpan IndexLookupTime { get; } - - /// - /// Gets the document loading time during query in the Azure Cosmos database service. - /// - public TimeSpan DocumentLoadTime { get; } - - /// - /// Gets the query runtime execution times during query in the Azure Cosmos database service. - /// - public TimeSpan RuntimeExecutionTimes { get; } - - /// - /// Gets the output writing/serializing time during query in the Azure Cosmos database service. - /// - public TimeSpan DocumentWriteTime { get; } - - /// - /// Gets the index hit ratio by query in the Azure Cosmos database service. - /// - public double IndexHitRatio { get; } - - /// - /// Gets the VMExecution Time. - /// - public TimeSpan VMExecutionTime { get; } - - /// - /// Gets the query system function execution time in the Azure Cosmos DB service. - /// - public TimeSpan SystemFunctionExecutionTime { get; } - - /// - /// Gets the query user defined function execution time in the Azure Cosmos DB service. - /// - public TimeSpan UserDefinedFunctionExecutionTime { get; } - - /// - /// Gets the total query runtime execution time in the Azure Cosmos DB service. - /// - public TimeSpan QueryEngineExecutionTime { get; } - - /// - /// String representation of the QueryBackendMetrics. - /// - /// Metric text - public override string ToString() - { - return $"totalExecutionTimeInMs={this.TotalTime.TotalMilliseconds};queryCompileTimeInMs={this.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={this.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={this.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={this.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={this.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={this.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={this.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={this.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={this.RetrievedDocumentCount};retrievedDocumentSize={this.RetrievedDocumentSize};outputDocumentCount={this.OutputDocumentCount};outputDocumentSize={this.OutputDocumentSize};writeOutputTimeInMs={this.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={this.IndexHitRatio}"; - } - - } -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs index e958aee949..8a4192e437 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs @@ -10,19 +10,12 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// /// Metrics received for queries from the backend. /// -#if INTERNAL -#pragma warning disable SA1600 -#pragma warning disable CS1591 - public -#else - internal -#endif - sealed class BackendMetrics + public sealed class BackendMetrics { /// /// QueryMetrics that with all members having default (but not null) members. /// - public static readonly BackendMetrics Empty = new BackendMetrics( + internal static readonly BackendMetrics Empty = new BackendMetrics( retrievedDocumentCount: default, retrievedDocumentSize: default, outputDocumentCount: default, @@ -36,7 +29,7 @@ sealed class BackendMetrics runtimeExecutionTimes: RuntimeExecutionTimes.Empty, documentWriteTime: default); - public BackendMetrics( + internal BackendMetrics( long retrievedDocumentCount, long retrievedDocumentSize, long outputDocumentCount, @@ -124,12 +117,16 @@ public BackendMetrics( /// public TimeSpan VMExecutionTime { get; } - public override string ToString() + /// + /// String representation of BackendMetric. + /// + /// BackendMetric text + public override string ToString() //todo move this logic elsewhere? { return $"totalExecutionTimeInMs={this.TotalTime.TotalMilliseconds};queryCompileTimeInMs={this.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={this.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={this.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={this.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={this.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={this.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={this.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={this.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={this.RetrievedDocumentCount};retrievedDocumentSize={this.RetrievedDocumentSize};outputDocumentCount={this.OutputDocumentCount};outputDocumentSize={this.OutputDocumentSize};writeOutputTimeInMs={this.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={this.IndexHitRatio}"; } - public static BackendMetrics CreateFromIEnumerable(IEnumerable backendMetricsEnumerable) + internal static BackendMetrics CreateFromIEnumerable(IEnumerable backendMetricsEnumerable) { BackendMetrics.Accumulator accumulator = default; foreach (BackendMetrics backendMetrics in backendMetricsEnumerable) @@ -140,12 +137,12 @@ public static BackendMetrics CreateFromIEnumerable(IEnumerable b return BackendMetrics.Accumulator.ToBackendMetrics(accumulator); } - public static bool TryParseFromDelimitedString(string delimitedString, out BackendMetrics backendMetrics) + internal static bool TryParseFromDelimitedString(string delimitedString, out BackendMetrics backendMetrics) { return BackendMetricsParser.TryParse(delimitedString, out backendMetrics); } - public static BackendMetrics ParseFromDelimitedString(string delimitedString) + internal static BackendMetrics ParseFromDelimitedString(string delimitedString) { if (!BackendMetricsParser.TryParse(delimitedString, out BackendMetrics backendMetrics)) { @@ -155,7 +152,7 @@ public static BackendMetrics ParseFromDelimitedString(string delimitedString) return backendMetrics; } - public ref struct Accumulator + internal ref struct Accumulator { public Accumulator( TimeSpan totalTime, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs index 4b2d3b1b20..8699f0126e 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs @@ -8,16 +8,9 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// /// Query preparation metrics in the Azure DocumentDB database service. /// -#if INTERNAL -#pragma warning disable SA1600 -#pragma warning disable CS1591 - public -#else - internal -#endif - sealed class QueryPreparationTimes + public sealed class QueryPreparationTimes { - public static readonly QueryPreparationTimes Zero = new QueryPreparationTimes( + internal static readonly QueryPreparationTimes Zero = new QueryPreparationTimes( queryCompilationTime: default, logicalPlanBuildTime: default, physicalPlanBuildTime: default, @@ -62,7 +55,7 @@ public QueryPreparationTimes( /// public TimeSpan QueryOptimizationTime { get; } - public ref struct Accumulator + internal ref struct Accumulator { public Accumulator(TimeSpan queryCompliationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, TimeSpan queryOptimizationTime) { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs index 9a4dadc6f3..6735a0bc71 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs @@ -8,16 +8,9 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// /// Query runtime execution times in the Azure Cosmos DB service. /// -#if INTERNAL -#pragma warning disable SA1600 -#pragma warning disable CS1591 - public -#else - internal -#endif - sealed class RuntimeExecutionTimes + public sealed class RuntimeExecutionTimes { - public static readonly RuntimeExecutionTimes Empty = new RuntimeExecutionTimes( + internal static readonly RuntimeExecutionTimes Empty = new RuntimeExecutionTimes( queryEngineExecutionTime: default, systemFunctionExecutionTime: default, userDefinedFunctionExecutionTime: default); @@ -53,7 +46,7 @@ public RuntimeExecutionTimes( /// public TimeSpan UserDefinedFunctionExecutionTime { get; } - public ref struct Accumulator + internal ref struct Accumulator { public Accumulator(TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTimes) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs deleted file mode 100644 index 7b05c1fd71..0000000000 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendAccumulatedMetricsTests.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Microsoft.Azure.Cosmos.Tests.Query.Metrics -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - internal class BackendAccumulatedMetricsTests - { - //TODO - } -} From 17705608f1bf347dc160dac294c2b95fddde891b Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 24 Jul 2023 14:15:39 -0700 Subject: [PATCH 04/43] more --- Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs | 2 +- .../src/Query/Core/Metrics/QueryPreparationTimes.cs | 2 +- .../src/Query/Core/Metrics/RuntimeExecutionTimes.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs index 43b5224837..412ee95460 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs @@ -47,7 +47,7 @@ public virtual int GetFailedRequestCount() /// /// This represents the accumulated backend query metrics for the request. /// - /// The string represemation of the query metrics dictionary. + /// The accumulated backend metrics for the request. public virtual BackendMetrics GetQueryMetrics() { // Default implementation avoids breaking change for users upgrading. diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs index 8699f0126e..0ca78ea9dc 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs @@ -23,7 +23,7 @@ public sealed class QueryPreparationTimes /// Query logical plan build time /// Query physical plan build time /// Query optimization time - public QueryPreparationTimes( + internal QueryPreparationTimes( TimeSpan queryCompilationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs index 6735a0bc71..4c74cbb703 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs @@ -21,7 +21,7 @@ public sealed class RuntimeExecutionTimes /// Query end - to - end execution time /// Total time spent executing system functions /// Total time spent executing user - defined functions - public RuntimeExecutionTimes( + internal RuntimeExecutionTimes( TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTime) From 6fa6e2a93d04c773e3247dfeb616ce6091500c59 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 25 Jul 2023 22:56:21 -0700 Subject: [PATCH 05/43] Public constructors and modify accumulators --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 29 +---- .../src/Query/Core/Metrics/BackendMetrics.cs | 104 ++++------------ .../Core/Metrics/BackendMetricsAccumulator.cs | 111 ++++++++++++++++++ .../Query/Core/Metrics/ClientSideMetrics.cs | 37 ------ .../Metrics/ClientSideMetricsAccumulator.cs | 47 ++++++++ .../Core/Metrics/IndexUtilizationInfo.cs | 38 ------ .../IndexUtilizationInfoAccumulator.cs | 47 ++++++++ .../src/Query/Core/Metrics/QueryMetrics.cs | 35 +++--- .../Core/Metrics/QueryPreparationTimes.cs | 41 +------ .../QueryPreparationTimesAccumulator.cs | 46 ++++++++ .../Core/Metrics/RuntimeExecutionTimes.cs | 37 +----- .../RuntimeExecutionTimesAccumulator.cs | 41 +++++++ .../Query/Metrics/BackendMetricsTests.cs | 20 ++-- .../Query/Metrics/ClientSideMetricsTests.cs | 8 +- .../Metrics/IndexUtilizationInfoTests.cs | 9 +- .../Query/Metrics/QueryMetricsTests.cs | 4 +- 16 files changed, 354 insertions(+), 300 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 03e7859a7e..60f72b2896 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -51,8 +51,9 @@ public override TimeSpan GetClientElapsedTime() public override BackendMetrics GetQueryMetrics() { - BackendMetrics.Accumulator accumulator = this.WalkTraceTreeForQueryMetrics(this.Value, new BackendMetrics.Accumulator()); - return BackendMetrics.Accumulator.ToBackendMetrics(accumulator); + BackendMetricsAccumulator accumulator = new BackendMetricsAccumulator(); + BackendMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); + return BackendMetricsAccumulator.ToBackendMetrics(accumulator); } @@ -61,30 +62,6 @@ internal bool IsGoneExceptionHit() return this.WalkTraceTreeForGoneException(this.Value); } - private BackendMetrics.Accumulator WalkTraceTreeForQueryMetrics(ITrace currentTrace, BackendMetrics.Accumulator accumulator) - { - if (currentTrace == null) - { - return accumulator; - } - - foreach (object datum in currentTrace.Data.Values) - { - if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) - { - accumulator = accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.BackendMetrics); - return accumulator; - } - } - - foreach (ITrace childTrace in currentTrace.Children) - { - accumulator = this.WalkTraceTreeForQueryMetrics(childTrace, accumulator); - } - - return accumulator; - } - private bool WalkTraceTreeForGoneException(ITrace currentTrace) { if (currentTrace == null) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs index 8a4192e437..fd8a79cb75 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs @@ -29,7 +29,22 @@ public sealed class BackendMetrics runtimeExecutionTimes: RuntimeExecutionTimes.Empty, documentWriteTime: default); - internal BackendMetrics( + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public BackendMetrics( long retrievedDocumentCount, long retrievedDocumentSize, long outputDocumentCount, @@ -128,13 +143,13 @@ public override string ToString() //todo move this logic elsewhere? internal static BackendMetrics CreateFromIEnumerable(IEnumerable backendMetricsEnumerable) { - BackendMetrics.Accumulator accumulator = default; + BackendMetricsAccumulator accumulator = default; foreach (BackendMetrics backendMetrics in backendMetricsEnumerable) { - accumulator = accumulator.Accumulate(backendMetrics); + accumulator.Accumulate(backendMetrics); } - return BackendMetrics.Accumulator.ToBackendMetrics(accumulator); + return BackendMetricsAccumulator.ToBackendMetrics(accumulator); } internal static bool TryParseFromDelimitedString(string delimitedString, out BackendMetrics backendMetrics) @@ -150,85 +165,6 @@ internal static BackendMetrics ParseFromDelimitedString(string delimitedString) } return backendMetrics; - } - - internal ref struct Accumulator - { - public Accumulator( - TimeSpan totalTime, - long retrievedDocumentCount, - long retrievedDocumentSize, - long outputDocumentCount, - long outputDocumentSize, - double indexHitRatio, - QueryPreparationTimes.Accumulator queryPreparationTimesAccumulator, - TimeSpan indexLookupTime, - TimeSpan documentLoadTime, - RuntimeExecutionTimes.Accumulator runtimeExecutionTimesAccumulator, - TimeSpan documentWriteTime, - TimeSpan vmExecutionTime) - { - this.TotalTime = totalTime; - this.RetrievedDocumentCount = retrievedDocumentCount; - this.RetrievedDocumentSize = retrievedDocumentSize; - this.OutputDocumentCount = outputDocumentCount; - this.OutputDocumentSize = outputDocumentSize; - this.IndexHitRatio = indexHitRatio; - this.QueryPreparationTimesAccumulator = queryPreparationTimesAccumulator; - this.IndexLookupTime = indexLookupTime; - this.DocumentLoadTime = documentLoadTime; - this.RuntimeExecutionTimesAccumulator = runtimeExecutionTimesAccumulator; - this.DocumentWriteTime = documentWriteTime; - this.VMExecutionTime = vmExecutionTime; - } - - public TimeSpan TotalTime { get; } - public long RetrievedDocumentCount { get; } - public long RetrievedDocumentSize { get; } - public long OutputDocumentCount { get; } - public long OutputDocumentSize { get; } - public double IndexHitRatio { get; } - public QueryPreparationTimes.Accumulator QueryPreparationTimesAccumulator { get; } - public TimeSpan IndexLookupTime { get; } - public TimeSpan DocumentLoadTime { get; } - public RuntimeExecutionTimes.Accumulator RuntimeExecutionTimesAccumulator { get; } - public TimeSpan DocumentWriteTime { get; } - public TimeSpan VMExecutionTime { get; } - - public Accumulator Accumulate(BackendMetrics backendMetrics) - { - return new Accumulator( - totalTime: this.TotalTime + backendMetrics.TotalTime, - retrievedDocumentCount: this.RetrievedDocumentCount + backendMetrics.RetrievedDocumentCount, - retrievedDocumentSize: this.RetrievedDocumentSize + backendMetrics.RetrievedDocumentSize, - outputDocumentCount: this.OutputDocumentCount + backendMetrics.OutputDocumentCount, - outputDocumentSize: this.OutputDocumentSize + backendMetrics.OutputDocumentSize, - indexHitRatio: ((this.OutputDocumentCount * this.IndexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (this.RetrievedDocumentCount + backendMetrics.RetrievedDocumentCount), - queryPreparationTimesAccumulator: this.QueryPreparationTimesAccumulator.Accumulate(backendMetrics.QueryPreparationTimes), - indexLookupTime: this.IndexLookupTime + backendMetrics.IndexLookupTime, - documentLoadTime: this.DocumentLoadTime + backendMetrics.DocumentLoadTime, - runtimeExecutionTimesAccumulator: this.RuntimeExecutionTimesAccumulator.Accumulate(backendMetrics.RuntimeExecutionTimes), - documentWriteTime: this.DocumentWriteTime + backendMetrics.DocumentWriteTime, - vmExecutionTime: this.VMExecutionTime + backendMetrics.VMExecutionTime); - - } - - public static BackendMetrics ToBackendMetrics(BackendMetrics.Accumulator accumulator) - { - return new BackendMetrics( - retrievedDocumentCount: accumulator.RetrievedDocumentCount, - retrievedDocumentSize: accumulator.RetrievedDocumentSize, - outputDocumentCount: accumulator.OutputDocumentCount, - outputDocumentSize: accumulator.OutputDocumentSize, - indexHitRatio: accumulator.IndexHitRatio, - totalQueryExecutionTime: accumulator.TotalTime, - queryPreparationTimes: QueryPreparationTimes.Accumulator.ToQueryPreparationTimes(accumulator.QueryPreparationTimesAccumulator), - indexLookupTime: accumulator.IndexLookupTime, - documentLoadTime: accumulator.DocumentLoadTime, - vmExecutionTime: accumulator.VMExecutionTime, - runtimeExecutionTimes: RuntimeExecutionTimes.Accumulator.ToRuntimeExecutionTimes(accumulator.RuntimeExecutionTimesAccumulator), - documentWriteTime: accumulator.DocumentWriteTime); - } - } + } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs new file mode 100644 index 0000000000..22120195a5 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs @@ -0,0 +1,111 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + using Microsoft.Azure.Cosmos.Tracing; + using Microsoft.Azure.Cosmos.Tracing.TraceData; + + internal ref struct BackendMetricsAccumulator + { + public BackendMetricsAccumulator( + TimeSpan totalTime, + long retrievedDocumentCount, + long retrievedDocumentSize, + long outputDocumentCount, + long outputDocumentSize, + double indexHitRatio, + QueryPreparationTimesAccumulator queryPreparationTimesAccumulator, + TimeSpan indexLookupTime, + TimeSpan documentLoadTime, + RuntimeExecutionTimesAccumulator runtimeExecutionTimesAccumulator, + TimeSpan documentWriteTime, + TimeSpan vmExecutionTime) + { + this.TotalTime = totalTime; + this.RetrievedDocumentCount = retrievedDocumentCount; + this.RetrievedDocumentSize = retrievedDocumentSize; + this.OutputDocumentCount = outputDocumentCount; + this.OutputDocumentSize = outputDocumentSize; + this.IndexHitRatio = indexHitRatio; + this.QueryPreparationTimesAccumulator = queryPreparationTimesAccumulator; + this.IndexLookupTime = indexLookupTime; + this.DocumentLoadTime = documentLoadTime; + this.RuntimeExecutionTimesAccumulator = runtimeExecutionTimesAccumulator; + this.DocumentWriteTime = documentWriteTime; + this.VMExecutionTime = vmExecutionTime; + } + + public TimeSpan TotalTime { get; set; } + public long RetrievedDocumentCount { get; set; } + public long RetrievedDocumentSize { get; set; } + public long OutputDocumentCount { get; set; } + public long OutputDocumentSize { get; set; } + public double IndexHitRatio { get; set; } + public QueryPreparationTimesAccumulator QueryPreparationTimesAccumulator { get; set; } + public TimeSpan IndexLookupTime { get; set; } + public TimeSpan DocumentLoadTime { get; set; } + public RuntimeExecutionTimesAccumulator RuntimeExecutionTimesAccumulator { get; set; } + public TimeSpan DocumentWriteTime { get; set; } + public TimeSpan VMExecutionTime { get; set; } + + public void Accumulate(BackendMetrics backendMetrics) + { + this.TotalTime += backendMetrics.TotalTime; + this.RetrievedDocumentCount += backendMetrics.RetrievedDocumentCount; + this.RetrievedDocumentSize += backendMetrics.RetrievedDocumentSize; + this.OutputDocumentCount += backendMetrics.OutputDocumentCount; + this.OutputDocumentSize += backendMetrics.OutputDocumentSize; + this.IndexHitRatio = ((this.OutputDocumentCount * this.IndexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (this.RetrievedDocumentCount + backendMetrics.RetrievedDocumentCount); + this.QueryPreparationTimesAccumulator.Accumulate(backendMetrics.QueryPreparationTimes); + this.IndexLookupTime += backendMetrics.IndexLookupTime; + this.DocumentLoadTime += backendMetrics.DocumentLoadTime; + this.RuntimeExecutionTimesAccumulator.Accumulate(backendMetrics.RuntimeExecutionTimes); + this.DocumentWriteTime += backendMetrics.DocumentWriteTime; + this.VMExecutionTime += backendMetrics.VMExecutionTime; + } + + public static BackendMetrics ToBackendMetrics(BackendMetricsAccumulator accumulator) + { + return new BackendMetrics( + retrievedDocumentCount: accumulator.RetrievedDocumentCount, + retrievedDocumentSize: accumulator.RetrievedDocumentSize, + outputDocumentCount: accumulator.OutputDocumentCount, + outputDocumentSize: accumulator.OutputDocumentSize, + indexHitRatio: accumulator.IndexHitRatio, + totalQueryExecutionTime: accumulator.TotalTime, + queryPreparationTimes: QueryPreparationTimesAccumulator.ToQueryPreparationTimes(accumulator.QueryPreparationTimesAccumulator), + indexLookupTime: accumulator.IndexLookupTime, + documentLoadTime: accumulator.DocumentLoadTime, + vmExecutionTime: accumulator.VMExecutionTime, + runtimeExecutionTimes: RuntimeExecutionTimesAccumulator.ToRuntimeExecutionTimes(accumulator.RuntimeExecutionTimesAccumulator), + documentWriteTime: accumulator.DocumentWriteTime); + } + + public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, BackendMetricsAccumulator accumulator) + { + if (currentTrace == null) + { + return; + } + + foreach (object datum in currentTrace.Data.Values) + { + if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) + { + accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.BackendMetrics); + return; + } + } + + foreach (ITrace childTrace in currentTrace.Children) + { + WalkTraceTreeForQueryMetrics(childTrace, accumulator); + } + + return; + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs index e69f4c5808..287c433c38 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs @@ -54,42 +54,5 @@ public ClientSideMetrics( /// Gets the Fetch Execution Ranges for this continuation of the query. /// public IEnumerable FetchExecutionRanges { get; } - - public ref struct Accumulator - { - public Accumulator(long retries, double requestCharge, IEnumerable fetchExecutionRanges) - { - this.Retries = retries; - this.RequestCharge = requestCharge; - this.FetchExecutionRanges = fetchExecutionRanges; - } - - public long Retries { get; } - - public double RequestCharge { get; } - - public IEnumerable FetchExecutionRanges { get; } - - public Accumulator Accumulate(ClientSideMetrics clientSideMetrics) - { - if (clientSideMetrics == null) - { - throw new ArgumentNullException(nameof(clientSideMetrics)); - } - - return new Accumulator( - retries: this.Retries + clientSideMetrics.Retries, - requestCharge: this.RequestCharge + clientSideMetrics.RequestCharge, - fetchExecutionRanges: (this.FetchExecutionRanges ?? Enumerable.Empty()).Concat(clientSideMetrics.FetchExecutionRanges)); - } - - public static ClientSideMetrics ToClientSideMetrics(Accumulator accumulator) - { - return new ClientSideMetrics( - retries: accumulator.Retries, - requestCharge: accumulator.RequestCharge, - fetchExecutionRanges: accumulator.FetchExecutionRanges); - } - } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs new file mode 100644 index 0000000000..a5c2399b5f --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + using System.Collections.Generic; + using System.Linq; + + internal ref struct ClientSideMetricsAccumulator + { + public ClientSideMetricsAccumulator(long retries, double requestCharge, IEnumerable fetchExecutionRanges) + { + this.Retries = retries; + this.RequestCharge = requestCharge; + this.FetchExecutionRanges = fetchExecutionRanges; + } + + public long Retries { get; set; } + + public double RequestCharge { get; set; } + + public IEnumerable FetchExecutionRanges { get; set; } + + public void Accumulate(ClientSideMetrics clientSideMetrics) + { + if (clientSideMetrics == null) + { + throw new ArgumentNullException(nameof(clientSideMetrics)); + } + + this.Retries += clientSideMetrics.Retries; + this.RequestCharge += clientSideMetrics.RequestCharge; + this.FetchExecutionRanges = (this.FetchExecutionRanges ?? Enumerable.Empty()).Concat(clientSideMetrics.FetchExecutionRanges); + + return; + } + + public static ClientSideMetrics ToClientSideMetrics(ClientSideMetricsAccumulator accumulator) + { + return new ClientSideMetrics( + retries: accumulator.Retries, + requestCharge: accumulator.RequestCharge, + fetchExecutionRanges: accumulator.FetchExecutionRanges); + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs index 2dba73132e..e34a7902ad 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs @@ -125,43 +125,5 @@ public static IndexUtilizationInfo CreateFromString(string delimitedString, bool return indexUtilizationInfo; } - - public ref struct Accumulator - { - public Accumulator( - IEnumerable utilizedSingleIndexes, - IEnumerable potentialSingleIndexes, - IEnumerable utilizedCompositeIndexes, - IEnumerable potentialCompositeIndexes) - { - this.UtilizedSingleIndexes = utilizedSingleIndexes; - this.PotentialSingleIndexes = potentialSingleIndexes; - this.UtilizedCompositeIndexes = utilizedCompositeIndexes; - this.PotentialCompositeIndexes = potentialCompositeIndexes; - } - - public IEnumerable UtilizedSingleIndexes { get; } - public IEnumerable PotentialSingleIndexes { get; } - public IEnumerable UtilizedCompositeIndexes { get; } - public IEnumerable PotentialCompositeIndexes { get; } - - public Accumulator Accumulate(IndexUtilizationInfo indexUtilizationInfo) - { - return new Accumulator( - utilizedSingleIndexes: (this.UtilizedSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedSingleIndexes), - potentialSingleIndexes: (this.PotentialSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialSingleIndexes), - utilizedCompositeIndexes: (this.UtilizedCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedCompositeIndexes), - potentialCompositeIndexes: (this.PotentialCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialCompositeIndexes)); - } - - public static IndexUtilizationInfo ToIndexUtilizationInfo(Accumulator accumulator) - { - return new IndexUtilizationInfo( - utilizedSingleIndexes: accumulator.UtilizedSingleIndexes.ToList(), - potentialSingleIndexes: accumulator.PotentialSingleIndexes.ToList(), - utilizedCompositeIndexes: accumulator.UtilizedCompositeIndexes.ToList(), - potentialCompositeIndexes: accumulator.PotentialCompositeIndexes.ToList()); - } - } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs new file mode 100644 index 0000000000..1128dc30f4 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System.Collections.Generic; + using System.Linq; + + internal ref struct IndexUtilizationInfoAccumulator + { + public IndexUtilizationInfoAccumulator( + IEnumerable utilizedSingleIndexes, + IEnumerable potentialSingleIndexes, + IEnumerable utilizedCompositeIndexes, + IEnumerable potentialCompositeIndexes) + { + this.UtilizedSingleIndexes = utilizedSingleIndexes; + this.PotentialSingleIndexes = potentialSingleIndexes; + this.UtilizedCompositeIndexes = utilizedCompositeIndexes; + this.PotentialCompositeIndexes = potentialCompositeIndexes; + } + + public IEnumerable UtilizedSingleIndexes { get; set; } + public IEnumerable PotentialSingleIndexes { get; set; } + public IEnumerable UtilizedCompositeIndexes { get; set; } + public IEnumerable PotentialCompositeIndexes { get; set; } + + public void Accumulate(IndexUtilizationInfo indexUtilizationInfo) + { + this.UtilizedSingleIndexes = (this.UtilizedSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedSingleIndexes); + this.PotentialSingleIndexes = (this.PotentialSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialSingleIndexes); + this.UtilizedCompositeIndexes = (this.UtilizedCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedCompositeIndexes); + this.PotentialCompositeIndexes = (this.PotentialCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialCompositeIndexes); + return; + } + + public static IndexUtilizationInfo ToIndexUtilizationInfo(IndexUtilizationInfoAccumulator accumulator) + { + return new IndexUtilizationInfo( + utilizedSingleIndexes: accumulator.UtilizedSingleIndexes.ToList(), + potentialSingleIndexes: accumulator.PotentialSingleIndexes.ToList(), + utilizedCompositeIndexes: accumulator.UtilizedCompositeIndexes.ToList(), + potentialCompositeIndexes: accumulator.PotentialCompositeIndexes.ToList()); + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs index 5a7e9377ed..9ff7a41ce6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs @@ -64,8 +64,8 @@ public QueryMetrics( public static QueryMetrics operator +(QueryMetrics queryMetrics1, QueryMetrics queryMetrics2) { QueryMetrics.Accumulator queryMetricsAccumulator = new QueryMetrics.Accumulator(); - queryMetricsAccumulator = queryMetricsAccumulator.Accumulate(queryMetrics1); - queryMetricsAccumulator = queryMetricsAccumulator.Accumulate(queryMetrics2); + queryMetricsAccumulator.Accumulate(queryMetrics1); + queryMetricsAccumulator.Accumulate(queryMetrics2); return QueryMetrics.Accumulator.ToQueryMetrics(queryMetricsAccumulator); } @@ -97,7 +97,7 @@ public static QueryMetrics CreateFromIEnumerable(IEnumerable query QueryMetrics.Accumulator queryMetricsAccumulator = new QueryMetrics.Accumulator(); foreach (QueryMetrics queryMetrics in queryMetricsList) { - queryMetricsAccumulator = queryMetricsAccumulator.Accumulate(queryMetrics); + queryMetricsAccumulator.Accumulate(queryMetrics); } return QueryMetrics.Accumulator.ToQueryMetrics(queryMetricsAccumulator); @@ -106,40 +106,39 @@ public static QueryMetrics CreateFromIEnumerable(IEnumerable query public ref struct Accumulator { public Accumulator( - BackendMetrics.Accumulator backendMetricsAccumulator, - IndexUtilizationInfo.Accumulator indexUtilizationInfoAccumulator, - ClientSideMetrics.Accumulator clientSideMetricsAccumulator) + BackendMetricsAccumulator backendMetricsAccumulator, + IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator, + ClientSideMetricsAccumulator clientSideMetricsAccumulator) { this.BackendMetricsAccumulator = backendMetricsAccumulator; this.IndexUtilizationInfoAccumulator = indexUtilizationInfoAccumulator; this.ClientSideMetricsAccumulator = clientSideMetricsAccumulator; } - public BackendMetrics.Accumulator BackendMetricsAccumulator { get; } + public BackendMetricsAccumulator BackendMetricsAccumulator { get; } - public IndexUtilizationInfo.Accumulator IndexUtilizationInfoAccumulator { get; } + public IndexUtilizationInfoAccumulator IndexUtilizationInfoAccumulator { get; } - public ClientSideMetrics.Accumulator ClientSideMetricsAccumulator { get; } + public ClientSideMetricsAccumulator ClientSideMetricsAccumulator { get; } - public Accumulator Accumulate(QueryMetrics queryMetrics) + public void Accumulate(QueryMetrics queryMetrics) { if (queryMetrics == null) { throw new ArgumentNullException(nameof(queryMetrics)); } - - return new Accumulator( - backendMetricsAccumulator: this.BackendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics), - indexUtilizationInfoAccumulator: this.IndexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo), - clientSideMetricsAccumulator: this.ClientSideMetricsAccumulator.Accumulate(queryMetrics.ClientSideMetrics)); + + this.BackendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics); + this.IndexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo); + this.ClientSideMetricsAccumulator.Accumulate(queryMetrics.ClientSideMetrics); } public static QueryMetrics ToQueryMetrics(Accumulator accumulator) { return new QueryMetrics( - BackendMetrics.Accumulator.ToBackendMetrics(accumulator.BackendMetricsAccumulator), - IndexUtilizationInfo.Accumulator.ToIndexUtilizationInfo(accumulator.IndexUtilizationInfoAccumulator), - ClientSideMetrics.Accumulator.ToClientSideMetrics(accumulator.ClientSideMetricsAccumulator)); + BackendMetricsAccumulator.ToBackendMetrics(accumulator.BackendMetricsAccumulator), + IndexUtilizationInfoAccumulator.ToIndexUtilizationInfo(accumulator.IndexUtilizationInfoAccumulator), + ClientSideMetricsAccumulator.ToClientSideMetrics(accumulator.ClientSideMetricsAccumulator)); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs index 0ca78ea9dc..0521665b74 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs @@ -23,7 +23,7 @@ public sealed class QueryPreparationTimes /// Query logical plan build time /// Query physical plan build time /// Query optimization time - internal QueryPreparationTimes( + public QueryPreparationTimes( TimeSpan queryCompilationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, @@ -54,44 +54,5 @@ internal QueryPreparationTimes( /// Gets the query optimization time in the Azure DocumentDB database service. /// public TimeSpan QueryOptimizationTime { get; } - - internal ref struct Accumulator - { - public Accumulator(TimeSpan queryCompliationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, TimeSpan queryOptimizationTime) - { - this.QueryCompilationTime = queryCompliationTime; - this.LogicalPlanBuildTime = logicalPlanBuildTime; - this.PhysicalPlanBuildTime = physicalPlanBuildTime; - this.QueryOptimizationTime = queryOptimizationTime; - } - - public TimeSpan QueryCompilationTime { get; } - public TimeSpan LogicalPlanBuildTime { get; } - public TimeSpan PhysicalPlanBuildTime { get; } - public TimeSpan QueryOptimizationTime { get; } - - public Accumulator Accumulate(QueryPreparationTimes queryPreparationTimes) - { - if (queryPreparationTimes == null) - { - throw new ArgumentNullException(nameof(queryPreparationTimes)); - } - - return new Accumulator( - queryCompliationTime: this.QueryCompilationTime + queryPreparationTimes.QueryCompilationTime, - logicalPlanBuildTime: this.LogicalPlanBuildTime + queryPreparationTimes.LogicalPlanBuildTime, - physicalPlanBuildTime: this.PhysicalPlanBuildTime + queryPreparationTimes.PhysicalPlanBuildTime, - queryOptimizationTime: this.QueryOptimizationTime + queryPreparationTimes.QueryOptimizationTime); - } - - public static QueryPreparationTimes ToQueryPreparationTimes(QueryPreparationTimes.Accumulator accumulator) - { - return new QueryPreparationTimes( - queryCompilationTime: accumulator.QueryCompilationTime, - logicalPlanBuildTime: accumulator.LogicalPlanBuildTime, - physicalPlanBuildTime: accumulator.PhysicalPlanBuildTime, - queryOptimizationTime: accumulator.QueryOptimizationTime); - } - } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs new file mode 100644 index 0000000000..12c2a62e32 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs @@ -0,0 +1,46 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + + internal ref struct QueryPreparationTimesAccumulator + { + public QueryPreparationTimesAccumulator(TimeSpan queryCompliationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, TimeSpan queryOptimizationTime) + { + this.QueryCompilationTime = queryCompliationTime; + this.LogicalPlanBuildTime = logicalPlanBuildTime; + this.PhysicalPlanBuildTime = physicalPlanBuildTime; + this.QueryOptimizationTime = queryOptimizationTime; + } + + public TimeSpan QueryCompilationTime { get; set; } + public TimeSpan LogicalPlanBuildTime { get; set; } + public TimeSpan PhysicalPlanBuildTime { get; set; } + public TimeSpan QueryOptimizationTime { get; set; } + + public void Accumulate(QueryPreparationTimes queryPreparationTimes) + { + if (queryPreparationTimes == null) + { + throw new ArgumentNullException(nameof(queryPreparationTimes)); + } + + this.QueryCompilationTime += queryPreparationTimes.QueryCompilationTime; + this.LogicalPlanBuildTime += queryPreparationTimes.LogicalPlanBuildTime; + this.PhysicalPlanBuildTime += queryPreparationTimes.PhysicalPlanBuildTime; + this.QueryOptimizationTime += queryPreparationTimes.QueryOptimizationTime; + } + + public static QueryPreparationTimes ToQueryPreparationTimes(QueryPreparationTimesAccumulator accumulator) + { + return new QueryPreparationTimes( + queryCompilationTime: accumulator.QueryCompilationTime, + logicalPlanBuildTime: accumulator.LogicalPlanBuildTime, + physicalPlanBuildTime: accumulator.PhysicalPlanBuildTime, + queryOptimizationTime: accumulator.QueryOptimizationTime); + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs index 4c74cbb703..f8ca879b63 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs @@ -21,7 +21,7 @@ public sealed class RuntimeExecutionTimes /// Query end - to - end execution time /// Total time spent executing system functions /// Total time spent executing user - defined functions - internal RuntimeExecutionTimes( + public RuntimeExecutionTimes( TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTime) @@ -45,40 +45,5 @@ internal RuntimeExecutionTimes( /// Gets the query user defined function execution time in the Azure Cosmos DB service. /// public TimeSpan UserDefinedFunctionExecutionTime { get; } - - internal ref struct Accumulator - { - public Accumulator(TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTimes) - { - this.QueryEngineExecutionTime = queryEngineExecutionTime; - this.SystemFunctionExecutionTime = systemFunctionExecutionTime; - this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTimes; - } - - public TimeSpan QueryEngineExecutionTime { get; } - public TimeSpan SystemFunctionExecutionTime { get; } - public TimeSpan UserDefinedFunctionExecutionTime { get; } - - public Accumulator Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) - { - if (runtimeExecutionTimes == null) - { - throw new ArgumentNullException(nameof(runtimeExecutionTimes)); - } - - return new Accumulator( - queryEngineExecutionTime: this.QueryEngineExecutionTime + runtimeExecutionTimes.QueryEngineExecutionTime, - systemFunctionExecutionTime: this.SystemFunctionExecutionTime + runtimeExecutionTimes.SystemFunctionExecutionTime, - userDefinedFunctionExecutionTimes: this.UserDefinedFunctionExecutionTime + runtimeExecutionTimes.UserDefinedFunctionExecutionTime); - } - - public static RuntimeExecutionTimes ToRuntimeExecutionTimes(Accumulator accumulator) - { - return new RuntimeExecutionTimes( - queryEngineExecutionTime: accumulator.QueryEngineExecutionTime, - systemFunctionExecutionTime: accumulator.SystemFunctionExecutionTime, - userDefinedFunctionExecutionTime: accumulator.UserDefinedFunctionExecutionTime); - } - } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs new file mode 100644 index 0000000000..28b7963112 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs @@ -0,0 +1,41 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + + internal ref struct RuntimeExecutionTimesAccumulator + { + public RuntimeExecutionTimesAccumulator(TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTimes) + { + this.QueryEngineExecutionTime = queryEngineExecutionTime; + this.SystemFunctionExecutionTime = systemFunctionExecutionTime; + this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTimes; + } + + public TimeSpan QueryEngineExecutionTime { get; set; } + public TimeSpan SystemFunctionExecutionTime { get; set; } + public TimeSpan UserDefinedFunctionExecutionTime { get; set; } + public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) + { + if (runtimeExecutionTimes == null) + { + throw new ArgumentNullException(nameof(runtimeExecutionTimes)); + } + + this.QueryEngineExecutionTime += runtimeExecutionTimes.QueryEngineExecutionTime; + this.SystemFunctionExecutionTime += runtimeExecutionTimes.SystemFunctionExecutionTime; + this.UserDefinedFunctionExecutionTime += runtimeExecutionTimes.UserDefinedFunctionExecutionTime; + } + + public static RuntimeExecutionTimes ToRuntimeExecutionTimes(RuntimeExecutionTimesAccumulator accumulator) + { + return new RuntimeExecutionTimes( + queryEngineExecutionTime: accumulator.QueryEngineExecutionTime, + systemFunctionExecutionTime: accumulator.SystemFunctionExecutionTime, + userDefinedFunctionExecutionTime: accumulator.UserDefinedFunctionExecutionTime); + } + } +} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs index 221057790d..5e29987532 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs @@ -164,11 +164,11 @@ public void TestParseStringWithUnknownField() [TestMethod] public void TestAccumulator() { - BackendMetrics.Accumulator accumulator = new BackendMetrics.Accumulator(); - accumulator = accumulator.Accumulate(MockBackendMetrics); - accumulator = accumulator.Accumulate(MockBackendMetrics); + BackendMetricsAccumulator accumulator = new BackendMetricsAccumulator(); + accumulator.Accumulate(MockBackendMetrics); + accumulator.Accumulate(MockBackendMetrics); - BackendMetrics backendMetricsFromAddition = BackendMetrics.Accumulator.ToBackendMetrics(accumulator); + BackendMetrics backendMetricsFromAddition = BackendMetricsAccumulator.ToBackendMetrics(accumulator); BackendMetrics expected = new BackendMetrics( retrievedDocumentCount * 2, retrievedDocumentSize * 2, @@ -208,12 +208,12 @@ private static void ValidateBackendMetricsEquals(BackendMetrics expected, Backen Assert.AreEqual(expected.RetrievedDocumentCount, actual.RetrievedDocumentCount); Assert.AreEqual(expected.RetrievedDocumentSize, actual.RetrievedDocumentSize); Assert.AreEqual(expected.IndexHitRatio, actual.IndexHitRatio); - Assert.AreEqual(expected.QueryPreparationTimes.QueryCompilationTime, actual.QueryPreparationTimes.QueryCompilationTime); - Assert.AreEqual(expected.QueryPreparationTimes.LogicalPlanBuildTime, actual.QueryPreparationTimes.LogicalPlanBuildTime); - Assert.AreEqual(expected.QueryPreparationTimes.PhysicalPlanBuildTime, actual.QueryPreparationTimes.PhysicalPlanBuildTime); - Assert.AreEqual(expected.QueryPreparationTimes.QueryOptimizationTime, actual.QueryPreparationTimes.QueryOptimizationTime); - Assert.AreEqual(expected.RuntimeExecutionTimes.SystemFunctionExecutionTime, actual.RuntimeExecutionTimes.SystemFunctionExecutionTime); - Assert.AreEqual(expected.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, actual.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime); + //Assert.AreEqual(expected.QueryPreparationTimes.QueryCompilationTime, actual.QueryPreparationTimes.QueryCompilationTime); + //Assert.AreEqual(expected.QueryPreparationTimes.LogicalPlanBuildTime, actual.QueryPreparationTimes.LogicalPlanBuildTime); + //Assert.AreEqual(expected.QueryPreparationTimes.PhysicalPlanBuildTime, actual.QueryPreparationTimes.PhysicalPlanBuildTime); + //Assert.AreEqual(expected.QueryPreparationTimes.QueryOptimizationTime, actual.QueryPreparationTimes.QueryOptimizationTime); + //Assert.AreEqual(expected.RuntimeExecutionTimes.SystemFunctionExecutionTime, actual.RuntimeExecutionTimes.SystemFunctionExecutionTime); + //Assert.AreEqual(expected.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, actual.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime); Assert.AreEqual(expected.TotalTime, actual.TotalTime); Assert.AreEqual(expected.VMExecutionTime, actual.VMExecutionTime); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs index 4a446bb933..cddfa6381f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs @@ -21,11 +21,11 @@ public class ClientSideMetricsTests [TestMethod] public void TestAccumulator() { - ClientSideMetrics.Accumulator accumulator = new ClientSideMetrics.Accumulator(); - accumulator = accumulator.Accumulate(MockClientSideMetrics); - accumulator = accumulator.Accumulate(MockClientSideMetrics); + ClientSideMetricsAccumulator accumulator = new ClientSideMetricsAccumulator(); + accumulator.Accumulate(MockClientSideMetrics); + accumulator.Accumulate(MockClientSideMetrics); - ClientSideMetrics doubleMetrics = ClientSideMetrics.Accumulator.ToClientSideMetrics(accumulator); + ClientSideMetrics doubleMetrics = ClientSideMetricsAccumulator.ToClientSideMetrics(accumulator); Assert.AreEqual(2 * MockClientSideMetrics.Retries, doubleMetrics.Retries); Assert.AreEqual(2 * MockClientSideMetrics.RequestCharge, doubleMetrics.RequestCharge); Assert.AreEqual(2 * MockClientSideMetrics.FetchExecutionRanges.Count(), doubleMetrics.FetchExecutionRanges.Count()); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs index 13702de3b5..584c7383e0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs @@ -8,7 +8,6 @@ namespace Microsoft.Azure.Cosmos.Tests.Query.Metrics using VisualStudio.TestTools.UnitTesting; using Microsoft.Azure.Cosmos.Query.Core.Metrics; using System.Collections.Generic; - using System.Text; [TestClass] public class IndexUtilizationInfoTests @@ -35,11 +34,11 @@ public class IndexUtilizationInfoTests [TestMethod] public void TestAccumulator() { - IndexUtilizationInfo.Accumulator accumulator = new IndexUtilizationInfo.Accumulator(); - accumulator = accumulator.Accumulate(MockIndexUtilizationInfo); - accumulator = accumulator.Accumulate(MockIndexUtilizationInfo); + IndexUtilizationInfoAccumulator accumulator = new IndexUtilizationInfoAccumulator(); + accumulator.Accumulate(MockIndexUtilizationInfo); + accumulator.Accumulate(MockIndexUtilizationInfo); - IndexUtilizationInfo doubleInfo = IndexUtilizationInfo.Accumulator.ToIndexUtilizationInfo(accumulator); + IndexUtilizationInfo doubleInfo = IndexUtilizationInfoAccumulator.ToIndexUtilizationInfo(accumulator); Assert.AreEqual(2 * MockIndexUtilizationInfo.PotentialSingleIndexes.Count, doubleInfo.PotentialSingleIndexes.Count); Assert.AreEqual(2 * MockIndexUtilizationInfo.UtilizedSingleIndexes.Count, doubleInfo.UtilizedSingleIndexes.Count); Assert.AreEqual(2 * MockIndexUtilizationInfo.PotentialCompositeIndexes.Count, doubleInfo.PotentialCompositeIndexes.Count); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs index d655de097a..797309966f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs @@ -20,8 +20,8 @@ public class QueryMetricsTests public void TestAccumulator() { QueryMetrics.Accumulator accumulator = new QueryMetrics.Accumulator(); - accumulator = accumulator.Accumulate(MockQueryMetrics); - accumulator = accumulator.Accumulate(MockQueryMetrics); + accumulator.Accumulate(MockQueryMetrics); + accumulator.Accumulate(MockQueryMetrics); QueryMetrics doubleQueryMetrics = QueryMetrics.Accumulator.ToQueryMetrics(accumulator); From 451763bf6805cf2969a9ca302c21bd62f4f6c286 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 26 Jul 2023 17:54:06 -0700 Subject: [PATCH 06/43] accumulator updates and undo test changes --- .../Query/Core/Metrics/BackendMetricsAccumulator.cs | 2 +- .../Core/Metrics/ClientSideMetricsAccumulator.cs | 2 +- .../Core/Metrics/IndexUtilizationInfoAccumulator.cs | 2 +- .../Core/Metrics/QueryPreparationTimesAccumulator.cs | 2 +- .../Core/Metrics/RuntimeExecutionTimesAccumulator.cs | 2 +- .../Query/Metrics/BackendMetricsTests.cs | 12 ++++++------ 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs index 22120195a5..717bfe248e 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs @@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using Microsoft.Azure.Cosmos.Tracing; using Microsoft.Azure.Cosmos.Tracing.TraceData; - internal ref struct BackendMetricsAccumulator + internal struct BackendMetricsAccumulator { public BackendMetricsAccumulator( TimeSpan totalTime, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs index a5c2399b5f..040e1f1010 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Collections.Generic; using System.Linq; - internal ref struct ClientSideMetricsAccumulator + internal struct ClientSideMetricsAccumulator { public ClientSideMetricsAccumulator(long retries, double requestCharge, IEnumerable fetchExecutionRanges) { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs index 1128dc30f4..537dc6a16f 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Collections.Generic; using System.Linq; - internal ref struct IndexUtilizationInfoAccumulator + internal struct IndexUtilizationInfoAccumulator { public IndexUtilizationInfoAccumulator( IEnumerable utilizedSingleIndexes, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs index 12c2a62e32..6499a97763 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; - internal ref struct QueryPreparationTimesAccumulator + internal struct QueryPreparationTimesAccumulator { public QueryPreparationTimesAccumulator(TimeSpan queryCompliationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, TimeSpan queryOptimizationTime) { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs index 28b7963112..a6727c64b6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; - internal ref struct RuntimeExecutionTimesAccumulator + internal struct RuntimeExecutionTimesAccumulator { public RuntimeExecutionTimesAccumulator(TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTimes) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs index 5e29987532..106fa8380a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs @@ -208,12 +208,12 @@ private static void ValidateBackendMetricsEquals(BackendMetrics expected, Backen Assert.AreEqual(expected.RetrievedDocumentCount, actual.RetrievedDocumentCount); Assert.AreEqual(expected.RetrievedDocumentSize, actual.RetrievedDocumentSize); Assert.AreEqual(expected.IndexHitRatio, actual.IndexHitRatio); - //Assert.AreEqual(expected.QueryPreparationTimes.QueryCompilationTime, actual.QueryPreparationTimes.QueryCompilationTime); - //Assert.AreEqual(expected.QueryPreparationTimes.LogicalPlanBuildTime, actual.QueryPreparationTimes.LogicalPlanBuildTime); - //Assert.AreEqual(expected.QueryPreparationTimes.PhysicalPlanBuildTime, actual.QueryPreparationTimes.PhysicalPlanBuildTime); - //Assert.AreEqual(expected.QueryPreparationTimes.QueryOptimizationTime, actual.QueryPreparationTimes.QueryOptimizationTime); - //Assert.AreEqual(expected.RuntimeExecutionTimes.SystemFunctionExecutionTime, actual.RuntimeExecutionTimes.SystemFunctionExecutionTime); - //Assert.AreEqual(expected.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, actual.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime); + Assert.AreEqual(expected.QueryPreparationTimes.QueryCompilationTime, actual.QueryPreparationTimes.QueryCompilationTime); + Assert.AreEqual(expected.QueryPreparationTimes.LogicalPlanBuildTime, actual.QueryPreparationTimes.LogicalPlanBuildTime); + Assert.AreEqual(expected.QueryPreparationTimes.PhysicalPlanBuildTime, actual.QueryPreparationTimes.PhysicalPlanBuildTime); + Assert.AreEqual(expected.QueryPreparationTimes.QueryOptimizationTime, actual.QueryPreparationTimes.QueryOptimizationTime); + Assert.AreEqual(expected.RuntimeExecutionTimes.SystemFunctionExecutionTime, actual.RuntimeExecutionTimes.SystemFunctionExecutionTime); + Assert.AreEqual(expected.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, actual.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime); Assert.AreEqual(expected.TotalTime, actual.TotalTime); Assert.AreEqual(expected.VMExecutionTime, actual.VMExecutionTime); } From d4f6c07f923c2dbfbbcfab4e8b4f1862a62a4114 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 26 Jul 2023 18:38:17 -0700 Subject: [PATCH 07/43] add test --- .../CosmosTraceDiagnosticsTests.cs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs new file mode 100644 index 0000000000..fd53eff8d1 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -0,0 +1,85 @@ +namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class CosmosTraceDiagnosticsTests : BaseCosmosClientHelper + { + private Container Container = null; + private ContainerProperties containerSettings = null; + + [TestInitialize] + public async Task TestInitialize() + { + await base.TestInit(validateSinglePartitionKeyRangeCacheCall: true); + string PartitionKey = "/pk"; + this.containerSettings = new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKey); + ContainerResponse response = await this.database.CreateContainerAsync( + this.containerSettings, + throughput: 15000, + cancellationToken: this.cancellationToken); + Assert.IsNotNull(response); + Assert.IsNotNull(response.Container); + Assert.IsNotNull(response.Resource); + this.Container = response; + } + + [TestCleanup] + public async Task Cleanup() + { + await base.TestCleanup(); + } + + /// + /// Validate QueryMetrics retrieved from Diagnostics for multi-partition query. + /// + [TestMethod] + public async Task ValidateMetricsMultiplePartitionQuery() + { + IList deleteList = await ToDoActivity.CreateRandomItems(this.Container, 3, randomPartitionKey: true); + + ToDoActivity find = deleteList.First(); + QueryDefinition sql = new QueryDefinition("select * from toDoActivity t where t.id = '" + find.id + "'"); + + QueryRequestOptions requestOptions = new QueryRequestOptions() + { + MaxBufferedItemCount = 10, + ResponseContinuationTokenLimitInKb = 500, + MaxItemCount = 1, + MaxConcurrency = 1, + }; + + FeedIterator feedIterator = this.Container.GetItemQueryIterator( + sql, + requestOptions: requestOptions); + + bool found = false; + BackendMetricsAccumulator headerMetricsAccumulator = default; + while (feedIterator.HasMoreResults) + { + FeedResponse iter = await feedIterator.ReadNextAsync(); + Assert.IsTrue(iter.Count() <= 1); + if (iter.Count() == 1) + { + found = true; + ToDoActivity response = iter.First(); + Assert.AreEqual(find.id, response.id); + } + + BackendMetrics backendMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); + bool tryParseResult = BackendMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out BackendMetrics backendMetricsFromTrace); + Assert.IsTrue(tryParseResult); + + headerMetricsAccumulator.Accumulate(backendMetricsFromTrace); + Assert.IsTrue(BackendMetricsAccumulator.ToBackendMetrics(headerMetricsAccumulator).Equals(backendMetricsFromDiagnostics)); + } + + Assert.IsTrue(found); + } + } +} From de863d916f3f5ddc7ff3cfd90656685931991abf Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 27 Jul 2023 13:05:44 -0700 Subject: [PATCH 08/43] PR comments --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 4 +- .../src/Query/Core/Metrics/BackendMetrics.cs | 2 +- .../Core/Metrics/BackendMetricsAccumulator.cs | 68 ++++++++++++------- .../Metrics/ClientSideMetricsAccumulator.cs | 23 ++++--- .../IndexUtilizationInfoAccumulator.cs | 28 +++++--- .../src/Query/Core/Metrics/QueryMetrics.cs | 47 ++----------- .../Core/Metrics/QueryMetricsAccumulator.cs | 54 +++++++++++++++ .../QueryPreparationTimesAccumulator.cs | 28 +++++--- .../RuntimeExecutionTimesAccumulator.cs | 23 ++++--- .../CosmosTraceDiagnosticsTests.cs | 2 +- .../Query/Metrics/BackendMetricsTests.cs | 2 +- .../Query/Metrics/ClientSideMetricsTests.cs | 2 +- .../Metrics/IndexUtilizationInfoTests.cs | 2 +- .../Query/Metrics/QueryMetricsTests.cs | 4 +- 14 files changed, 175 insertions(+), 114 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 60f72b2896..a0bc342767 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -51,9 +51,9 @@ public override TimeSpan GetClientElapsedTime() public override BackendMetrics GetQueryMetrics() { - BackendMetricsAccumulator accumulator = new BackendMetricsAccumulator(); + BackendMetricsAccumulator accumulator = default; BackendMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - return BackendMetricsAccumulator.ToBackendMetrics(accumulator); + return accumulator.GetBackendMetrics(); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs index fd8a79cb75..dd30c281b6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs @@ -149,7 +149,7 @@ internal static BackendMetrics CreateFromIEnumerable(IEnumerable accumulator.Accumulate(backendMetrics); } - return BackendMetricsAccumulator.ToBackendMetrics(accumulator); + return accumulator.GetBackendMetrics(); } internal static bool TryParseFromDelimitedString(string delimitedString, out BackendMetrics backendMetrics) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs index 717bfe248e..2af09caf84 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs @@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using Microsoft.Azure.Cosmos.Tracing; using Microsoft.Azure.Cosmos.Tracing.TraceData; - internal struct BackendMetricsAccumulator + internal class BackendMetricsAccumulator { public BackendMetricsAccumulator( TimeSpan totalTime, @@ -38,18 +38,34 @@ public BackendMetricsAccumulator( this.VMExecutionTime = vmExecutionTime; } - public TimeSpan TotalTime { get; set; } - public long RetrievedDocumentCount { get; set; } - public long RetrievedDocumentSize { get; set; } - public long OutputDocumentCount { get; set; } - public long OutputDocumentSize { get; set; } - public double IndexHitRatio { get; set; } - public QueryPreparationTimesAccumulator QueryPreparationTimesAccumulator { get; set; } - public TimeSpan IndexLookupTime { get; set; } - public TimeSpan DocumentLoadTime { get; set; } - public RuntimeExecutionTimesAccumulator RuntimeExecutionTimesAccumulator { get; set; } - public TimeSpan DocumentWriteTime { get; set; } - public TimeSpan VMExecutionTime { get; set; } + public BackendMetricsAccumulator() + { + this.TotalTime = default; + this.RetrievedDocumentCount = default; + this.RetrievedDocumentSize = default; + this.OutputDocumentCount = default; + this.OutputDocumentSize = default; + this.IndexHitRatio = default; + this.QueryPreparationTimesAccumulator = new QueryPreparationTimesAccumulator(); + this.IndexLookupTime = default; + this.DocumentLoadTime = default; + this.RuntimeExecutionTimesAccumulator = new RuntimeExecutionTimesAccumulator(); + this.DocumentWriteTime = default; + this.VMExecutionTime = default; + } + + private TimeSpan TotalTime { get; set; } + private long RetrievedDocumentCount { get; set; } + private long RetrievedDocumentSize { get; set; } + private long OutputDocumentCount { get; set; } + private long OutputDocumentSize { get; set; } + private double IndexHitRatio { get; set; } + private QueryPreparationTimesAccumulator QueryPreparationTimesAccumulator { get; set; } + private TimeSpan IndexLookupTime { get; set; } + private TimeSpan DocumentLoadTime { get; set; } + private RuntimeExecutionTimesAccumulator RuntimeExecutionTimesAccumulator { get; set; } + private TimeSpan DocumentWriteTime { get; set; } + private TimeSpan VMExecutionTime { get; set; } public void Accumulate(BackendMetrics backendMetrics) { @@ -67,21 +83,21 @@ public void Accumulate(BackendMetrics backendMetrics) this.VMExecutionTime += backendMetrics.VMExecutionTime; } - public static BackendMetrics ToBackendMetrics(BackendMetricsAccumulator accumulator) + public BackendMetrics GetBackendMetrics() { return new BackendMetrics( - retrievedDocumentCount: accumulator.RetrievedDocumentCount, - retrievedDocumentSize: accumulator.RetrievedDocumentSize, - outputDocumentCount: accumulator.OutputDocumentCount, - outputDocumentSize: accumulator.OutputDocumentSize, - indexHitRatio: accumulator.IndexHitRatio, - totalQueryExecutionTime: accumulator.TotalTime, - queryPreparationTimes: QueryPreparationTimesAccumulator.ToQueryPreparationTimes(accumulator.QueryPreparationTimesAccumulator), - indexLookupTime: accumulator.IndexLookupTime, - documentLoadTime: accumulator.DocumentLoadTime, - vmExecutionTime: accumulator.VMExecutionTime, - runtimeExecutionTimes: RuntimeExecutionTimesAccumulator.ToRuntimeExecutionTimes(accumulator.RuntimeExecutionTimesAccumulator), - documentWriteTime: accumulator.DocumentWriteTime); + retrievedDocumentCount: this.RetrievedDocumentCount, + retrievedDocumentSize: this.RetrievedDocumentSize, + outputDocumentCount: this.OutputDocumentCount, + outputDocumentSize: this.OutputDocumentSize, + indexHitRatio: this.IndexHitRatio, + totalQueryExecutionTime: this.TotalTime, + queryPreparationTimes: this.QueryPreparationTimesAccumulator.GetQueryPreparationTimes(), + indexLookupTime: this.IndexLookupTime, + documentLoadTime: this.DocumentLoadTime, + vmExecutionTime: this.VMExecutionTime, + runtimeExecutionTimes: this.RuntimeExecutionTimesAccumulator.GetRuntimeExecutionTimes(), + documentWriteTime: this.DocumentWriteTime); } public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, BackendMetricsAccumulator accumulator) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs index 040e1f1010..93e981cabf 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Collections.Generic; using System.Linq; - internal struct ClientSideMetricsAccumulator + internal class ClientSideMetricsAccumulator { public ClientSideMetricsAccumulator(long retries, double requestCharge, IEnumerable fetchExecutionRanges) { @@ -16,11 +16,18 @@ public ClientSideMetricsAccumulator(long retries, double requestCharge, IEnumera this.FetchExecutionRanges = fetchExecutionRanges; } - public long Retries { get; set; } + public ClientSideMetricsAccumulator() + { + this.Retries = default; + this.RequestCharge = default; + this.FetchExecutionRanges = default; + } + + private long Retries { get; set; } - public double RequestCharge { get; set; } + private double RequestCharge { get; set; } - public IEnumerable FetchExecutionRanges { get; set; } + private IEnumerable FetchExecutionRanges { get; set; } public void Accumulate(ClientSideMetrics clientSideMetrics) { @@ -36,12 +43,12 @@ public void Accumulate(ClientSideMetrics clientSideMetrics) return; } - public static ClientSideMetrics ToClientSideMetrics(ClientSideMetricsAccumulator accumulator) + public ClientSideMetrics GetClientSideMetrics() { return new ClientSideMetrics( - retries: accumulator.Retries, - requestCharge: accumulator.RequestCharge, - fetchExecutionRanges: accumulator.FetchExecutionRanges); + retries: this.Retries, + requestCharge: this.RequestCharge, + fetchExecutionRanges: this.FetchExecutionRanges); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs index 537dc6a16f..32a7cb3b0b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Collections.Generic; using System.Linq; - internal struct IndexUtilizationInfoAccumulator + internal class IndexUtilizationInfoAccumulator { public IndexUtilizationInfoAccumulator( IEnumerable utilizedSingleIndexes, @@ -21,10 +21,18 @@ public IndexUtilizationInfoAccumulator( this.PotentialCompositeIndexes = potentialCompositeIndexes; } - public IEnumerable UtilizedSingleIndexes { get; set; } - public IEnumerable PotentialSingleIndexes { get; set; } - public IEnumerable UtilizedCompositeIndexes { get; set; } - public IEnumerable PotentialCompositeIndexes { get; set; } + public IndexUtilizationInfoAccumulator() + { + this.UtilizedSingleIndexes = default; + this.PotentialSingleIndexes = default; + this.UtilizedCompositeIndexes = default; + this.PotentialCompositeIndexes = default; + } + + private IEnumerable UtilizedSingleIndexes { get; set; } + private IEnumerable PotentialSingleIndexes { get; set; } + private IEnumerable UtilizedCompositeIndexes { get; set; } + private IEnumerable PotentialCompositeIndexes { get; set; } public void Accumulate(IndexUtilizationInfo indexUtilizationInfo) { @@ -35,13 +43,13 @@ public void Accumulate(IndexUtilizationInfo indexUtilizationInfo) return; } - public static IndexUtilizationInfo ToIndexUtilizationInfo(IndexUtilizationInfoAccumulator accumulator) + public IndexUtilizationInfo GetIndexUtilizationInfo() { return new IndexUtilizationInfo( - utilizedSingleIndexes: accumulator.UtilizedSingleIndexes.ToList(), - potentialSingleIndexes: accumulator.PotentialSingleIndexes.ToList(), - utilizedCompositeIndexes: accumulator.UtilizedCompositeIndexes.ToList(), - potentialCompositeIndexes: accumulator.PotentialCompositeIndexes.ToList()); + utilizedSingleIndexes: this.UtilizedSingleIndexes.ToList(), + potentialSingleIndexes: this.PotentialSingleIndexes.ToList(), + utilizedCompositeIndexes: this.UtilizedCompositeIndexes.ToList(), + potentialCompositeIndexes: this.PotentialCompositeIndexes.ToList()); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs index 9ff7a41ce6..3e621c2044 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs @@ -63,11 +63,11 @@ public QueryMetrics( /// A new instance that is the sum of two instances public static QueryMetrics operator +(QueryMetrics queryMetrics1, QueryMetrics queryMetrics2) { - QueryMetrics.Accumulator queryMetricsAccumulator = new QueryMetrics.Accumulator(); + QueryMetricsAccumulator queryMetricsAccumulator = new QueryMetricsAccumulator(); queryMetricsAccumulator.Accumulate(queryMetrics1); queryMetricsAccumulator.Accumulate(queryMetrics2); - return QueryMetrics.Accumulator.ToQueryMetrics(queryMetricsAccumulator); + return queryMetricsAccumulator.GetQueryMetrics(); } /// @@ -94,52 +94,13 @@ public static QueryMetrics CreateFromIEnumerable(IEnumerable query throw new ArgumentNullException(nameof(queryMetricsList)); } - QueryMetrics.Accumulator queryMetricsAccumulator = new QueryMetrics.Accumulator(); + QueryMetricsAccumulator queryMetricsAccumulator = new QueryMetricsAccumulator(); foreach (QueryMetrics queryMetrics in queryMetricsList) { queryMetricsAccumulator.Accumulate(queryMetrics); } - return QueryMetrics.Accumulator.ToQueryMetrics(queryMetricsAccumulator); - } - - public ref struct Accumulator - { - public Accumulator( - BackendMetricsAccumulator backendMetricsAccumulator, - IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator, - ClientSideMetricsAccumulator clientSideMetricsAccumulator) - { - this.BackendMetricsAccumulator = backendMetricsAccumulator; - this.IndexUtilizationInfoAccumulator = indexUtilizationInfoAccumulator; - this.ClientSideMetricsAccumulator = clientSideMetricsAccumulator; - } - - public BackendMetricsAccumulator BackendMetricsAccumulator { get; } - - public IndexUtilizationInfoAccumulator IndexUtilizationInfoAccumulator { get; } - - public ClientSideMetricsAccumulator ClientSideMetricsAccumulator { get; } - - public void Accumulate(QueryMetrics queryMetrics) - { - if (queryMetrics == null) - { - throw new ArgumentNullException(nameof(queryMetrics)); - } - - this.BackendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics); - this.IndexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo); - this.ClientSideMetricsAccumulator.Accumulate(queryMetrics.ClientSideMetrics); - } - - public static QueryMetrics ToQueryMetrics(Accumulator accumulator) - { - return new QueryMetrics( - BackendMetricsAccumulator.ToBackendMetrics(accumulator.BackendMetricsAccumulator), - IndexUtilizationInfoAccumulator.ToIndexUtilizationInfo(accumulator.IndexUtilizationInfoAccumulator), - ClientSideMetricsAccumulator.ToClientSideMetrics(accumulator.ClientSideMetricsAccumulator)); - } + return queryMetricsAccumulator.GetQueryMetrics(); } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs new file mode 100644 index 0000000000..28de9092ac --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs @@ -0,0 +1,54 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + + internal class QueryMetricsAccumulator + { + public QueryMetricsAccumulator( + BackendMetricsAccumulator backendMetricsAccumulator, + IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator, + ClientSideMetricsAccumulator clientSideMetricsAccumulator) + { + this.BackendMetricsAccumulator = backendMetricsAccumulator; + this.IndexUtilizationInfoAccumulator = indexUtilizationInfoAccumulator; + this.ClientSideMetricsAccumulator = clientSideMetricsAccumulator; + } + + public QueryMetricsAccumulator() + { + this.BackendMetricsAccumulator = new BackendMetricsAccumulator(); + this.IndexUtilizationInfoAccumulator = new IndexUtilizationInfoAccumulator(); + this.ClientSideMetricsAccumulator = new ClientSideMetricsAccumulator(); + } + + private BackendMetricsAccumulator BackendMetricsAccumulator { get; } + + private IndexUtilizationInfoAccumulator IndexUtilizationInfoAccumulator { get; } + + private ClientSideMetricsAccumulator ClientSideMetricsAccumulator { get; } + + public void Accumulate(QueryMetrics queryMetrics) + { + if (queryMetrics == null) + { + throw new ArgumentNullException(nameof(queryMetrics)); + } + + this.BackendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics); + this.IndexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo); + this.ClientSideMetricsAccumulator.Accumulate(queryMetrics.ClientSideMetrics); + } + + public QueryMetrics GetQueryMetrics() + { + return new QueryMetrics( + this.BackendMetricsAccumulator.GetBackendMetrics(), + this.IndexUtilizationInfoAccumulator.GetIndexUtilizationInfo(), + this.ClientSideMetricsAccumulator.GetClientSideMetrics()); + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs index 6499a97763..2b68589efe 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; - internal struct QueryPreparationTimesAccumulator + internal class QueryPreparationTimesAccumulator { public QueryPreparationTimesAccumulator(TimeSpan queryCompliationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, TimeSpan queryOptimizationTime) { @@ -16,10 +16,18 @@ public QueryPreparationTimesAccumulator(TimeSpan queryCompliationTime, TimeSpan this.QueryOptimizationTime = queryOptimizationTime; } - public TimeSpan QueryCompilationTime { get; set; } - public TimeSpan LogicalPlanBuildTime { get; set; } - public TimeSpan PhysicalPlanBuildTime { get; set; } - public TimeSpan QueryOptimizationTime { get; set; } + public QueryPreparationTimesAccumulator() + { + this.QueryCompilationTime = default; + this.LogicalPlanBuildTime = default; + this.PhysicalPlanBuildTime = default; + this.QueryOptimizationTime = default; + } + + private TimeSpan QueryCompilationTime { get; set; } + private TimeSpan LogicalPlanBuildTime { get; set; } + private TimeSpan PhysicalPlanBuildTime { get; set; } + private TimeSpan QueryOptimizationTime { get; set; } public void Accumulate(QueryPreparationTimes queryPreparationTimes) { @@ -34,13 +42,13 @@ public void Accumulate(QueryPreparationTimes queryPreparationTimes) this.QueryOptimizationTime += queryPreparationTimes.QueryOptimizationTime; } - public static QueryPreparationTimes ToQueryPreparationTimes(QueryPreparationTimesAccumulator accumulator) + public QueryPreparationTimes GetQueryPreparationTimes() { return new QueryPreparationTimes( - queryCompilationTime: accumulator.QueryCompilationTime, - logicalPlanBuildTime: accumulator.LogicalPlanBuildTime, - physicalPlanBuildTime: accumulator.PhysicalPlanBuildTime, - queryOptimizationTime: accumulator.QueryOptimizationTime); + queryCompilationTime: this.QueryCompilationTime, + logicalPlanBuildTime: this.LogicalPlanBuildTime, + physicalPlanBuildTime: this.PhysicalPlanBuildTime, + queryOptimizationTime: this.QueryOptimizationTime); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs index a6727c64b6..3135e6a08b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; - internal struct RuntimeExecutionTimesAccumulator + internal class RuntimeExecutionTimesAccumulator { public RuntimeExecutionTimesAccumulator(TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTimes) { @@ -15,9 +15,16 @@ public RuntimeExecutionTimesAccumulator(TimeSpan queryEngineExecutionTime, TimeS this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTimes; } - public TimeSpan QueryEngineExecutionTime { get; set; } - public TimeSpan SystemFunctionExecutionTime { get; set; } - public TimeSpan UserDefinedFunctionExecutionTime { get; set; } + public RuntimeExecutionTimesAccumulator() + { + this.QueryEngineExecutionTime = default; + this.SystemFunctionExecutionTime = default; + this.UserDefinedFunctionExecutionTime = default; + } + + private TimeSpan QueryEngineExecutionTime { get; set; } + private TimeSpan SystemFunctionExecutionTime { get; set; } + private TimeSpan UserDefinedFunctionExecutionTime { get; set; } public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) { if (runtimeExecutionTimes == null) @@ -30,12 +37,12 @@ public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) this.UserDefinedFunctionExecutionTime += runtimeExecutionTimes.UserDefinedFunctionExecutionTime; } - public static RuntimeExecutionTimes ToRuntimeExecutionTimes(RuntimeExecutionTimesAccumulator accumulator) + public RuntimeExecutionTimes GetRuntimeExecutionTimes() { return new RuntimeExecutionTimes( - queryEngineExecutionTime: accumulator.QueryEngineExecutionTime, - systemFunctionExecutionTime: accumulator.SystemFunctionExecutionTime, - userDefinedFunctionExecutionTime: accumulator.UserDefinedFunctionExecutionTime); + queryEngineExecutionTime: this.QueryEngineExecutionTime, + systemFunctionExecutionTime: this.SystemFunctionExecutionTime, + userDefinedFunctionExecutionTime: this.UserDefinedFunctionExecutionTime); } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index fd53eff8d1..007cd90424 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -76,7 +76,7 @@ public async Task ValidateMetricsMultiplePartitionQuery() Assert.IsTrue(tryParseResult); headerMetricsAccumulator.Accumulate(backendMetricsFromTrace); - Assert.IsTrue(BackendMetricsAccumulator.ToBackendMetrics(headerMetricsAccumulator).Equals(backendMetricsFromDiagnostics)); + Assert.IsTrue(headerMetricsAccumulator.GetBackendMetrics().Equals(backendMetricsFromDiagnostics)); } Assert.IsTrue(found); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs index 106fa8380a..2ea3ace6bc 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs @@ -168,7 +168,7 @@ public void TestAccumulator() accumulator.Accumulate(MockBackendMetrics); accumulator.Accumulate(MockBackendMetrics); - BackendMetrics backendMetricsFromAddition = BackendMetricsAccumulator.ToBackendMetrics(accumulator); + BackendMetrics backendMetricsFromAddition = accumulator.GetBackendMetrics(); BackendMetrics expected = new BackendMetrics( retrievedDocumentCount * 2, retrievedDocumentSize * 2, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs index cddfa6381f..90f9fec8ad 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ClientSideMetricsTests.cs @@ -25,7 +25,7 @@ public void TestAccumulator() accumulator.Accumulate(MockClientSideMetrics); accumulator.Accumulate(MockClientSideMetrics); - ClientSideMetrics doubleMetrics = ClientSideMetricsAccumulator.ToClientSideMetrics(accumulator); + ClientSideMetrics doubleMetrics = accumulator.GetClientSideMetrics(); Assert.AreEqual(2 * MockClientSideMetrics.Retries, doubleMetrics.Retries); Assert.AreEqual(2 * MockClientSideMetrics.RequestCharge, doubleMetrics.RequestCharge); Assert.AreEqual(2 * MockClientSideMetrics.FetchExecutionRanges.Count(), doubleMetrics.FetchExecutionRanges.Count()); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs index 584c7383e0..9fe272a6bd 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/IndexUtilizationInfoTests.cs @@ -38,7 +38,7 @@ public void TestAccumulator() accumulator.Accumulate(MockIndexUtilizationInfo); accumulator.Accumulate(MockIndexUtilizationInfo); - IndexUtilizationInfo doubleInfo = IndexUtilizationInfoAccumulator.ToIndexUtilizationInfo(accumulator); + IndexUtilizationInfo doubleInfo = accumulator.GetIndexUtilizationInfo(); Assert.AreEqual(2 * MockIndexUtilizationInfo.PotentialSingleIndexes.Count, doubleInfo.PotentialSingleIndexes.Count); Assert.AreEqual(2 * MockIndexUtilizationInfo.UtilizedSingleIndexes.Count, doubleInfo.UtilizedSingleIndexes.Count); Assert.AreEqual(2 * MockIndexUtilizationInfo.PotentialCompositeIndexes.Count, doubleInfo.PotentialCompositeIndexes.Count); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs index 797309966f..4adbb582ad 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs @@ -19,11 +19,11 @@ public class QueryMetricsTests [TestMethod] public void TestAccumulator() { - QueryMetrics.Accumulator accumulator = new QueryMetrics.Accumulator(); + QueryMetricsAccumulator accumulator = new QueryMetricsAccumulator(); accumulator.Accumulate(MockQueryMetrics); accumulator.Accumulate(MockQueryMetrics); - QueryMetrics doubleQueryMetrics = QueryMetrics.Accumulator.ToQueryMetrics(accumulator); + QueryMetrics doubleQueryMetrics = accumulator.GetQueryMetrics(); // Spot check Assert.AreEqual(2 * BackendMetricsTests.MockBackendMetrics.IndexLookupTime, doubleQueryMetrics.BackendMetrics.IndexLookupTime); From b1a78235e2f08010cca70d2e6cf1122593c04504 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 27 Jul 2023 14:45:29 -0700 Subject: [PATCH 09/43] bug fix --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 2 +- .../src/Query/Core/Metrics/BackendMetricsAccumulator.cs | 6 +++--- .../CosmosTraceDiagnosticsTests.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index a0bc342767..f28a530bea 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -51,7 +51,7 @@ public override TimeSpan GetClientElapsedTime() public override BackendMetrics GetQueryMetrics() { - BackendMetricsAccumulator accumulator = default; + BackendMetricsAccumulator accumulator = new BackendMetricsAccumulator(); BackendMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); return accumulator.GetBackendMetrics(); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs index 2af09caf84..66b557f45d 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs @@ -60,21 +60,21 @@ public BackendMetricsAccumulator() private long OutputDocumentCount { get; set; } private long OutputDocumentSize { get; set; } private double IndexHitRatio { get; set; } - private QueryPreparationTimesAccumulator QueryPreparationTimesAccumulator { get; set; } + private QueryPreparationTimesAccumulator QueryPreparationTimesAccumulator { get; } private TimeSpan IndexLookupTime { get; set; } private TimeSpan DocumentLoadTime { get; set; } - private RuntimeExecutionTimesAccumulator RuntimeExecutionTimesAccumulator { get; set; } + private RuntimeExecutionTimesAccumulator RuntimeExecutionTimesAccumulator { get; } private TimeSpan DocumentWriteTime { get; set; } private TimeSpan VMExecutionTime { get; set; } public void Accumulate(BackendMetrics backendMetrics) { + this.IndexHitRatio = ((this.OutputDocumentCount * this.IndexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (this.RetrievedDocumentCount + backendMetrics.RetrievedDocumentCount); this.TotalTime += backendMetrics.TotalTime; this.RetrievedDocumentCount += backendMetrics.RetrievedDocumentCount; this.RetrievedDocumentSize += backendMetrics.RetrievedDocumentSize; this.OutputDocumentCount += backendMetrics.OutputDocumentCount; this.OutputDocumentSize += backendMetrics.OutputDocumentSize; - this.IndexHitRatio = ((this.OutputDocumentCount * this.IndexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (this.RetrievedDocumentCount + backendMetrics.RetrievedDocumentCount); this.QueryPreparationTimesAccumulator.Accumulate(backendMetrics.QueryPreparationTimes); this.IndexLookupTime += backendMetrics.IndexLookupTime; this.DocumentLoadTime += backendMetrics.DocumentLoadTime; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index 007cd90424..e52ed11b0a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -59,7 +59,7 @@ public async Task ValidateMetricsMultiplePartitionQuery() requestOptions: requestOptions); bool found = false; - BackendMetricsAccumulator headerMetricsAccumulator = default; + BackendMetricsAccumulator headerMetricsAccumulator = new BackendMetricsAccumulator(); while (feedIterator.HasMoreResults) { FeedResponse iter = await feedIterator.ReadNextAsync(); From b96203a5061449bfb4179d25c7b1e052fc7fc312 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 27 Jul 2023 17:08:47 -0700 Subject: [PATCH 10/43] ToString() refactor --- .../src/Query/Core/Metrics/BackendMetrics.cs | 9 --------- .../src/Query/Core/Metrics/BackendMetricsUtils.cs | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs index dd30c281b6..d3300e613d 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs @@ -132,15 +132,6 @@ public BackendMetrics( /// public TimeSpan VMExecutionTime { get; } - /// - /// String representation of BackendMetric. - /// - /// BackendMetric text - public override string ToString() //todo move this logic elsewhere? - { - return $"totalExecutionTimeInMs={this.TotalTime.TotalMilliseconds};queryCompileTimeInMs={this.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={this.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={this.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={this.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={this.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={this.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={this.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={this.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={this.RetrievedDocumentCount};retrievedDocumentSize={this.RetrievedDocumentSize};outputDocumentCount={this.OutputDocumentCount};outputDocumentSize={this.OutputDocumentSize};writeOutputTimeInMs={this.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={this.IndexHitRatio}"; - } - internal static BackendMetrics CreateFromIEnumerable(IEnumerable backendMetricsEnumerable) { BackendMetricsAccumulator accumulator = default; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs new file mode 100644 index 0000000000..32eee6a099 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs @@ -0,0 +1,13 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + internal static class BackendMetricsUtils + { + public static string FormatTrace(this BackendMetrics backendMetrics) + { + return $"totalExecutionTimeInMs={backendMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={backendMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={backendMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={backendMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={backendMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={backendMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={backendMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={backendMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={backendMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={backendMetrics.RetrievedDocumentCount};retrievedDocumentSize={backendMetrics.RetrievedDocumentSize};outputDocumentCount={backendMetrics.OutputDocumentCount};outputDocumentSize={backendMetrics.OutputDocumentSize};writeOutputTimeInMs={backendMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={backendMetrics.IndexHitRatio}"; + } + } +} From f84e69857c92cdcb03a725a454bf07100a5b6289 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 28 Jul 2023 11:11:26 -0700 Subject: [PATCH 11/43] contract updates --- .../Contracts/DotNetSDKAPI.json | 266 ++++++++++++++++++ 1 file changed, 266 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 7fde376d49..047a16c66d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -3124,6 +3124,11 @@ "Attributes": [], "MethodInfo": "Int32 GetFailedRequestCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.BackendMetrics GetQueryMetrics()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.BackendMetrics GetQueryMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Uri]] GetContactedRegions()": { "Type": "Method", "Attributes": [], @@ -6236,6 +6241,267 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.BackendMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "Double get_IndexHitRatio()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Double IndexHitRatio": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Double IndexHitRatio;CanRead:True;CanWrite:False;Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_OutputDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_OutputDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_RetrievedDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_RetrievedDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 OutputDocumentCount": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 OutputDocumentCount;CanRead:True;CanWrite:False;Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 OutputDocumentSize": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 OutputDocumentSize;CanRead:True;CanWrite:False;Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 RetrievedDocumentCount": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 RetrievedDocumentCount;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 RetrievedDocumentSize": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes get_QueryPreparationTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes QueryPreparationTimes": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes QueryPreparationTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes get_RuntimeExecutionTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes RuntimeExecutionTimes": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes RuntimeExecutionTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan DocumentLoadTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan DocumentLoadTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan DocumentWriteTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan DocumentWriteTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_DocumentLoadTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_DocumentWriteTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_IndexLookupTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_TotalTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_VMExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan IndexLookupTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan TotalTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan TotalTime;CanRead:True;CanWrite:False;System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan VMExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes, System.TimeSpan, System.TimeSpan, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes, System.TimeSpan)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes, System.TimeSpan, System.TimeSpan, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes, System.TimeSpan), Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes, System.TimeSpan, System.TimeSpan, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes, System.TimeSpan)]" + } + }, + "NestedTypes": {} + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.TimeSpan get_LogicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_PhysicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_QueryCompilationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_QueryOptimizationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan LogicalPlanBuildTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan LogicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan PhysicalPlanBuildTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan PhysicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan QueryCompilationTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryCompilationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan QueryOptimizationTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryOptimizationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)]" + } + }, + "NestedTypes": {} + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.TimeSpan get_QueryEngineExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_SystemFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_UserDefinedFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan QueryEngineExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryEngineExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan SystemFunctionExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan SystemFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan UserDefinedFunctionExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan UserDefinedFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)]" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.QueryDefinition;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { From e2137d2aabf62fa74ec0e3f8a1bcb319f7f1ea12 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 28 Jul 2023 14:30:45 -0700 Subject: [PATCH 12/43] test updates --- .../CosmosTraceDiagnosticsTests.cs | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index e52ed11b0a..a2c65aeb8c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -10,23 +10,10 @@ [TestClass] public class CosmosTraceDiagnosticsTests : BaseCosmosClientHelper { - private Container Container = null; - private ContainerProperties containerSettings = null; - [TestInitialize] public async Task TestInitialize() { await base.TestInit(validateSinglePartitionKeyRangeCacheCall: true); - string PartitionKey = "/pk"; - this.containerSettings = new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKey); - ContainerResponse response = await this.database.CreateContainerAsync( - this.containerSettings, - throughput: 15000, - cancellationToken: this.cancellationToken); - Assert.IsNotNull(response); - Assert.IsNotNull(response.Container); - Assert.IsNotNull(response.Resource); - this.Container = response; } [TestCleanup] @@ -35,13 +22,38 @@ public async Task Cleanup() await base.TestCleanup(); } + /// + /// Validate QueryMetrics retrieved from Diagnostics for single partition query. + /// + [TestMethod] + public async Task ValidateMetricsSinglePartitionQuery() + { + await this.ValidateMetrics(throughput: 5000); + } + /// /// Validate QueryMetrics retrieved from Diagnostics for multi-partition query. /// [TestMethod] public async Task ValidateMetricsMultiplePartitionQuery() { - IList deleteList = await ToDoActivity.CreateRandomItems(this.Container, 3, randomPartitionKey: true); + await this.ValidateMetrics(throughput: 15000); + } + + private async Task ValidateMetrics(int throughput) + { + string PartitionKey = "/pk"; + ContainerProperties containerSettings = new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKey); + ContainerResponse containerResponse = await this.database.CreateContainerAsync( + containerSettings, + throughput: throughput, + cancellationToken: this.cancellationToken); + Assert.IsNotNull(containerResponse); + Assert.IsNotNull(containerResponse.Container); + Assert.IsNotNull(containerResponse.Resource); + Container container = containerResponse; + + IList deleteList = await ToDoActivity.CreateRandomItems(container, 3, randomPartitionKey: true); ToDoActivity find = deleteList.First(); QueryDefinition sql = new QueryDefinition("select * from toDoActivity t where t.id = '" + find.id + "'"); @@ -54,7 +66,7 @@ public async Task ValidateMetricsMultiplePartitionQuery() MaxConcurrency = 1, }; - FeedIterator feedIterator = this.Container.GetItemQueryIterator( + FeedIterator feedIterator = container.GetItemQueryIterator( sql, requestOptions: requestOptions); @@ -72,11 +84,13 @@ public async Task ValidateMetricsMultiplePartitionQuery() } BackendMetrics backendMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); + string diag = iter.Diagnostics.ToString(); + Assert.IsNotNull(diag); bool tryParseResult = BackendMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out BackendMetrics backendMetricsFromTrace); Assert.IsTrue(tryParseResult); headerMetricsAccumulator.Accumulate(backendMetricsFromTrace); - Assert.IsTrue(headerMetricsAccumulator.GetBackendMetrics().Equals(backendMetricsFromDiagnostics)); + Assert.IsTrue(headerMetricsAccumulator.GetBackendMetrics().FormatTrace() == backendMetricsFromDiagnostics.FormatTrace()); } Assert.IsTrue(found); From 4c5152dd85f1dee484d38044f9c41a300b2c7425 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 28 Jul 2023 15:59:17 -0700 Subject: [PATCH 13/43] small fixes --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 1 - .../CosmosTraceDiagnosticsTests.cs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index f28a530bea..ee4be9f81c 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -54,7 +54,6 @@ public override BackendMetrics GetQueryMetrics() BackendMetricsAccumulator accumulator = new BackendMetricsAccumulator(); BackendMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); return accumulator.GetBackendMetrics(); - } internal bool IsGoneExceptionHit() diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index a2c65aeb8c..600f0d6a9e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -86,10 +86,10 @@ private async Task ValidateMetrics(int throughput) BackendMetrics backendMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); string diag = iter.Diagnostics.ToString(); Assert.IsNotNull(diag); - bool tryParseResult = BackendMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out BackendMetrics backendMetricsFromTrace); + bool tryParseResult = BackendMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out BackendMetrics backendMetricsFromHeaders); Assert.IsTrue(tryParseResult); - headerMetricsAccumulator.Accumulate(backendMetricsFromTrace); + headerMetricsAccumulator.Accumulate(backendMetricsFromHeaders); Assert.IsTrue(headerMetricsAccumulator.GetBackendMetrics().FormatTrace() == backendMetricsFromDiagnostics.FormatTrace()); } From f18b585c2fe5c811b737214ed90b70cf6d8d30ee Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 28 Jul 2023 16:00:22 -0700 Subject: [PATCH 14/43] text fix --- .../CosmosTraceDiagnosticsTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index 600f0d6a9e..a738546ef2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -84,8 +84,6 @@ private async Task ValidateMetrics(int throughput) } BackendMetrics backendMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); - string diag = iter.Diagnostics.ToString(); - Assert.IsNotNull(diag); bool tryParseResult = BackendMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out BackendMetrics backendMetricsFromHeaders); Assert.IsTrue(tryParseResult); From b25f872063eac63f105ee1d94aa9b334c8119b18 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 31 Jul 2023 16:25:50 -0700 Subject: [PATCH 15/43] Update accumulators --- .../Core/Metrics/BackendMetricsAccumulator.cs | 126 +++++++----------- .../Metrics/ClientSideMetricsAccumulator.cs | 38 +++--- .../IndexUtilizationInfoAccumulator.cs | 56 ++++---- .../Core/Metrics/QueryMetricsAccumulator.cs | 42 +++--- .../QueryPreparationTimesAccumulator.cs | 45 +++---- .../RuntimeExecutionTimesAccumulator.cs | 38 +++--- 6 files changed, 152 insertions(+), 193 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs index 66b557f45d..ba0b734b80 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs @@ -5,99 +5,73 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; + using System.Collections.Generic; using Microsoft.Azure.Cosmos.Tracing; using Microsoft.Azure.Cosmos.Tracing.TraceData; internal class BackendMetricsAccumulator { - public BackendMetricsAccumulator( - TimeSpan totalTime, - long retrievedDocumentCount, - long retrievedDocumentSize, - long outputDocumentCount, - long outputDocumentSize, - double indexHitRatio, - QueryPreparationTimesAccumulator queryPreparationTimesAccumulator, - TimeSpan indexLookupTime, - TimeSpan documentLoadTime, - RuntimeExecutionTimesAccumulator runtimeExecutionTimesAccumulator, - TimeSpan documentWriteTime, - TimeSpan vmExecutionTime) - { - this.TotalTime = totalTime; - this.RetrievedDocumentCount = retrievedDocumentCount; - this.RetrievedDocumentSize = retrievedDocumentSize; - this.OutputDocumentCount = outputDocumentCount; - this.OutputDocumentSize = outputDocumentSize; - this.IndexHitRatio = indexHitRatio; - this.QueryPreparationTimesAccumulator = queryPreparationTimesAccumulator; - this.IndexLookupTime = indexLookupTime; - this.DocumentLoadTime = documentLoadTime; - this.RuntimeExecutionTimesAccumulator = runtimeExecutionTimesAccumulator; - this.DocumentWriteTime = documentWriteTime; - this.VMExecutionTime = vmExecutionTime; - } - public BackendMetricsAccumulator() { - this.TotalTime = default; - this.RetrievedDocumentCount = default; - this.RetrievedDocumentSize = default; - this.OutputDocumentCount = default; - this.OutputDocumentSize = default; - this.IndexHitRatio = default; - this.QueryPreparationTimesAccumulator = new QueryPreparationTimesAccumulator(); - this.IndexLookupTime = default; - this.DocumentLoadTime = default; - this.RuntimeExecutionTimesAccumulator = new RuntimeExecutionTimesAccumulator(); - this.DocumentWriteTime = default; - this.VMExecutionTime = default; + this.BackendMetricsList = new List(); } - private TimeSpan TotalTime { get; set; } - private long RetrievedDocumentCount { get; set; } - private long RetrievedDocumentSize { get; set; } - private long OutputDocumentCount { get; set; } - private long OutputDocumentSize { get; set; } - private double IndexHitRatio { get; set; } - private QueryPreparationTimesAccumulator QueryPreparationTimesAccumulator { get; } - private TimeSpan IndexLookupTime { get; set; } - private TimeSpan DocumentLoadTime { get; set; } - private RuntimeExecutionTimesAccumulator RuntimeExecutionTimesAccumulator { get; } - private TimeSpan DocumentWriteTime { get; set; } - private TimeSpan VMExecutionTime { get; set; } + private readonly List BackendMetricsList; public void Accumulate(BackendMetrics backendMetrics) { - this.IndexHitRatio = ((this.OutputDocumentCount * this.IndexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (this.RetrievedDocumentCount + backendMetrics.RetrievedDocumentCount); - this.TotalTime += backendMetrics.TotalTime; - this.RetrievedDocumentCount += backendMetrics.RetrievedDocumentCount; - this.RetrievedDocumentSize += backendMetrics.RetrievedDocumentSize; - this.OutputDocumentCount += backendMetrics.OutputDocumentCount; - this.OutputDocumentSize += backendMetrics.OutputDocumentSize; - this.QueryPreparationTimesAccumulator.Accumulate(backendMetrics.QueryPreparationTimes); - this.IndexLookupTime += backendMetrics.IndexLookupTime; - this.DocumentLoadTime += backendMetrics.DocumentLoadTime; - this.RuntimeExecutionTimesAccumulator.Accumulate(backendMetrics.RuntimeExecutionTimes); - this.DocumentWriteTime += backendMetrics.DocumentWriteTime; - this.VMExecutionTime += backendMetrics.VMExecutionTime; + if (backendMetrics == null) + { + throw new ArgumentNullException(nameof(backendMetrics)); + } + + this.BackendMetricsList.Add(backendMetrics); } public BackendMetrics GetBackendMetrics() { + TimeSpan totalTime = default; + long retrievedDocumentCount = default; + long retrievedDocumentSize = default; + long outputDocumentCount = default; + long outputDocumentSize = default; + double indexHitRatio = default; + QueryPreparationTimesAccumulator queryPreparationTimesAccumulator = new QueryPreparationTimesAccumulator(); + TimeSpan indexLookupTime = default; + TimeSpan documentLoadTime = default; + RuntimeExecutionTimesAccumulator runtimeExecutionTimesAccumulator = new RuntimeExecutionTimesAccumulator(); + TimeSpan documentWriteTime = default; + TimeSpan vMExecutionTime = default; + + foreach (BackendMetrics backendMetrics in this.BackendMetricsList) + { + indexHitRatio = ((outputDocumentCount * indexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (retrievedDocumentCount + backendMetrics.RetrievedDocumentCount); + totalTime += backendMetrics.TotalTime; + retrievedDocumentCount += backendMetrics.RetrievedDocumentCount; + retrievedDocumentSize += backendMetrics.RetrievedDocumentSize; + outputDocumentCount += backendMetrics.OutputDocumentCount; + outputDocumentSize += backendMetrics.OutputDocumentSize; + queryPreparationTimesAccumulator.Accumulate(backendMetrics.QueryPreparationTimes); + indexLookupTime += backendMetrics.IndexLookupTime; + documentLoadTime += backendMetrics.DocumentLoadTime; + runtimeExecutionTimesAccumulator.Accumulate(backendMetrics.RuntimeExecutionTimes); + documentWriteTime += backendMetrics.DocumentWriteTime; + vMExecutionTime += backendMetrics.VMExecutionTime; + } + return new BackendMetrics( - retrievedDocumentCount: this.RetrievedDocumentCount, - retrievedDocumentSize: this.RetrievedDocumentSize, - outputDocumentCount: this.OutputDocumentCount, - outputDocumentSize: this.OutputDocumentSize, - indexHitRatio: this.IndexHitRatio, - totalQueryExecutionTime: this.TotalTime, - queryPreparationTimes: this.QueryPreparationTimesAccumulator.GetQueryPreparationTimes(), - indexLookupTime: this.IndexLookupTime, - documentLoadTime: this.DocumentLoadTime, - vmExecutionTime: this.VMExecutionTime, - runtimeExecutionTimes: this.RuntimeExecutionTimesAccumulator.GetRuntimeExecutionTimes(), - documentWriteTime: this.DocumentWriteTime); + retrievedDocumentCount: retrievedDocumentCount, + retrievedDocumentSize: retrievedDocumentSize, + outputDocumentCount: outputDocumentCount, + outputDocumentSize: outputDocumentSize, + indexHitRatio: indexHitRatio, + totalQueryExecutionTime: totalTime, + queryPreparationTimes: queryPreparationTimesAccumulator.GetQueryPreparationTimes(), + indexLookupTime: indexLookupTime, + documentLoadTime: documentLoadTime, + vmExecutionTime: vMExecutionTime, + runtimeExecutionTimes: runtimeExecutionTimesAccumulator.GetRuntimeExecutionTimes(), + documentWriteTime: documentWriteTime); } public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, BackendMetricsAccumulator accumulator) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs index 93e981cabf..661514cc65 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs @@ -9,25 +9,12 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class ClientSideMetricsAccumulator { - public ClientSideMetricsAccumulator(long retries, double requestCharge, IEnumerable fetchExecutionRanges) - { - this.Retries = retries; - this.RequestCharge = requestCharge; - this.FetchExecutionRanges = fetchExecutionRanges; - } - public ClientSideMetricsAccumulator() { - this.Retries = default; - this.RequestCharge = default; - this.FetchExecutionRanges = default; + this.ClientSideMetricsList = new List(); } - private long Retries { get; set; } - - private double RequestCharge { get; set; } - - private IEnumerable FetchExecutionRanges { get; set; } + private readonly List ClientSideMetricsList; public void Accumulate(ClientSideMetrics clientSideMetrics) { @@ -36,19 +23,28 @@ public void Accumulate(ClientSideMetrics clientSideMetrics) throw new ArgumentNullException(nameof(clientSideMetrics)); } - this.Retries += clientSideMetrics.Retries; - this.RequestCharge += clientSideMetrics.RequestCharge; - this.FetchExecutionRanges = (this.FetchExecutionRanges ?? Enumerable.Empty()).Concat(clientSideMetrics.FetchExecutionRanges); + this.ClientSideMetricsList.Add(clientSideMetrics); return; } public ClientSideMetrics GetClientSideMetrics() { + long retries = default; + double requestCharge = default; + IEnumerable fetchExecutionRanges = default; + + foreach (ClientSideMetrics clientSideMetrics in this.ClientSideMetricsList) + { + retries += clientSideMetrics.Retries; + requestCharge += clientSideMetrics.RequestCharge; + fetchExecutionRanges = (fetchExecutionRanges ?? Enumerable.Empty()).Concat(clientSideMetrics.FetchExecutionRanges); + } + return new ClientSideMetrics( - retries: this.Retries, - requestCharge: this.RequestCharge, - fetchExecutionRanges: this.FetchExecutionRanges); + retries: retries, + requestCharge: requestCharge, + fetchExecutionRanges: fetchExecutionRanges); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs index 32a7cb3b0b..613bf6b488 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs @@ -4,52 +4,50 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { + using System; using System.Collections.Generic; using System.Linq; internal class IndexUtilizationInfoAccumulator { - public IndexUtilizationInfoAccumulator( - IEnumerable utilizedSingleIndexes, - IEnumerable potentialSingleIndexes, - IEnumerable utilizedCompositeIndexes, - IEnumerable potentialCompositeIndexes) - { - this.UtilizedSingleIndexes = utilizedSingleIndexes; - this.PotentialSingleIndexes = potentialSingleIndexes; - this.UtilizedCompositeIndexes = utilizedCompositeIndexes; - this.PotentialCompositeIndexes = potentialCompositeIndexes; - } - public IndexUtilizationInfoAccumulator() { - this.UtilizedSingleIndexes = default; - this.PotentialSingleIndexes = default; - this.UtilizedCompositeIndexes = default; - this.PotentialCompositeIndexes = default; + this.IndexUtilizationInfoList = new List(); } - private IEnumerable UtilizedSingleIndexes { get; set; } - private IEnumerable PotentialSingleIndexes { get; set; } - private IEnumerable UtilizedCompositeIndexes { get; set; } - private IEnumerable PotentialCompositeIndexes { get; set; } + private readonly List IndexUtilizationInfoList; public void Accumulate(IndexUtilizationInfo indexUtilizationInfo) { - this.UtilizedSingleIndexes = (this.UtilizedSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedSingleIndexes); - this.PotentialSingleIndexes = (this.PotentialSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialSingleIndexes); - this.UtilizedCompositeIndexes = (this.UtilizedCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedCompositeIndexes); - this.PotentialCompositeIndexes = (this.PotentialCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialCompositeIndexes); - return; + if (indexUtilizationInfo == null) + { + throw new ArgumentNullException(nameof(indexUtilizationInfo)); + } + + this.IndexUtilizationInfoList.Add(indexUtilizationInfo); } public IndexUtilizationInfo GetIndexUtilizationInfo() { + IEnumerable utilizedSingleIndexes = default; + IEnumerable potentialSingleIndexes = default; + IEnumerable utilizedCompositeIndexes = default; + IEnumerable potentialCompositeIndexes = default; + + foreach (IndexUtilizationInfo indexUtilizationInfo in this.IndexUtilizationInfoList) + { + utilizedSingleIndexes = (utilizedSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedSingleIndexes); + potentialSingleIndexes = (potentialSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialSingleIndexes); + utilizedCompositeIndexes = (utilizedCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedCompositeIndexes); + potentialCompositeIndexes = (potentialCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialCompositeIndexes); + + } + return new IndexUtilizationInfo( - utilizedSingleIndexes: this.UtilizedSingleIndexes.ToList(), - potentialSingleIndexes: this.PotentialSingleIndexes.ToList(), - utilizedCompositeIndexes: this.UtilizedCompositeIndexes.ToList(), - potentialCompositeIndexes: this.PotentialCompositeIndexes.ToList()); + utilizedSingleIndexes: utilizedSingleIndexes.ToList(), + potentialSingleIndexes: potentialSingleIndexes.ToList(), + utilizedCompositeIndexes: utilizedCompositeIndexes.ToList(), + potentialCompositeIndexes: potentialCompositeIndexes.ToList()); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs index 28de9092ac..cb83d44c53 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs @@ -5,31 +5,16 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; + using System.Collections.Generic; internal class QueryMetricsAccumulator { - public QueryMetricsAccumulator( - BackendMetricsAccumulator backendMetricsAccumulator, - IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator, - ClientSideMetricsAccumulator clientSideMetricsAccumulator) - { - this.BackendMetricsAccumulator = backendMetricsAccumulator; - this.IndexUtilizationInfoAccumulator = indexUtilizationInfoAccumulator; - this.ClientSideMetricsAccumulator = clientSideMetricsAccumulator; - } - public QueryMetricsAccumulator() { - this.BackendMetricsAccumulator = new BackendMetricsAccumulator(); - this.IndexUtilizationInfoAccumulator = new IndexUtilizationInfoAccumulator(); - this.ClientSideMetricsAccumulator = new ClientSideMetricsAccumulator(); + this.QueryMetricsList = new List(); } - private BackendMetricsAccumulator BackendMetricsAccumulator { get; } - - private IndexUtilizationInfoAccumulator IndexUtilizationInfoAccumulator { get; } - - private ClientSideMetricsAccumulator ClientSideMetricsAccumulator { get; } + private readonly List QueryMetricsList; public void Accumulate(QueryMetrics queryMetrics) { @@ -38,17 +23,26 @@ public void Accumulate(QueryMetrics queryMetrics) throw new ArgumentNullException(nameof(queryMetrics)); } - this.BackendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics); - this.IndexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo); - this.ClientSideMetricsAccumulator.Accumulate(queryMetrics.ClientSideMetrics); + this.QueryMetricsList.Add(queryMetrics); } public QueryMetrics GetQueryMetrics() { + BackendMetricsAccumulator backendMetricsAccumulator = new BackendMetricsAccumulator(); + IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator = new IndexUtilizationInfoAccumulator(); + ClientSideMetricsAccumulator clientSideMetricsAccumulator = new ClientSideMetricsAccumulator(); + + foreach (QueryMetrics queryMetrics in this.QueryMetricsList) + { + backendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics); + indexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo); + clientSideMetricsAccumulator.Accumulate(queryMetrics.ClientSideMetrics); + } + return new QueryMetrics( - this.BackendMetricsAccumulator.GetBackendMetrics(), - this.IndexUtilizationInfoAccumulator.GetIndexUtilizationInfo(), - this.ClientSideMetricsAccumulator.GetClientSideMetrics()); + backendMetricsAccumulator.GetBackendMetrics(), + indexUtilizationInfoAccumulator.GetIndexUtilizationInfo(), + clientSideMetricsAccumulator.GetClientSideMetrics()); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs index 2b68589efe..ece818367c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs @@ -5,29 +5,16 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; + using System.Collections.Generic; internal class QueryPreparationTimesAccumulator { - public QueryPreparationTimesAccumulator(TimeSpan queryCompliationTime, TimeSpan logicalPlanBuildTime, TimeSpan physicalPlanBuildTime, TimeSpan queryOptimizationTime) - { - this.QueryCompilationTime = queryCompliationTime; - this.LogicalPlanBuildTime = logicalPlanBuildTime; - this.PhysicalPlanBuildTime = physicalPlanBuildTime; - this.QueryOptimizationTime = queryOptimizationTime; - } - public QueryPreparationTimesAccumulator() { - this.QueryCompilationTime = default; - this.LogicalPlanBuildTime = default; - this.PhysicalPlanBuildTime = default; - this.QueryOptimizationTime = default; + this.QueryPreparationTimesList = new List(); } - private TimeSpan QueryCompilationTime { get; set; } - private TimeSpan LogicalPlanBuildTime { get; set; } - private TimeSpan PhysicalPlanBuildTime { get; set; } - private TimeSpan QueryOptimizationTime { get; set; } + private readonly List QueryPreparationTimesList; public void Accumulate(QueryPreparationTimes queryPreparationTimes) { @@ -36,19 +23,29 @@ public void Accumulate(QueryPreparationTimes queryPreparationTimes) throw new ArgumentNullException(nameof(queryPreparationTimes)); } - this.QueryCompilationTime += queryPreparationTimes.QueryCompilationTime; - this.LogicalPlanBuildTime += queryPreparationTimes.LogicalPlanBuildTime; - this.PhysicalPlanBuildTime += queryPreparationTimes.PhysicalPlanBuildTime; - this.QueryOptimizationTime += queryPreparationTimes.QueryOptimizationTime; + this.QueryPreparationTimesList.Add(queryPreparationTimes); } public QueryPreparationTimes GetQueryPreparationTimes() { + TimeSpan queryCompilationTime; + TimeSpan logicalPlanBuildTime; + TimeSpan physicalPlanBuildTime; + TimeSpan queryOptimizationTime; + + foreach (QueryPreparationTimes queryPreparationTimes in this.QueryPreparationTimesList) + { + queryCompilationTime += queryPreparationTimes.QueryCompilationTime; + logicalPlanBuildTime += queryPreparationTimes.LogicalPlanBuildTime; + physicalPlanBuildTime += queryPreparationTimes.PhysicalPlanBuildTime; + queryOptimizationTime += queryPreparationTimes.QueryOptimizationTime; + } + return new QueryPreparationTimes( - queryCompilationTime: this.QueryCompilationTime, - logicalPlanBuildTime: this.LogicalPlanBuildTime, - physicalPlanBuildTime: this.PhysicalPlanBuildTime, - queryOptimizationTime: this.QueryOptimizationTime); + queryCompilationTime: queryCompilationTime, + logicalPlanBuildTime: logicalPlanBuildTime, + physicalPlanBuildTime: physicalPlanBuildTime, + queryOptimizationTime: queryOptimizationTime); } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs index 3135e6a08b..e5bc24ddef 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs @@ -5,26 +5,17 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; + using System.Collections.Generic; internal class RuntimeExecutionTimesAccumulator { - public RuntimeExecutionTimesAccumulator(TimeSpan queryEngineExecutionTime, TimeSpan systemFunctionExecutionTime, TimeSpan userDefinedFunctionExecutionTimes) - { - this.QueryEngineExecutionTime = queryEngineExecutionTime; - this.SystemFunctionExecutionTime = systemFunctionExecutionTime; - this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTimes; - } - public RuntimeExecutionTimesAccumulator() { - this.QueryEngineExecutionTime = default; - this.SystemFunctionExecutionTime = default; - this.UserDefinedFunctionExecutionTime = default; + this.RuntimeExecutionTimesList = new List(); } - private TimeSpan QueryEngineExecutionTime { get; set; } - private TimeSpan SystemFunctionExecutionTime { get; set; } - private TimeSpan UserDefinedFunctionExecutionTime { get; set; } + private readonly List RuntimeExecutionTimesList; + public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) { if (runtimeExecutionTimes == null) @@ -32,17 +23,26 @@ public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) throw new ArgumentNullException(nameof(runtimeExecutionTimes)); } - this.QueryEngineExecutionTime += runtimeExecutionTimes.QueryEngineExecutionTime; - this.SystemFunctionExecutionTime += runtimeExecutionTimes.SystemFunctionExecutionTime; - this.UserDefinedFunctionExecutionTime += runtimeExecutionTimes.UserDefinedFunctionExecutionTime; + this.RuntimeExecutionTimesList.Add(runtimeExecutionTimes); } public RuntimeExecutionTimes GetRuntimeExecutionTimes() { + TimeSpan queryEngineExecutionTime = default; + TimeSpan systemFunctionExecutionTime = default; + TimeSpan userDefinedFunctionExecutionTime = default; + + foreach (RuntimeExecutionTimes runtimeExecutionTimes in this.RuntimeExecutionTimesList) + { + queryEngineExecutionTime += runtimeExecutionTimes.QueryEngineExecutionTime; + systemFunctionExecutionTime += runtimeExecutionTimes.SystemFunctionExecutionTime; + userDefinedFunctionExecutionTime += runtimeExecutionTimes.UserDefinedFunctionExecutionTime; + } + return new RuntimeExecutionTimes( - queryEngineExecutionTime: this.QueryEngineExecutionTime, - systemFunctionExecutionTime: this.SystemFunctionExecutionTime, - userDefinedFunctionExecutionTime: this.UserDefinedFunctionExecutionTime); + queryEngineExecutionTime: queryEngineExecutionTime, + systemFunctionExecutionTime: systemFunctionExecutionTime, + userDefinedFunctionExecutionTime: userDefinedFunctionExecutionTime); } } } From 7f8aa59854803853a7f39590989a2ec2fddd1794 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 1 Aug 2023 08:35:29 -0700 Subject: [PATCH 16/43] fix --- .../src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs index 661514cc65..e54c63cee9 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs @@ -24,8 +24,6 @@ public void Accumulate(ClientSideMetrics clientSideMetrics) } this.ClientSideMetricsList.Add(clientSideMetrics); - - return; } public ClientSideMetrics GetClientSideMetrics() From f9af87337103475710d6dd4059d8c6231a1b72e3 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 1 Aug 2023 13:32:20 -0700 Subject: [PATCH 17/43] PR comments --- .../src/Query/Core/Metrics/BackendMetrics.cs | 2 +- .../Core/Metrics/BackendMetricsAccumulator.cs | 30 +++++++++---------- .../Metrics/ClientSideMetricsAccumulator.cs | 18 +++++------ .../IndexUtilizationInfoAccumulator.cs | 27 ++++++++--------- .../Core/Metrics/QueryMetricsAccumulator.cs | 10 +++---- .../QueryPreparationTimesAccumulator.cs | 18 +++++------ .../RuntimeExecutionTimesAccumulator.cs | 16 +++++----- 7 files changed, 60 insertions(+), 61 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs index d3300e613d..c6f824a85a 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs @@ -132,7 +132,7 @@ public BackendMetrics( /// public TimeSpan VMExecutionTime { get; } - internal static BackendMetrics CreateFromIEnumerable(IEnumerable backendMetricsEnumerable) + internal static BackendMetrics Create(IEnumerable backendMetricsEnumerable) { BackendMetricsAccumulator accumulator = default; foreach (BackendMetrics backendMetrics in backendMetricsEnumerable) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs index ba0b734b80..48fca2c87a 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs @@ -11,13 +11,13 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class BackendMetricsAccumulator { + private readonly List backendMetricsList; + public BackendMetricsAccumulator() { - this.BackendMetricsList = new List(); + this.backendMetricsList = new List(); } - private readonly List BackendMetricsList; - public void Accumulate(BackendMetrics backendMetrics) { if (backendMetrics == null) @@ -25,25 +25,25 @@ public void Accumulate(BackendMetrics backendMetrics) throw new ArgumentNullException(nameof(backendMetrics)); } - this.BackendMetricsList.Add(backendMetrics); + this.backendMetricsList.Add(backendMetrics); } public BackendMetrics GetBackendMetrics() { - TimeSpan totalTime = default; - long retrievedDocumentCount = default; - long retrievedDocumentSize = default; - long outputDocumentCount = default; - long outputDocumentSize = default; - double indexHitRatio = default; + TimeSpan totalTime = TimeSpan.Zero; + long retrievedDocumentCount = 0; + long retrievedDocumentSize = 0; + long outputDocumentCount = 0; + long outputDocumentSize = 0; + double indexHitRatio = 0; QueryPreparationTimesAccumulator queryPreparationTimesAccumulator = new QueryPreparationTimesAccumulator(); - TimeSpan indexLookupTime = default; - TimeSpan documentLoadTime = default; + TimeSpan indexLookupTime = TimeSpan.Zero; + TimeSpan documentLoadTime = TimeSpan.Zero; RuntimeExecutionTimesAccumulator runtimeExecutionTimesAccumulator = new RuntimeExecutionTimesAccumulator(); - TimeSpan documentWriteTime = default; - TimeSpan vMExecutionTime = default; + TimeSpan documentWriteTime = TimeSpan.Zero; + TimeSpan vMExecutionTime = TimeSpan.Zero; - foreach (BackendMetrics backendMetrics in this.BackendMetricsList) + foreach (BackendMetrics backendMetrics in this.backendMetricsList) { indexHitRatio = ((outputDocumentCount * indexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (retrievedDocumentCount + backendMetrics.RetrievedDocumentCount); totalTime += backendMetrics.TotalTime; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs index e54c63cee9..f0e43b61dc 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs @@ -9,13 +9,13 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class ClientSideMetricsAccumulator { + private readonly List clientSideMetricsList; + public ClientSideMetricsAccumulator() { - this.ClientSideMetricsList = new List(); + this.clientSideMetricsList = new List(); } - private readonly List ClientSideMetricsList; - public void Accumulate(ClientSideMetrics clientSideMetrics) { if (clientSideMetrics == null) @@ -23,20 +23,20 @@ public void Accumulate(ClientSideMetrics clientSideMetrics) throw new ArgumentNullException(nameof(clientSideMetrics)); } - this.ClientSideMetricsList.Add(clientSideMetrics); + this.clientSideMetricsList.Add(clientSideMetrics); } public ClientSideMetrics GetClientSideMetrics() { - long retries = default; - double requestCharge = default; - IEnumerable fetchExecutionRanges = default; + long retries = 0; + double requestCharge = 0; + List fetchExecutionRanges = new List(); - foreach (ClientSideMetrics clientSideMetrics in this.ClientSideMetricsList) + foreach (ClientSideMetrics clientSideMetrics in this.clientSideMetricsList) { retries += clientSideMetrics.Retries; requestCharge += clientSideMetrics.RequestCharge; - fetchExecutionRanges = (fetchExecutionRanges ?? Enumerable.Empty()).Concat(clientSideMetrics.FetchExecutionRanges); + fetchExecutionRanges.AddRange(clientSideMetrics.FetchExecutionRanges); } return new ClientSideMetrics( diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs index 613bf6b488..0bd2b60f46 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs @@ -10,13 +10,13 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class IndexUtilizationInfoAccumulator { + private readonly List indexUtilizationInfoList; + public IndexUtilizationInfoAccumulator() { - this.IndexUtilizationInfoList = new List(); + this.indexUtilizationInfoList = new List(); } - private readonly List IndexUtilizationInfoList; - public void Accumulate(IndexUtilizationInfo indexUtilizationInfo) { if (indexUtilizationInfo == null) @@ -24,23 +24,22 @@ public void Accumulate(IndexUtilizationInfo indexUtilizationInfo) throw new ArgumentNullException(nameof(indexUtilizationInfo)); } - this.IndexUtilizationInfoList.Add(indexUtilizationInfo); + this.indexUtilizationInfoList.Add(indexUtilizationInfo); } public IndexUtilizationInfo GetIndexUtilizationInfo() { - IEnumerable utilizedSingleIndexes = default; - IEnumerable potentialSingleIndexes = default; - IEnumerable utilizedCompositeIndexes = default; - IEnumerable potentialCompositeIndexes = default; + List utilizedSingleIndexes = new List(); + List potentialSingleIndexes = new List(); + List utilizedCompositeIndexes = new List(); + List potentialCompositeIndexes = new List(); - foreach (IndexUtilizationInfo indexUtilizationInfo in this.IndexUtilizationInfoList) + foreach (IndexUtilizationInfo indexUtilizationInfo in this.indexUtilizationInfoList) { - utilizedSingleIndexes = (utilizedSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedSingleIndexes); - potentialSingleIndexes = (potentialSingleIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialSingleIndexes); - utilizedCompositeIndexes = (utilizedCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.UtilizedCompositeIndexes); - potentialCompositeIndexes = (potentialCompositeIndexes ?? Enumerable.Empty()).Concat(indexUtilizationInfo.PotentialCompositeIndexes); - + utilizedSingleIndexes.AddRange(indexUtilizationInfo.UtilizedSingleIndexes); + potentialSingleIndexes.AddRange(indexUtilizationInfo.PotentialSingleIndexes); + utilizedCompositeIndexes.AddRange(indexUtilizationInfo.UtilizedCompositeIndexes); + potentialCompositeIndexes.AddRange(indexUtilizationInfo.PotentialCompositeIndexes); } return new IndexUtilizationInfo( diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs index cb83d44c53..e8f11ec20c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs @@ -9,13 +9,13 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class QueryMetricsAccumulator { + private readonly List queryMetricsList; + public QueryMetricsAccumulator() { - this.QueryMetricsList = new List(); + this.queryMetricsList = new List(); } - private readonly List QueryMetricsList; - public void Accumulate(QueryMetrics queryMetrics) { if (queryMetrics == null) @@ -23,7 +23,7 @@ public void Accumulate(QueryMetrics queryMetrics) throw new ArgumentNullException(nameof(queryMetrics)); } - this.QueryMetricsList.Add(queryMetrics); + this.queryMetricsList.Add(queryMetrics); } public QueryMetrics GetQueryMetrics() @@ -32,7 +32,7 @@ public QueryMetrics GetQueryMetrics() IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator = new IndexUtilizationInfoAccumulator(); ClientSideMetricsAccumulator clientSideMetricsAccumulator = new ClientSideMetricsAccumulator(); - foreach (QueryMetrics queryMetrics in this.QueryMetricsList) + foreach (QueryMetrics queryMetrics in this.queryMetricsList) { backendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics); indexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs index ece818367c..555ad1cc2b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs @@ -9,13 +9,13 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class QueryPreparationTimesAccumulator { + private readonly List queryPreparationTimesList; + public QueryPreparationTimesAccumulator() { - this.QueryPreparationTimesList = new List(); + this.queryPreparationTimesList = new List(); } - private readonly List QueryPreparationTimesList; - public void Accumulate(QueryPreparationTimes queryPreparationTimes) { if (queryPreparationTimes == null) @@ -23,17 +23,17 @@ public void Accumulate(QueryPreparationTimes queryPreparationTimes) throw new ArgumentNullException(nameof(queryPreparationTimes)); } - this.QueryPreparationTimesList.Add(queryPreparationTimes); + this.queryPreparationTimesList.Add(queryPreparationTimes); } public QueryPreparationTimes GetQueryPreparationTimes() { - TimeSpan queryCompilationTime; - TimeSpan logicalPlanBuildTime; - TimeSpan physicalPlanBuildTime; - TimeSpan queryOptimizationTime; + TimeSpan queryCompilationTime = TimeSpan.Zero; + TimeSpan logicalPlanBuildTime = TimeSpan.Zero; + TimeSpan physicalPlanBuildTime = TimeSpan.Zero; + TimeSpan queryOptimizationTime = TimeSpan.Zero; - foreach (QueryPreparationTimes queryPreparationTimes in this.QueryPreparationTimesList) + foreach (QueryPreparationTimes queryPreparationTimes in this.queryPreparationTimesList) { queryCompilationTime += queryPreparationTimes.QueryCompilationTime; logicalPlanBuildTime += queryPreparationTimes.LogicalPlanBuildTime; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs index e5bc24ddef..c8784a9798 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs @@ -9,13 +9,13 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class RuntimeExecutionTimesAccumulator { + private readonly List runtimeExecutionTimesList; + public RuntimeExecutionTimesAccumulator() { - this.RuntimeExecutionTimesList = new List(); + this.runtimeExecutionTimesList = new List(); } - private readonly List RuntimeExecutionTimesList; - public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) { if (runtimeExecutionTimes == null) @@ -23,16 +23,16 @@ public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) throw new ArgumentNullException(nameof(runtimeExecutionTimes)); } - this.RuntimeExecutionTimesList.Add(runtimeExecutionTimes); + this.runtimeExecutionTimesList.Add(runtimeExecutionTimes); } public RuntimeExecutionTimes GetRuntimeExecutionTimes() { - TimeSpan queryEngineExecutionTime = default; - TimeSpan systemFunctionExecutionTime = default; - TimeSpan userDefinedFunctionExecutionTime = default; + TimeSpan queryEngineExecutionTime = TimeSpan.Zero; + TimeSpan systemFunctionExecutionTime = TimeSpan.Zero; + TimeSpan userDefinedFunctionExecutionTime = TimeSpan.Zero; - foreach (RuntimeExecutionTimes runtimeExecutionTimes in this.RuntimeExecutionTimesList) + foreach (RuntimeExecutionTimes runtimeExecutionTimes in this.runtimeExecutionTimesList) { queryEngineExecutionTime += runtimeExecutionTimes.QueryEngineExecutionTime; systemFunctionExecutionTime += runtimeExecutionTimes.SystemFunctionExecutionTime; From d320017a5f738a66b3dba92f218d51d11dd9c119 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 1 Aug 2023 16:28:45 -0700 Subject: [PATCH 18/43] small fix --- .../Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs index 0bd2b60f46..89a1e193db 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs @@ -43,10 +43,10 @@ public IndexUtilizationInfo GetIndexUtilizationInfo() } return new IndexUtilizationInfo( - utilizedSingleIndexes: utilizedSingleIndexes.ToList(), - potentialSingleIndexes: potentialSingleIndexes.ToList(), - utilizedCompositeIndexes: utilizedCompositeIndexes.ToList(), - potentialCompositeIndexes: potentialCompositeIndexes.ToList()); + utilizedSingleIndexes: utilizedSingleIndexes, + potentialSingleIndexes: potentialSingleIndexes, + utilizedCompositeIndexes: utilizedCompositeIndexes, + potentialCompositeIndexes: potentialCompositeIndexes); } } } From edc5aabb6c4a4a9039ce5fea7f69e2e05435c054 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 2 Aug 2023 10:34:36 -0700 Subject: [PATCH 19/43] Rename BE -> ServerSide --- .../src/Diagnostics/CosmosDiagnostics.cs | 2 +- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 6 +-- .../Core/Metrics/BackendMetricsParser.cs | 8 ++-- .../Core/Metrics/BackendMetricsTokenizer.cs | 2 +- .../Query/Core/Metrics/BackendMetricsUtils.cs | 2 +- .../src/Query/Core/Metrics/QueryMetrics.cs | 8 ++-- .../Core/Metrics/QueryMetricsAccumulator.cs | 2 +- ...BackendMetrics.cs => ServerSideMetrics.cs} | 20 +++++----- ...tor.cs => ServerSideMetricsAccumulator.cs} | 18 ++++----- .../CosmosTraceDiagnosticsTests.cs | 6 +-- .../Query/Metrics/Performance.cs | 2 +- .../Query/Metrics/QueryMetricsTests.cs | 8 ++-- ...ricsTests.cs => ServerSideMetricsTests.cs} | 40 +++++++++---------- .../Tracing/TraceWriterBaselineTests.cs | 4 +- 14 files changed, 63 insertions(+), 65 deletions(-) rename Microsoft.Azure.Cosmos/src/Query/Core/Metrics/{BackendMetrics.cs => ServerSideMetrics.cs} (89%) rename Microsoft.Azure.Cosmos/src/Query/Core/Metrics/{BackendMetricsAccumulator.cs => ServerSideMetricsAccumulator.cs} (88%) rename Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/{BackendMetricsTests.cs => ServerSideMetricsTests.cs} (87%) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs index 412ee95460..98e2ddaf42 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs @@ -48,7 +48,7 @@ public virtual int GetFailedRequestCount() /// This represents the accumulated backend query metrics for the request. /// /// The accumulated backend metrics for the request. - public virtual BackendMetrics GetQueryMetrics() + public virtual ServerSideMetrics GetQueryMetrics() { // Default implementation avoids breaking change for users upgrading. throw new NotImplementedException($"{nameof(CosmosDiagnostics)}.{nameof(GetQueryMetrics)}"); diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index ee4be9f81c..baf8c6ac69 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -49,10 +49,10 @@ public override TimeSpan GetClientElapsedTime() return this.Value?.Summary?.RegionsContacted; } - public override BackendMetrics GetQueryMetrics() + public override ServerSideMetrics GetQueryMetrics() { - BackendMetricsAccumulator accumulator = new BackendMetricsAccumulator(); - BackendMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); + ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); + ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); return accumulator.GetBackendMetrics(); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsParser.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsParser.cs index ecd5becdd4..a06e98484f 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsParser.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsParser.cs @@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Text; /// - /// Parser for . + /// Parser for . /// #if INTERNAL #pragma warning disable SA1600 @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics #endif static class BackendMetricsParser { - public static unsafe bool TryParse(string deliminatedString, out BackendMetrics backendMetrics) + public static unsafe bool TryParse(string deliminatedString, out ServerSideMetrics backendMetrics) { if (deliminatedString == null) { @@ -30,7 +30,7 @@ public static unsafe bool TryParse(string deliminatedString, out BackendMetrics { // Stack allocating a zero length buffer returns a null pointer // so we special case the zero length string. - backendMetrics = BackendMetrics.Empty; + backendMetrics = ServerSideMetrics.Empty; return true; } @@ -258,7 +258,7 @@ public static unsafe bool TryParse(string deliminatedString, out BackendMetrics } } - backendMetrics = new BackendMetrics( + backendMetrics = new ServerSideMetrics( retrievedDocumentCount: retrievedDocumentCount, retrievedDocumentSize: retrievedDocumentSize, outputDocumentCount: outputDocumentCount, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsTokenizer.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsTokenizer.cs index f17e6afbf4..ef0b2fd3ec 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsTokenizer.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsTokenizer.cs @@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Text; /// - /// Tokenizer for + /// Tokenizer for /// #if INTERNAL #pragma warning disable SA1600 diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs index 32eee6a099..c2988f944c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs @@ -5,7 +5,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { internal static class BackendMetricsUtils { - public static string FormatTrace(this BackendMetrics backendMetrics) + public static string FormatTrace(this ServerSideMetrics backendMetrics) { return $"totalExecutionTimeInMs={backendMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={backendMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={backendMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={backendMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={backendMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={backendMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={backendMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={backendMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={backendMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={backendMetrics.RetrievedDocumentCount};retrievedDocumentSize={backendMetrics.RetrievedDocumentSize};outputDocumentCount={backendMetrics.OutputDocumentCount};outputDocumentSize={backendMetrics.OutputDocumentSize};writeOutputTimeInMs={backendMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={backendMetrics.IndexHitRatio}"; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs index 3e621c2044..62c908ceae 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs @@ -29,7 +29,7 @@ sealed class QueryMetrics clientSideMetrics: ClientSideMetrics.Empty); public QueryMetrics( - BackendMetrics backendMetrics, + ServerSideMetrics backendMetrics, IndexUtilizationInfo indexUtilizationInfo, ClientSideMetrics clientSideMetrics) { @@ -43,13 +43,13 @@ public QueryMetrics( IndexUtilizationInfo indexUtilizationInfo, ClientSideMetrics clientSideMetrics) : this(!String.IsNullOrWhiteSpace(deliminatedString) && - BackendMetricsParser.TryParse(deliminatedString, out BackendMetrics backendMetrics) + BackendMetricsParser.TryParse(deliminatedString, out ServerSideMetrics backendMetrics) ? backendMetrics - : BackendMetrics.Empty, indexUtilizationInfo, clientSideMetrics) + : ServerSideMetrics.Empty, indexUtilizationInfo, clientSideMetrics) { } - public BackendMetrics BackendMetrics { get; } + public ServerSideMetrics BackendMetrics { get; } public IndexUtilizationInfo IndexUtilizationInfo { get; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs index e8f11ec20c..af9be04230 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs @@ -28,7 +28,7 @@ public void Accumulate(QueryMetrics queryMetrics) public QueryMetrics GetQueryMetrics() { - BackendMetricsAccumulator backendMetricsAccumulator = new BackendMetricsAccumulator(); + ServerSideMetricsAccumulator backendMetricsAccumulator = new ServerSideMetricsAccumulator(); IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator = new IndexUtilizationInfoAccumulator(); ClientSideMetricsAccumulator clientSideMetricsAccumulator = new ClientSideMetricsAccumulator(); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs similarity index 89% rename from Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs rename to Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index c6f824a85a..3b32023f83 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -10,12 +10,12 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// /// Metrics received for queries from the backend. /// - public sealed class BackendMetrics + public sealed class ServerSideMetrics { /// /// QueryMetrics that with all members having default (but not null) members. /// - internal static readonly BackendMetrics Empty = new BackendMetrics( + internal static readonly ServerSideMetrics Empty = new ServerSideMetrics( retrievedDocumentCount: default, retrievedDocumentSize: default, outputDocumentCount: default, @@ -30,7 +30,7 @@ public sealed class BackendMetrics documentWriteTime: default); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// @@ -44,7 +44,7 @@ public sealed class BackendMetrics /// /// /// - public BackendMetrics( + public ServerSideMetrics( long retrievedDocumentCount, long retrievedDocumentSize, long outputDocumentCount, @@ -132,10 +132,10 @@ public BackendMetrics( /// public TimeSpan VMExecutionTime { get; } - internal static BackendMetrics Create(IEnumerable backendMetricsEnumerable) + internal static ServerSideMetrics Create(IEnumerable backendMetricsEnumerable) { - BackendMetricsAccumulator accumulator = default; - foreach (BackendMetrics backendMetrics in backendMetricsEnumerable) + ServerSideMetricsAccumulator accumulator = default; + foreach (ServerSideMetrics backendMetrics in backendMetricsEnumerable) { accumulator.Accumulate(backendMetrics); } @@ -143,14 +143,14 @@ internal static BackendMetrics Create(IEnumerable backendMetrics return accumulator.GetBackendMetrics(); } - internal static bool TryParseFromDelimitedString(string delimitedString, out BackendMetrics backendMetrics) + internal static bool TryParseFromDelimitedString(string delimitedString, out ServerSideMetrics backendMetrics) { return BackendMetricsParser.TryParse(delimitedString, out backendMetrics); } - internal static BackendMetrics ParseFromDelimitedString(string delimitedString) + internal static ServerSideMetrics ParseFromDelimitedString(string delimitedString) { - if (!BackendMetricsParser.TryParse(delimitedString, out BackendMetrics backendMetrics)) + if (!BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics backendMetrics)) { throw new FormatException(); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs similarity index 88% rename from Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs rename to Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index 48fca2c87a..95aaa5edb3 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -9,16 +9,16 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using Microsoft.Azure.Cosmos.Tracing; using Microsoft.Azure.Cosmos.Tracing.TraceData; - internal class BackendMetricsAccumulator + internal class ServerSideMetricsAccumulator { - private readonly List backendMetricsList; + private readonly List backendMetricsList; - public BackendMetricsAccumulator() + public ServerSideMetricsAccumulator() { - this.backendMetricsList = new List(); + this.backendMetricsList = new List(); } - public void Accumulate(BackendMetrics backendMetrics) + public void Accumulate(ServerSideMetrics backendMetrics) { if (backendMetrics == null) { @@ -28,7 +28,7 @@ public void Accumulate(BackendMetrics backendMetrics) this.backendMetricsList.Add(backendMetrics); } - public BackendMetrics GetBackendMetrics() + public ServerSideMetrics GetBackendMetrics() { TimeSpan totalTime = TimeSpan.Zero; long retrievedDocumentCount = 0; @@ -43,7 +43,7 @@ public BackendMetrics GetBackendMetrics() TimeSpan documentWriteTime = TimeSpan.Zero; TimeSpan vMExecutionTime = TimeSpan.Zero; - foreach (BackendMetrics backendMetrics in this.backendMetricsList) + foreach (ServerSideMetrics backendMetrics in this.backendMetricsList) { indexHitRatio = ((outputDocumentCount * indexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (retrievedDocumentCount + backendMetrics.RetrievedDocumentCount); totalTime += backendMetrics.TotalTime; @@ -59,7 +59,7 @@ public BackendMetrics GetBackendMetrics() vMExecutionTime += backendMetrics.VMExecutionTime; } - return new BackendMetrics( + return new ServerSideMetrics( retrievedDocumentCount: retrievedDocumentCount, retrievedDocumentSize: retrievedDocumentSize, outputDocumentCount: outputDocumentCount, @@ -74,7 +74,7 @@ public BackendMetrics GetBackendMetrics() documentWriteTime: documentWriteTime); } - public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, BackendMetricsAccumulator accumulator) + public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideMetricsAccumulator accumulator) { if (currentTrace == null) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index a738546ef2..862d25e30c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -71,7 +71,7 @@ private async Task ValidateMetrics(int throughput) requestOptions: requestOptions); bool found = false; - BackendMetricsAccumulator headerMetricsAccumulator = new BackendMetricsAccumulator(); + ServerSideMetricsAccumulator headerMetricsAccumulator = new ServerSideMetricsAccumulator(); while (feedIterator.HasMoreResults) { FeedResponse iter = await feedIterator.ReadNextAsync(); @@ -83,8 +83,8 @@ private async Task ValidateMetrics(int throughput) Assert.AreEqual(find.id, response.id); } - BackendMetrics backendMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); - bool tryParseResult = BackendMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out BackendMetrics backendMetricsFromHeaders); + ServerSideMetrics backendMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); + bool tryParseResult = ServerSideMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out ServerSideMetrics backendMetricsFromHeaders); Assert.IsTrue(tryParseResult); headerMetricsAccumulator.Accumulate(backendMetricsFromHeaders); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs index 6d5db62d6d..3c26fb5fdf 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs @@ -37,7 +37,7 @@ public void TestParse() ValueStopwatch stopwatch = ValueStopwatch.StartNew(); for (int i = 0; i < 100000; i++) { - BackendMetricsParser.TryParse(delimitedString, out BackendMetrics backendMetrics); + BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics backendMetrics); } stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs index 4adbb582ad..23ba77b8d3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos.Tests.Query.Metrics public class QueryMetricsTests { private static readonly QueryMetrics MockQueryMetrics = new QueryMetrics( - BackendMetricsTests.MockBackendMetrics, + ServerSideMetricsTests.MockBackendMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics); @@ -26,7 +26,7 @@ public void TestAccumulator() QueryMetrics doubleQueryMetrics = accumulator.GetQueryMetrics(); // Spot check - Assert.AreEqual(2 * BackendMetricsTests.MockBackendMetrics.IndexLookupTime, doubleQueryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreEqual(2 * ServerSideMetricsTests.MockBackendMetrics.IndexLookupTime, doubleQueryMetrics.BackendMetrics.IndexLookupTime); Assert.AreEqual(2 * IndexUtilizationInfoTests.MockIndexUtilizationInfo.PotentialSingleIndexes.Count, doubleQueryMetrics.IndexUtilizationInfo.PotentialSingleIndexes.Count); Assert.AreEqual(2 * ClientSideMetricsTests.MockClientSideMetrics.RequestCharge, doubleQueryMetrics.ClientSideMetrics.RequestCharge); } @@ -37,7 +37,7 @@ public void TestAddition() QueryMetrics doubleQueryMetrics = MockQueryMetrics + MockQueryMetrics; // Spot check - Assert.AreEqual(2 * BackendMetricsTests.MockBackendMetrics.IndexLookupTime, doubleQueryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreEqual(2 * ServerSideMetricsTests.MockBackendMetrics.IndexLookupTime, doubleQueryMetrics.BackendMetrics.IndexLookupTime); Assert.AreEqual(2 * IndexUtilizationInfoTests.MockIndexUtilizationInfo.PotentialSingleIndexes.Count, doubleQueryMetrics.IndexUtilizationInfo.PotentialSingleIndexes.Count); Assert.AreEqual(2 * ClientSideMetricsTests.MockClientSideMetrics.RequestCharge, doubleQueryMetrics.ClientSideMetrics.RequestCharge); } @@ -48,7 +48,7 @@ public void TestCreateFromEnumerable() QueryMetrics tripleQueryMetrics = QueryMetrics.CreateFromIEnumerable(new List() { MockQueryMetrics, MockQueryMetrics, MockQueryMetrics }); // Spot check - Assert.AreEqual(3 * BackendMetricsTests.MockBackendMetrics.IndexLookupTime, tripleQueryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreEqual(3 * ServerSideMetricsTests.MockBackendMetrics.IndexLookupTime, tripleQueryMetrics.BackendMetrics.IndexLookupTime); Assert.AreEqual(3 * IndexUtilizationInfoTests.MockIndexUtilizationInfo.PotentialSingleIndexes.Count, tripleQueryMetrics.IndexUtilizationInfo.PotentialSingleIndexes.Count); Assert.AreEqual(3 * ClientSideMetricsTests.MockClientSideMetrics.RequestCharge, tripleQueryMetrics.ClientSideMetrics.RequestCharge); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs similarity index 87% rename from Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs rename to Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs index 2ea3ace6bc..d6f05562ef 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/BackendMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs @@ -7,11 +7,9 @@ namespace Microsoft.Azure.Cosmos.Tests.Query.Metrics using System; using VisualStudio.TestTools.UnitTesting; using Microsoft.Azure.Cosmos.Query.Core.Metrics; - using System.Diagnostics; - using System.Collections.Generic; [TestClass] - public class BackendMetricsTests + public class ServerSideMetricsTests { private static readonly TimeSpan totalExecutionTime = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 33.67)); private static readonly TimeSpan queryCompileTime = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 0.06)); @@ -32,7 +30,7 @@ public class BackendMetricsTests private static readonly string delimitedString = $"totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds};queryCompileTimeInMs={queryCompileTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={logicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={physicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={queryOptimizationTime.TotalMilliseconds};VMExecutionTimeInMs={vmExecutionTime.TotalMilliseconds};indexLookupTimeInMs={indexLookupTime.TotalMilliseconds};documentLoadTimeInMs={documentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={systemFunctionExecuteTime.TotalMilliseconds};userFunctionExecuteTimeInMs={userFunctionExecuteTime.TotalMilliseconds};retrievedDocumentCount={retrievedDocumentCount};retrievedDocumentSize={retrievedDocumentSize};outputDocumentCount={outputDocumentCount};outputDocumentSize={outputDocumentSize};writeOutputTimeInMs={documentWriteTime.TotalMilliseconds};indexUtilizationRatio={indexHitRatio}"; - internal static readonly BackendMetrics MockBackendMetrics = new BackendMetrics( + internal static readonly ServerSideMetrics MockBackendMetrics = new ServerSideMetrics( retrievedDocumentCount, retrievedDocumentSize, outputDocumentCount, @@ -57,13 +55,13 @@ public class BackendMetricsTests [TestMethod] public void TestParse() { - BackendMetricsTests.ValidateParse(delimitedString, MockBackendMetrics); + ServerSideMetricsTests.ValidateParse(delimitedString, MockBackendMetrics); } [TestMethod] public void TestParseEmptyString() { - BackendMetricsTests.ValidateParse(string.Empty, BackendMetrics.Empty); + ServerSideMetricsTests.ValidateParse(string.Empty, ServerSideMetrics.Empty); } [TestMethod] @@ -72,7 +70,7 @@ public void TestParseStringWithMissingFields() TimeSpan totalExecutionTime = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 33.67)); string delimitedString = $"totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds}"; - BackendMetrics expected = new BackendMetrics( + ServerSideMetrics expected = new ServerSideMetrics( default(long), default(long), default(long), @@ -93,14 +91,14 @@ public void TestParseStringWithMissingFields() default(TimeSpan)), default(TimeSpan)); - BackendMetricsTests.ValidateParse(delimitedString, expected); + ServerSideMetricsTests.ValidateParse(delimitedString, expected); } [TestMethod] public void TestParseStringWithTrailingUnknownField() { string delimitedString = $"thisIsNotAKnownField=asdf"; - BackendMetrics expected = new BackendMetrics( + ServerSideMetrics expected = new ServerSideMetrics( default(long), default(long), default(long), @@ -121,7 +119,7 @@ public void TestParseStringWithTrailingUnknownField() default(TimeSpan)), default(TimeSpan)); - BackendMetricsTests.ValidateParse(delimitedString, expected); + ServerSideMetricsTests.ValidateParse(delimitedString, expected); } [TestMethod] @@ -129,7 +127,7 @@ public void TestParseStringWithTrailingUnknownField() [DataRow("totalExecutionTimeInMs=33.6+totalExecutionTimeInMs=33.6", DisplayName = "Wrong Delimiter")] public void TestNegativeCases(string delimitedString) { - Assert.IsFalse(BackendMetricsParser.TryParse(delimitedString, out BackendMetrics backendMetrics)); + Assert.IsFalse(BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics backendMetrics)); } [TestMethod] @@ -137,7 +135,7 @@ public void TestParseStringWithUnknownField() { TimeSpan totalExecutionTime = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 33.67)); string delimitedString = $"totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds};thisIsNotAKnownField={totalExecutionTime.TotalMilliseconds};totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds}"; - BackendMetrics expected = new BackendMetrics( + ServerSideMetrics expected = new ServerSideMetrics( default(long), default(long), default(long), @@ -158,18 +156,18 @@ public void TestParseStringWithUnknownField() default(TimeSpan)), default(TimeSpan)); - BackendMetricsTests.ValidateParse(delimitedString, expected); + ServerSideMetricsTests.ValidateParse(delimitedString, expected); } [TestMethod] public void TestAccumulator() { - BackendMetricsAccumulator accumulator = new BackendMetricsAccumulator(); + ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); accumulator.Accumulate(MockBackendMetrics); accumulator.Accumulate(MockBackendMetrics); - BackendMetrics backendMetricsFromAddition = accumulator.GetBackendMetrics(); - BackendMetrics expected = new BackendMetrics( + ServerSideMetrics backendMetricsFromAddition = accumulator.GetBackendMetrics(); + ServerSideMetrics expected = new ServerSideMetrics( retrievedDocumentCount * 2, retrievedDocumentSize * 2, outputDocumentCount * 2, @@ -190,16 +188,16 @@ public void TestAccumulator() userFunctionExecuteTime * 2), documentWriteTime * 2); - BackendMetricsTests.ValidateBackendMetricsEquals(expected, backendMetricsFromAddition); + ServerSideMetricsTests.ValidateBackendMetricsEquals(expected, backendMetricsFromAddition); } - private static void ValidateParse(string delimitedString, BackendMetrics expected) + private static void ValidateParse(string delimitedString, ServerSideMetrics expected) { - Assert.IsTrue(BackendMetricsParser.TryParse(delimitedString, out BackendMetrics actual)); - BackendMetricsTests.ValidateBackendMetricsEquals(expected, actual); + Assert.IsTrue(BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics actual)); + ServerSideMetricsTests.ValidateBackendMetricsEquals(expected, actual); } - private static void ValidateBackendMetricsEquals(BackendMetrics expected, BackendMetrics actual) + private static void ValidateBackendMetricsEquals(ServerSideMetrics expected, ServerSideMetrics actual) { Assert.AreEqual(expected.DocumentLoadTime, actual.DocumentLoadTime); Assert.AreEqual(expected.DocumentWriteTime, actual.DocumentWriteTime); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs index fe3dc7054f..7bb961eb25 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs @@ -41,7 +41,7 @@ namespace Microsoft.Azure.Cosmos.Tests.Tracing public sealed class TraceWriterBaselineTests : BaselineTests { private static readonly Lazy MockQueryMetrics = new Lazy(() => new QueryMetrics( - BackendMetricsTests.MockBackendMetrics, + ServerSideMetricsTests.MockBackendMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics)); @@ -316,7 +316,7 @@ public void TraceData() { QueryMetricsTraceDatum datum = new QueryMetricsTraceDatum( new Lazy(() => new QueryMetrics( - BackendMetricsTests.MockBackendMetrics, + ServerSideMetricsTests.MockBackendMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics))); rootTrace.AddDatum("Query Metrics", datum); From b64d837bbcbaed0aec07d5e87db0d01950af08ac Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 2 Aug 2023 10:49:20 -0700 Subject: [PATCH 20/43] more renaming --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 2 +- .../Query/Core/Metrics/BackendMetricsUtils.cs | 13 -- .../src/Query/Core/Metrics/QueryMetrics.cs | 10 +- .../Core/Metrics/QueryMetricsAccumulator.cs | 6 +- .../Query/Core/Metrics/QueryMetricsWriter.cs | 24 +-- .../Query/Core/Metrics/ServerSideMetrics.cs | 16 +- .../Metrics/ServerSideMetricsAccumulator.cs | 42 ++--- ...csParser.cs => ServerSideMetricsParser.cs} | 158 +++++++++--------- ...nizer.cs => ServerSideMetricsTokenizer.cs} | 2 +- .../Core/Metrics/ServerSideMetricsUtils.cs | 13 ++ .../CosmosTraceDiagnosticsTests.cs | 8 +- .../QueryStatisticsDatumVisitor.cs | 14 +- .../QueryTests.cs | 26 +-- .../Query/Metrics/Performance.cs | 2 +- .../TraceWriterBaselineTests.TraceData.xml | 5 +- .../Query/Metrics/QueryMetricsTests.cs | 8 +- .../Query/Metrics/ServerSideMetricsTests.cs | 20 +-- .../Tracing/TraceWriterBaselineTests.cs | 4 +- 18 files changed, 187 insertions(+), 186 deletions(-) delete mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs rename Microsoft.Azure.Cosmos/src/Query/Core/Metrics/{BackendMetricsParser.cs => ServerSideMetricsParser.cs} (54%) rename Microsoft.Azure.Cosmos/src/Query/Core/Metrics/{BackendMetricsTokenizer.cs => ServerSideMetricsTokenizer.cs} (99%) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index baf8c6ac69..80cdc0c823 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -53,7 +53,7 @@ public override ServerSideMetrics GetQueryMetrics() { ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - return accumulator.GetBackendMetrics(); + return accumulator.GetServerSideMetrics(); } internal bool IsGoneExceptionHit() diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs deleted file mode 100644 index c2988f944c..0000000000 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsUtils.cs +++ /dev/null @@ -1,13 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ -namespace Microsoft.Azure.Cosmos.Query.Core.Metrics -{ - internal static class BackendMetricsUtils - { - public static string FormatTrace(this ServerSideMetrics backendMetrics) - { - return $"totalExecutionTimeInMs={backendMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={backendMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={backendMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={backendMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={backendMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={backendMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={backendMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={backendMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={backendMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={backendMetrics.RetrievedDocumentCount};retrievedDocumentSize={backendMetrics.RetrievedDocumentSize};outputDocumentCount={backendMetrics.OutputDocumentCount};outputDocumentSize={backendMetrics.OutputDocumentSize};writeOutputTimeInMs={backendMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={backendMetrics.IndexHitRatio}"; - } - } -} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs index 62c908ceae..454df8d0e8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs @@ -29,11 +29,11 @@ sealed class QueryMetrics clientSideMetrics: ClientSideMetrics.Empty); public QueryMetrics( - ServerSideMetrics backendMetrics, + ServerSideMetrics serverSideMetrics, IndexUtilizationInfo indexUtilizationInfo, ClientSideMetrics clientSideMetrics) { - this.BackendMetrics = backendMetrics ?? throw new ArgumentNullException(nameof(backendMetrics)); + this.ServerSideMetrics = serverSideMetrics ?? throw new ArgumentNullException(nameof(serverSideMetrics)); this.IndexUtilizationInfo = indexUtilizationInfo ?? throw new ArgumentNullException(nameof(indexUtilizationInfo)); this.ClientSideMetrics = clientSideMetrics ?? throw new ArgumentNullException(nameof(clientSideMetrics)); } @@ -43,13 +43,13 @@ public QueryMetrics( IndexUtilizationInfo indexUtilizationInfo, ClientSideMetrics clientSideMetrics) : this(!String.IsNullOrWhiteSpace(deliminatedString) && - BackendMetricsParser.TryParse(deliminatedString, out ServerSideMetrics backendMetrics) - ? backendMetrics + ServerSideMetricsParser.TryParse(deliminatedString, out ServerSideMetrics serverSideMetrics) + ? serverSideMetrics : ServerSideMetrics.Empty, indexUtilizationInfo, clientSideMetrics) { } - public ServerSideMetrics BackendMetrics { get; } + public ServerSideMetrics ServerSideMetrics { get; } public IndexUtilizationInfo IndexUtilizationInfo { get; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs index af9be04230..ecfe6b92a6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs @@ -28,19 +28,19 @@ public void Accumulate(QueryMetrics queryMetrics) public QueryMetrics GetQueryMetrics() { - ServerSideMetricsAccumulator backendMetricsAccumulator = new ServerSideMetricsAccumulator(); + ServerSideMetricsAccumulator serverSideMetricsAccumulator = new ServerSideMetricsAccumulator(); IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator = new IndexUtilizationInfoAccumulator(); ClientSideMetricsAccumulator clientSideMetricsAccumulator = new ClientSideMetricsAccumulator(); foreach (QueryMetrics queryMetrics in this.queryMetricsList) { - backendMetricsAccumulator.Accumulate(queryMetrics.BackendMetrics); + serverSideMetricsAccumulator.Accumulate(queryMetrics.ServerSideMetrics); indexUtilizationInfoAccumulator.Accumulate(queryMetrics.IndexUtilizationInfo); clientSideMetricsAccumulator.Accumulate(queryMetrics.ClientSideMetrics); } return new QueryMetrics( - backendMetricsAccumulator.GetBackendMetrics(), + serverSideMetricsAccumulator.GetServerSideMetrics(), indexUtilizationInfoAccumulator.GetIndexUtilizationInfo(), clientSideMetricsAccumulator.GetClientSideMetrics()); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs index 2fbb455152..744f466e23 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs @@ -23,25 +23,25 @@ public void WriteQueryMetrics(QueryMetrics queryMetrics) this.WriteBeforeQueryMetrics(); // Top Level Properties - this.WriteRetrievedDocumentCount(queryMetrics.BackendMetrics.RetrievedDocumentCount); - this.WriteRetrievedDocumentSize(queryMetrics.BackendMetrics.RetrievedDocumentSize); - this.WriteOutputDocumentCount(queryMetrics.BackendMetrics.OutputDocumentCount); - this.WriteOutputDocumentSize(queryMetrics.BackendMetrics.OutputDocumentSize); - this.WriteIndexHitRatio(queryMetrics.BackendMetrics.IndexHitRatio); + this.WriteRetrievedDocumentCount(queryMetrics.ServerSideMetrics.RetrievedDocumentCount); + this.WriteRetrievedDocumentSize(queryMetrics.ServerSideMetrics.RetrievedDocumentSize); + this.WriteOutputDocumentCount(queryMetrics.ServerSideMetrics.OutputDocumentCount); + this.WriteOutputDocumentSize(queryMetrics.ServerSideMetrics.OutputDocumentSize); + this.WriteIndexHitRatio(queryMetrics.ServerSideMetrics.IndexHitRatio); - this.WriteTotalQueryExecutionTime(queryMetrics.BackendMetrics.TotalTime); + this.WriteTotalQueryExecutionTime(queryMetrics.ServerSideMetrics.TotalTime); // QueryPreparationTimes - this.WriteQueryPreparationTime(queryMetrics.BackendMetrics.QueryPreparationTimes); + this.WriteQueryPreparationTime(queryMetrics.ServerSideMetrics.QueryPreparationTimes); - this.WriteIndexLookupTime(queryMetrics.BackendMetrics.IndexLookupTime); - this.WriteDocumentLoadTime(queryMetrics.BackendMetrics.DocumentLoadTime); - this.WriteVMExecutionTime(queryMetrics.BackendMetrics.VMExecutionTime); + this.WriteIndexLookupTime(queryMetrics.ServerSideMetrics.IndexLookupTime); + this.WriteDocumentLoadTime(queryMetrics.ServerSideMetrics.DocumentLoadTime); + this.WriteVMExecutionTime(queryMetrics.ServerSideMetrics.VMExecutionTime); // RuntimesExecutionTimes - this.WriteRuntimeExecutionTime(queryMetrics.BackendMetrics.RuntimeExecutionTimes); + this.WriteRuntimeExecutionTime(queryMetrics.ServerSideMetrics.RuntimeExecutionTimes); - this.WriteDocumentWriteTime(queryMetrics.BackendMetrics.DocumentWriteTime); + this.WriteDocumentWriteTime(queryMetrics.ServerSideMetrics.DocumentWriteTime); #if false // ClientSideMetrics this.WriteClientSideMetrics(queryMetrics.ClientSideMetrics); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 3b32023f83..d68125401b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -132,30 +132,30 @@ public ServerSideMetrics( /// public TimeSpan VMExecutionTime { get; } - internal static ServerSideMetrics Create(IEnumerable backendMetricsEnumerable) + internal static ServerSideMetrics Create(IEnumerable serverSideMetricsEnumerable) { ServerSideMetricsAccumulator accumulator = default; - foreach (ServerSideMetrics backendMetrics in backendMetricsEnumerable) + foreach (ServerSideMetrics serverSideMetrics in serverSideMetricsEnumerable) { - accumulator.Accumulate(backendMetrics); + accumulator.Accumulate(serverSideMetrics); } - return accumulator.GetBackendMetrics(); + return accumulator.GetServerSideMetrics(); } - internal static bool TryParseFromDelimitedString(string delimitedString, out ServerSideMetrics backendMetrics) + internal static bool TryParseFromDelimitedString(string delimitedString, out ServerSideMetrics serverSideMetrics) { - return BackendMetricsParser.TryParse(delimitedString, out backendMetrics); + return ServerSideMetricsParser.TryParse(delimitedString, out serverSideMetrics); } internal static ServerSideMetrics ParseFromDelimitedString(string delimitedString) { - if (!BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics backendMetrics)) + if (!ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics serverSideMetrics)) { throw new FormatException(); } - return backendMetrics; + return serverSideMetrics; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index 95aaa5edb3..4dd0478985 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -11,24 +11,24 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class ServerSideMetricsAccumulator { - private readonly List backendMetricsList; + private readonly List serverSideMetricsList; public ServerSideMetricsAccumulator() { - this.backendMetricsList = new List(); + this.serverSideMetricsList = new List(); } - public void Accumulate(ServerSideMetrics backendMetrics) + public void Accumulate(ServerSideMetrics serverSideMetrics) { - if (backendMetrics == null) + if (serverSideMetrics == null) { - throw new ArgumentNullException(nameof(backendMetrics)); + throw new ArgumentNullException(nameof(serverSideMetrics)); } - this.backendMetricsList.Add(backendMetrics); + this.serverSideMetricsList.Add(serverSideMetrics); } - public ServerSideMetrics GetBackendMetrics() + public ServerSideMetrics GetServerSideMetrics() { TimeSpan totalTime = TimeSpan.Zero; long retrievedDocumentCount = 0; @@ -43,20 +43,20 @@ public ServerSideMetrics GetBackendMetrics() TimeSpan documentWriteTime = TimeSpan.Zero; TimeSpan vMExecutionTime = TimeSpan.Zero; - foreach (ServerSideMetrics backendMetrics in this.backendMetricsList) + foreach (ServerSideMetrics serverSideMetrics in this.serverSideMetricsList) { - indexHitRatio = ((outputDocumentCount * indexHitRatio) + (backendMetrics.OutputDocumentCount * backendMetrics.IndexHitRatio)) / (retrievedDocumentCount + backendMetrics.RetrievedDocumentCount); - totalTime += backendMetrics.TotalTime; - retrievedDocumentCount += backendMetrics.RetrievedDocumentCount; - retrievedDocumentSize += backendMetrics.RetrievedDocumentSize; - outputDocumentCount += backendMetrics.OutputDocumentCount; - outputDocumentSize += backendMetrics.OutputDocumentSize; - queryPreparationTimesAccumulator.Accumulate(backendMetrics.QueryPreparationTimes); - indexLookupTime += backendMetrics.IndexLookupTime; - documentLoadTime += backendMetrics.DocumentLoadTime; - runtimeExecutionTimesAccumulator.Accumulate(backendMetrics.RuntimeExecutionTimes); - documentWriteTime += backendMetrics.DocumentWriteTime; - vMExecutionTime += backendMetrics.VMExecutionTime; + indexHitRatio = ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount); + totalTime += serverSideMetrics.TotalTime; + retrievedDocumentCount += serverSideMetrics.RetrievedDocumentCount; + retrievedDocumentSize += serverSideMetrics.RetrievedDocumentSize; + outputDocumentCount += serverSideMetrics.OutputDocumentCount; + outputDocumentSize += serverSideMetrics.OutputDocumentSize; + queryPreparationTimesAccumulator.Accumulate(serverSideMetrics.QueryPreparationTimes); + indexLookupTime += serverSideMetrics.IndexLookupTime; + documentLoadTime += serverSideMetrics.DocumentLoadTime; + runtimeExecutionTimesAccumulator.Accumulate(serverSideMetrics.RuntimeExecutionTimes); + documentWriteTime += serverSideMetrics.DocumentWriteTime; + vMExecutionTime += serverSideMetrics.VMExecutionTime; } return new ServerSideMetrics( @@ -85,7 +85,7 @@ public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideM { if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) { - accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.BackendMetrics); + accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics); return; } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsParser.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsParser.cs similarity index 54% rename from Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsParser.cs rename to Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsParser.cs index a06e98484f..bc21b849e9 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsParser.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsParser.cs @@ -17,9 +17,9 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics #else internal #endif - static class BackendMetricsParser + static class ServerSideMetricsParser { - public static unsafe bool TryParse(string deliminatedString, out ServerSideMetrics backendMetrics) + public static unsafe bool TryParse(string deliminatedString, out ServerSideMetrics serverSideMetrics) { if (deliminatedString == null) { @@ -30,7 +30,7 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri { // Stack allocating a zero length buffer returns a null pointer // so we special case the zero length string. - backendMetrics = ServerSideMetrics.Empty; + serverSideMetrics = ServerSideMetrics.Empty; return true; } @@ -72,7 +72,7 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri while (!corpus.IsEmpty) { - (BackendMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = BackendMetricsTokenizer.Read(corpus); + (ServerSideMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = ServerSideMetricsTokenizer.Read(corpus); int bytesConsumed; if (!tokenType.HasValue) @@ -95,162 +95,162 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri { switch (tokenType.Value) { - case BackendMetricsTokenizer.TokenType.DocumentLoadTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.DocumentLoadTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out documentLoadTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.DocumentLoadTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.DocumentLoadTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out documentLoadTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.WriteOutputTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.WriteOutputTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out documentWriteTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.WriteOutputTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.WriteOutputTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out documentWriteTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.IndexLookupTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.IndexLookupTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out indexLookupTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.IndexLookupTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.IndexLookupTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out indexLookupTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.IndexUtilizationRatio: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.IndexUtilizationRatio.Length); - if (!BackendMetricsParser.TryParseDoubleField(corpus, out indexHitRatio, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.IndexUtilizationRatio: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.IndexUtilizationRatio.Length); + if (!ServerSideMetricsParser.TryParseDoubleField(corpus, out indexHitRatio, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.QueryLogicalPlanBuildTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.QueryLogicalPlanBuildTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out logicalPlanBuildTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.QueryLogicalPlanBuildTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.QueryLogicalPlanBuildTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out logicalPlanBuildTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.OutputDocumentCount: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.OutputDocumentCount.Length); - if (!BackendMetricsParser.TryParseLongField(corpus, out outputDocumentCount, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.OutputDocumentCount: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.OutputDocumentCount.Length); + if (!ServerSideMetricsParser.TryParseLongField(corpus, out outputDocumentCount, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.OutputDocumentSize: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.OutputDocumentSize.Length); - if (!BackendMetricsParser.TryParseLongField(corpus, out outputDocumentSize, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.OutputDocumentSize: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.OutputDocumentSize.Length); + if (!ServerSideMetricsParser.TryParseLongField(corpus, out outputDocumentSize, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.QueryPhysicalPlanBuildTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.QueryPhysicalPlanBuildTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out physicalPlanBuildTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.QueryPhysicalPlanBuildTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.QueryPhysicalPlanBuildTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out physicalPlanBuildTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.QueryCompileTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.QueryCompileTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out queryCompilationTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.QueryCompileTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.QueryCompileTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out queryCompilationTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.QueryOptimizationTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.QueryOptimizationTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out queryOptimizationTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.QueryOptimizationTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.QueryOptimizationTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out queryOptimizationTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.RetrievedDocumentCount: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.RetrievedDocumentCount.Length); - if (!BackendMetricsParser.TryParseLongField(corpus, out retrievedDocumentCount, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.RetrievedDocumentCount: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.RetrievedDocumentCount.Length); + if (!ServerSideMetricsParser.TryParseLongField(corpus, out retrievedDocumentCount, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.RetrievedDocumentSize: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.RetrievedDocumentSize.Length); - if (!BackendMetricsParser.TryParseLongField(corpus, out retrievedDocumentSize, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.RetrievedDocumentSize: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.RetrievedDocumentSize.Length); + if (!ServerSideMetricsParser.TryParseLongField(corpus, out retrievedDocumentSize, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.SystemFunctionExecuteTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.SystemFunctionExecuteTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out systemFunctionExecutionTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.SystemFunctionExecuteTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.SystemFunctionExecuteTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out systemFunctionExecutionTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.TotalExecutionTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.TotalExecutionTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out totalQueryExecutionTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.TotalExecutionTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.TotalExecutionTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out totalQueryExecutionTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.UserFunctionExecuteTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.UserFunctionExecuteTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out userDefinedFunctionExecutionTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.UserFunctionExecuteTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.UserFunctionExecuteTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out userDefinedFunctionExecutionTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; - case BackendMetricsTokenizer.TokenType.VMExecutionTimeInMs: - corpus = corpus.Slice(BackendMetricsTokenizer.TokenBuffers.VMExecutionTimeInMs.Length); - if (!BackendMetricsParser.TryParseTimeSpanField(corpus, out vmExecutionTime, out bytesConsumed)) + case ServerSideMetricsTokenizer.TokenType.VMExecutionTimeInMs: + corpus = corpus.Slice(ServerSideMetricsTokenizer.TokenBuffers.VMExecutionTimeInMs.Length); + if (!ServerSideMetricsParser.TryParseTimeSpanField(corpus, out vmExecutionTime, out bytesConsumed)) { - backendMetrics = default; + serverSideMetrics = default; return false; } break; default: - backendMetrics = default; + serverSideMetrics = default; return false; } } corpus = corpus.Slice(bytesConsumed); if (!corpus.IsEmpty) { - (BackendMetricsTokenizer.TokenType? semicolonToken, ReadOnlyMemory semicolonBuffer) = BackendMetricsTokenizer.Read(corpus); - if (!semicolonToken.HasValue || (semicolonToken != BackendMetricsTokenizer.TokenType.SemiColonDelimiter)) + (ServerSideMetricsTokenizer.TokenType? semicolonToken, ReadOnlyMemory semicolonBuffer) = ServerSideMetricsTokenizer.Read(corpus); + if (!semicolonToken.HasValue || (semicolonToken != ServerSideMetricsTokenizer.TokenType.SemiColonDelimiter)) { - backendMetrics = default; + serverSideMetrics = default; return false; } @@ -258,7 +258,7 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri } } - backendMetrics = new ServerSideMetrics( + serverSideMetrics = new ServerSideMetrics( retrievedDocumentCount: retrievedDocumentCount, retrievedDocumentSize: retrievedDocumentSize, outputDocumentCount: outputDocumentCount, @@ -283,8 +283,8 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri private static bool TryParseTimeSpanField(ReadOnlySpan corpus, out TimeSpan timeSpan, out int bytesConsumed) { - (BackendMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = BackendMetricsTokenizer.Read(corpus); - if (!tokenType.HasValue || (tokenType.Value != BackendMetricsTokenizer.TokenType.EqualsDelimiter)) + (ServerSideMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = ServerSideMetricsTokenizer.Read(corpus); + if (!tokenType.HasValue || (tokenType.Value != ServerSideMetricsTokenizer.TokenType.EqualsDelimiter)) { timeSpan = default; bytesConsumed = default; @@ -306,8 +306,8 @@ private static bool TryParseTimeSpanField(ReadOnlySpan corpus, out TimeSpa private static bool TryParseLongField(ReadOnlySpan corpus, out long value, out int bytesConsumed) { - (BackendMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = BackendMetricsTokenizer.Read(corpus); - if (!tokenType.HasValue || (tokenType.Value != BackendMetricsTokenizer.TokenType.EqualsDelimiter)) + (ServerSideMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = ServerSideMetricsTokenizer.Read(corpus); + if (!tokenType.HasValue || (tokenType.Value != ServerSideMetricsTokenizer.TokenType.EqualsDelimiter)) { value = default; bytesConsumed = default; @@ -327,8 +327,8 @@ private static bool TryParseLongField(ReadOnlySpan corpus, out long value, private static bool TryParseDoubleField(ReadOnlySpan corpus, out double value, out int bytesConsumed) { - (BackendMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = BackendMetricsTokenizer.Read(corpus); - if (!tokenType.HasValue || (tokenType.Value != BackendMetricsTokenizer.TokenType.EqualsDelimiter)) + (ServerSideMetricsTokenizer.TokenType? tokenType, ReadOnlyMemory buffer) = ServerSideMetricsTokenizer.Read(corpus); + if (!tokenType.HasValue || (tokenType.Value != ServerSideMetricsTokenizer.TokenType.EqualsDelimiter)) { value = default; bytesConsumed = default; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsTokenizer.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsTokenizer.cs similarity index 99% rename from Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsTokenizer.cs rename to Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsTokenizer.cs index ef0b2fd3ec..bba72e211d 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/BackendMetricsTokenizer.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsTokenizer.cs @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics #else internal #endif - static class BackendMetricsTokenizer + static class ServerSideMetricsTokenizer { public enum TokenType { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs new file mode 100644 index 0000000000..8342c24f33 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs @@ -0,0 +1,13 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + internal static class ServerSideMetricsUtils + { + public static string FormatTrace(this ServerSideMetrics serverSideMetrics) + { + return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; + } + } +} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index 862d25e30c..23cac83f93 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -83,12 +83,12 @@ private async Task ValidateMetrics(int throughput) Assert.AreEqual(find.id, response.id); } - ServerSideMetrics backendMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); - bool tryParseResult = ServerSideMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out ServerSideMetrics backendMetricsFromHeaders); + ServerSideMetrics serverSideMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); + bool tryParseResult = ServerSideMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out ServerSideMetrics serverSideMetricsFromHeaders); Assert.IsTrue(tryParseResult); - headerMetricsAccumulator.Accumulate(backendMetricsFromHeaders); - Assert.IsTrue(headerMetricsAccumulator.GetBackendMetrics().FormatTrace() == backendMetricsFromDiagnostics.FormatTrace()); + headerMetricsAccumulator.Accumulate(serverSideMetricsFromHeaders); + Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == serverSideMetricsFromDiagnostics.FormatTrace()); } Assert.IsTrue(found); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/QueryStatisticsDatumVisitor.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/QueryStatisticsDatumVisitor.cs index 200150875b..c100146bdb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/QueryStatisticsDatumVisitor.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/QueryStatisticsDatumVisitor.cs @@ -41,13 +41,13 @@ public void AddGetCosmosElementResponseTime(double time) public void Visit(QueryMetricsTraceDatum queryMetricsTraceDatum) { - this.queryMetrics.RetrievedDocumentCount = queryMetricsTraceDatum.QueryMetrics.BackendMetrics.RetrievedDocumentCount; - this.queryMetrics.RetrievedDocumentSize = queryMetricsTraceDatum.QueryMetrics.BackendMetrics.RetrievedDocumentSize; - this.queryMetrics.OutputDocumentCount = queryMetricsTraceDatum.QueryMetrics.BackendMetrics.OutputDocumentCount; - this.queryMetrics.OutputDocumentSize = queryMetricsTraceDatum.QueryMetrics.BackendMetrics.OutputDocumentSize; - this.queryMetrics.TotalQueryExecutionTime = queryMetricsTraceDatum.QueryMetrics.BackendMetrics.TotalTime.TotalMilliseconds; - this.queryMetrics.DocumentLoadTime = queryMetricsTraceDatum.QueryMetrics.BackendMetrics.DocumentLoadTime.TotalMilliseconds; - this.queryMetrics.DocumentWriteTime = queryMetricsTraceDatum.QueryMetrics.BackendMetrics.DocumentWriteTime.TotalMilliseconds; + this.queryMetrics.RetrievedDocumentCount = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.RetrievedDocumentCount; + this.queryMetrics.RetrievedDocumentSize = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.RetrievedDocumentSize; + this.queryMetrics.OutputDocumentCount = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.OutputDocumentCount; + this.queryMetrics.OutputDocumentSize = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.OutputDocumentSize; + this.queryMetrics.TotalQueryExecutionTime = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.TotalTime.TotalMilliseconds; + this.queryMetrics.DocumentLoadTime = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.DocumentLoadTime.TotalMilliseconds; + this.queryMetrics.DocumentWriteTime = queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.DocumentWriteTime.TotalMilliseconds; } public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs index afc25ec771..d971223f09 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs @@ -1870,11 +1870,11 @@ public async Task TestQueryMetricsNonZero() QueryMetrics queryMetrics = QueryMetrics.CreateFromIEnumerable(feedResonse.QueryMetrics.Values); - Assert.IsTrue(queryMetrics.BackendMetrics.RetrievedDocumentCount > 0); - Assert.IsTrue(queryMetrics.BackendMetrics.RetrievedDocumentSize > 0); - Assert.IsTrue(queryMetrics.BackendMetrics.OutputDocumentCount > 0); - Assert.IsTrue(queryMetrics.BackendMetrics.OutputDocumentSize > 0); - Assert.IsTrue(queryMetrics.BackendMetrics.IndexHitRatio > 0); + Assert.IsTrue(queryMetrics.ServerSideMetrics.RetrievedDocumentCount > 0); + Assert.IsTrue(queryMetrics.ServerSideMetrics.RetrievedDocumentSize > 0); + Assert.IsTrue(queryMetrics.ServerSideMetrics.OutputDocumentCount > 0); + Assert.IsTrue(queryMetrics.ServerSideMetrics.OutputDocumentSize > 0); + Assert.IsTrue(queryMetrics.ServerSideMetrics.IndexHitRatio > 0); await client.DeleteDatabaseAsync(database); } @@ -1960,7 +1960,7 @@ private void TestForceQueryScanHeaders(Database database, bool partitionedCollec query, feedOptions).AsDocumentQuery().ExecuteNextAsync().Result; queryMetrics = result.QueryMetrics.Values.Aggregate((curr, acc) => curr + acc); - Assert.AreEqual(TimeSpan.Zero, queryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreEqual(TimeSpan.Zero, queryMetrics.ServerSideMetrics.IndexLookupTime); // Without ForceQueryScan feedOptions = new FeedOptions() @@ -1976,7 +1976,7 @@ private void TestForceQueryScanHeaders(Database database, bool partitionedCollec query, feedOptions).AsDocumentQuery().ExecuteNextAsync().Result; queryMetrics = result.QueryMetrics.Values.Aggregate((curr, acc) => curr + acc); - Assert.AreNotEqual(TimeSpan.Zero, queryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreNotEqual(TimeSpan.Zero, queryMetrics.ServerSideMetrics.IndexLookupTime); } private void TestFeedOptionInput( @@ -2315,19 +2315,19 @@ private void ValidateQueryMetrics(QueryMetrics metrics) Assert.AreEqual(0, metrics.ClientSideMetrics.Retries); //We are not checking VMExecutionTime, since that is not a public property //Assert.IsTrue(metrics.QueryEngineTimes.VMExecutionTime.TotalMilliseconds > 0, "Expected VMExecutionTimeInMs to be > 0, metrics = {0}", metrics); - Assert.IsTrue(metrics.BackendMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds > 0, "Expected CompileTimeInMs to be > 0, metrics = {0}", metrics); + Assert.IsTrue(metrics.ServerSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds > 0, "Expected CompileTimeInMs to be > 0, metrics = {0}", metrics); //We are not checking DocumentLoadTime and RetrievedDocumentCount, since some queries don't return any documents (especially in the last continuation). //Assert.IsTrue(metrics.QueryEngineTimes.DocumentLoadTime.TotalMilliseconds > 0, "Expected DocumentLoadTimeInMs to be > 0, metrics = {0}", metrics); //Assert.IsTrue(metrics.RetrievedDocumentCount > 0, "Expected RetrievedDocumentCount to be > 0, metrics = {0}", metrics); - Assert.IsTrue(metrics.BackendMetrics.TotalTime.TotalMilliseconds > 0, "Expected TotalExecutionTimeInMs to be > 0, metrics = {0}", metrics); + Assert.IsTrue(metrics.ServerSideMetrics.TotalTime.TotalMilliseconds > 0, "Expected TotalExecutionTimeInMs to be > 0, metrics = {0}", metrics); //Assert.IsTrue(metrics.QueryEngineTimes.WriteOutputTime.TotalMilliseconds > 0, "Expected WriteOutputTimeInMs to be > 0, metrics = {0}", metrics); //Assert.IsTrue(metrics.RetrievedDocumentSize > 0, "Expected RetrievedDocumentSize to be > 0, metrics = {0}", metrics); - Assert.IsTrue(metrics.BackendMetrics.IndexLookupTime.TotalMilliseconds > 0, "Expected IndexLookupTimeInMs to be > 0, metrics = {0}", metrics); - Assert.IsTrue(metrics.BackendMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds > 0, "Expected LogicalPlanBuildTimeInMs to be > 0, metrics = {0}", metrics); + Assert.IsTrue(metrics.ServerSideMetrics.IndexLookupTime.TotalMilliseconds > 0, "Expected IndexLookupTimeInMs to be > 0, metrics = {0}", metrics); + Assert.IsTrue(metrics.ServerSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds > 0, "Expected LogicalPlanBuildTimeInMs to be > 0, metrics = {0}", metrics); //Assert.AreEqual(metrics.QueryEngineTimes.VMExecutionTime - metrics.QueryEngineTimes.IndexLookupTime - metrics.QueryEngineTimes.DocumentLoadTime - metrics.QueryEngineTimes.WriteOutputTime, // metrics.QueryEngineTimes.RuntimeExecutionTimes.TotalTime); - Assert.IsTrue(metrics.BackendMetrics.RuntimeExecutionTimes.QueryEngineExecutionTime >= metrics.BackendMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime + metrics.BackendMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, - "Expected Query VM Execution Time to be > {0}, metrics = {1}", metrics.BackendMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime + metrics.BackendMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, metrics); + Assert.IsTrue(metrics.ServerSideMetrics.RuntimeExecutionTimes.QueryEngineExecutionTime >= metrics.ServerSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime + metrics.ServerSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, + "Expected Query VM Execution Time to be > {0}, metrics = {1}", metrics.ServerSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime + metrics.ServerSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime, metrics); //Assert.IsTrue(metrics.QueryEngineTimes.VMExecutionTime >= metrics.QueryEngineTimes.RuntimeExecutionTimes.TotalTime, // "Expected Query VM Execution Time to be > {0}, metrics = {1}", metrics.QueryEngineTimes.RuntimeExecutionTimes.TotalTime, metrics); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs index 3c26fb5fdf..e37077976e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs @@ -37,7 +37,7 @@ public void TestParse() ValueStopwatch stopwatch = ValueStopwatch.StartNew(); for (int i = 0; i < 100000; i++) { - BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics backendMetrics); + ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics serverSideMetrics); } stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml index d1dee72a0f..887902db79 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml @@ -120,13 +120,14 @@ Query Metrics - + (() => new QueryMetrics( - BackendMetricsTests.MockBackendMetrics, + ServerSideMetricsTests.MockServerSideMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics))); rootTrace.AddDatum("Query Metrics", datum); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs index 23ba77b8d3..17f73616c2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/QueryMetricsTests.cs @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos.Tests.Query.Metrics public class QueryMetricsTests { private static readonly QueryMetrics MockQueryMetrics = new QueryMetrics( - ServerSideMetricsTests.MockBackendMetrics, + ServerSideMetricsTests.ServerSideMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics); @@ -26,7 +26,7 @@ public void TestAccumulator() QueryMetrics doubleQueryMetrics = accumulator.GetQueryMetrics(); // Spot check - Assert.AreEqual(2 * ServerSideMetricsTests.MockBackendMetrics.IndexLookupTime, doubleQueryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreEqual(2 * ServerSideMetricsTests.ServerSideMetrics.IndexLookupTime, doubleQueryMetrics.ServerSideMetrics.IndexLookupTime); Assert.AreEqual(2 * IndexUtilizationInfoTests.MockIndexUtilizationInfo.PotentialSingleIndexes.Count, doubleQueryMetrics.IndexUtilizationInfo.PotentialSingleIndexes.Count); Assert.AreEqual(2 * ClientSideMetricsTests.MockClientSideMetrics.RequestCharge, doubleQueryMetrics.ClientSideMetrics.RequestCharge); } @@ -37,7 +37,7 @@ public void TestAddition() QueryMetrics doubleQueryMetrics = MockQueryMetrics + MockQueryMetrics; // Spot check - Assert.AreEqual(2 * ServerSideMetricsTests.MockBackendMetrics.IndexLookupTime, doubleQueryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreEqual(2 * ServerSideMetricsTests.ServerSideMetrics.IndexLookupTime, doubleQueryMetrics.ServerSideMetrics.IndexLookupTime); Assert.AreEqual(2 * IndexUtilizationInfoTests.MockIndexUtilizationInfo.PotentialSingleIndexes.Count, doubleQueryMetrics.IndexUtilizationInfo.PotentialSingleIndexes.Count); Assert.AreEqual(2 * ClientSideMetricsTests.MockClientSideMetrics.RequestCharge, doubleQueryMetrics.ClientSideMetrics.RequestCharge); } @@ -48,7 +48,7 @@ public void TestCreateFromEnumerable() QueryMetrics tripleQueryMetrics = QueryMetrics.CreateFromIEnumerable(new List() { MockQueryMetrics, MockQueryMetrics, MockQueryMetrics }); // Spot check - Assert.AreEqual(3 * ServerSideMetricsTests.MockBackendMetrics.IndexLookupTime, tripleQueryMetrics.BackendMetrics.IndexLookupTime); + Assert.AreEqual(3 * ServerSideMetricsTests.ServerSideMetrics.IndexLookupTime, tripleQueryMetrics.ServerSideMetrics.IndexLookupTime); Assert.AreEqual(3 * IndexUtilizationInfoTests.MockIndexUtilizationInfo.PotentialSingleIndexes.Count, tripleQueryMetrics.IndexUtilizationInfo.PotentialSingleIndexes.Count); Assert.AreEqual(3 * ClientSideMetricsTests.MockClientSideMetrics.RequestCharge, tripleQueryMetrics.ClientSideMetrics.RequestCharge); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs index d6f05562ef..79e3b18c94 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs @@ -30,7 +30,7 @@ public class ServerSideMetricsTests private static readonly string delimitedString = $"totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds};queryCompileTimeInMs={queryCompileTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={logicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={physicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={queryOptimizationTime.TotalMilliseconds};VMExecutionTimeInMs={vmExecutionTime.TotalMilliseconds};indexLookupTimeInMs={indexLookupTime.TotalMilliseconds};documentLoadTimeInMs={documentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={systemFunctionExecuteTime.TotalMilliseconds};userFunctionExecuteTimeInMs={userFunctionExecuteTime.TotalMilliseconds};retrievedDocumentCount={retrievedDocumentCount};retrievedDocumentSize={retrievedDocumentSize};outputDocumentCount={outputDocumentCount};outputDocumentSize={outputDocumentSize};writeOutputTimeInMs={documentWriteTime.TotalMilliseconds};indexUtilizationRatio={indexHitRatio}"; - internal static readonly ServerSideMetrics MockBackendMetrics = new ServerSideMetrics( + internal static readonly ServerSideMetrics ServerSideMetrics = new ServerSideMetrics( retrievedDocumentCount, retrievedDocumentSize, outputDocumentCount, @@ -55,7 +55,7 @@ public class ServerSideMetricsTests [TestMethod] public void TestParse() { - ServerSideMetricsTests.ValidateParse(delimitedString, MockBackendMetrics); + ServerSideMetricsTests.ValidateParse(delimitedString, ServerSideMetrics); } [TestMethod] @@ -127,7 +127,7 @@ public void TestParseStringWithTrailingUnknownField() [DataRow("totalExecutionTimeInMs=33.6+totalExecutionTimeInMs=33.6", DisplayName = "Wrong Delimiter")] public void TestNegativeCases(string delimitedString) { - Assert.IsFalse(BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics backendMetrics)); + Assert.IsFalse(ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics serverSideMetrics)); } [TestMethod] @@ -163,10 +163,10 @@ public void TestParseStringWithUnknownField() public void TestAccumulator() { ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); - accumulator.Accumulate(MockBackendMetrics); - accumulator.Accumulate(MockBackendMetrics); + accumulator.Accumulate(ServerSideMetrics); + accumulator.Accumulate(ServerSideMetrics); - ServerSideMetrics backendMetricsFromAddition = accumulator.GetBackendMetrics(); + ServerSideMetrics serverSideMetricsFromAddition = accumulator.GetServerSideMetrics(); ServerSideMetrics expected = new ServerSideMetrics( retrievedDocumentCount * 2, retrievedDocumentSize * 2, @@ -188,16 +188,16 @@ public void TestAccumulator() userFunctionExecuteTime * 2), documentWriteTime * 2); - ServerSideMetricsTests.ValidateBackendMetricsEquals(expected, backendMetricsFromAddition); + ServerSideMetricsTests.ValidateServerSideMetricsEquals(expected, serverSideMetricsFromAddition); } private static void ValidateParse(string delimitedString, ServerSideMetrics expected) { - Assert.IsTrue(BackendMetricsParser.TryParse(delimitedString, out ServerSideMetrics actual)); - ServerSideMetricsTests.ValidateBackendMetricsEquals(expected, actual); + Assert.IsTrue(ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics actual)); + ServerSideMetricsTests.ValidateServerSideMetricsEquals(expected, actual); } - private static void ValidateBackendMetricsEquals(ServerSideMetrics expected, ServerSideMetrics actual) + private static void ValidateServerSideMetricsEquals(ServerSideMetrics expected, ServerSideMetrics actual) { Assert.AreEqual(expected.DocumentLoadTime, actual.DocumentLoadTime); Assert.AreEqual(expected.DocumentWriteTime, actual.DocumentWriteTime); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs index 7bb961eb25..2d69341182 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs @@ -41,7 +41,7 @@ namespace Microsoft.Azure.Cosmos.Tests.Tracing public sealed class TraceWriterBaselineTests : BaselineTests { private static readonly Lazy MockQueryMetrics = new Lazy(() => new QueryMetrics( - ServerSideMetricsTests.MockBackendMetrics, + ServerSideMetricsTests.ServerSideMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics)); @@ -316,7 +316,7 @@ public void TraceData() { QueryMetricsTraceDatum datum = new QueryMetricsTraceDatum( new Lazy(() => new QueryMetrics( - ServerSideMetricsTests.MockBackendMetrics, + ServerSideMetricsTests.ServerSideMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics))); rootTrace.AddDatum("Query Metrics", datum); From 8d71294aaf46de17ed12ea203efde2762662d7f7 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 2 Aug 2023 11:29:18 -0700 Subject: [PATCH 21/43] Update API and tests --- .../TraceWriterBaselineTests.TraceData.xml | 5 +- .../Contracts/ContractTests.cs | 2 +- .../Contracts/DotNetSDKAPI.json | 218 +++++++++--------- 3 files changed, 112 insertions(+), 113 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml index 887902db79..75cd9894de 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.TraceData.xml @@ -120,14 +120,13 @@ Query Metrics - - (() => new QueryMetrics( - ServerSideMetricsTests.MockServerSideMetrics, + ServerSideMetricsTests.ServerSideMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics))); rootTrace.AddDatum("Query Metrics", datum); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs index a4d295a634..48c3e5accc 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs @@ -38,7 +38,7 @@ public void ClientDllNamespaceTest() #if INTERNAL int expected = 7; #else - int expected = 5; + int expected = 6; #endif ContractTests.NamespaceCountTest(typeof(CosmosClient), expected); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 047a16c66d..19c6af457e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -3124,10 +3124,10 @@ "Attributes": [], "MethodInfo": "Int32 GetFailedRequestCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.BackendMetrics GetQueryMetrics()": { + "Microsoft.Azure.Cosmos.Query.Core.Metrics.ServerSideMetrics GetQueryMetrics()": { "Type": "Method", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.BackendMetrics GetQueryMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.ServerSideMetrics GetQueryMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Uri]] GetContactedRegions()": { "Type": "Method", @@ -6241,7 +6241,113 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.BackendMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.TimeSpan get_LogicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_PhysicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_QueryCompilationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_QueryOptimizationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan LogicalPlanBuildTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan LogicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan PhysicalPlanBuildTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan PhysicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan QueryCompilationTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryCompilationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan QueryOptimizationTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryOptimizationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)]" + } + }, + "NestedTypes": {} + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.TimeSpan get_QueryEngineExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_SystemFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_UserDefinedFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan QueryEngineExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryEngineExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan SystemFunctionExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan SystemFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan UserDefinedFunctionExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan UserDefinedFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)]" + } + }, + "NestedTypes": {} + }, + "Microsoft.Azure.Cosmos.Query.Core.Metrics.ServerSideMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { "Double get_IndexHitRatio()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { @@ -6396,112 +6502,6 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.TimeSpan get_LogicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_PhysicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_QueryCompilationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_QueryOptimizationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan LogicalPlanBuildTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan LogicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan PhysicalPlanBuildTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan PhysicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan QueryCompilationTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryCompilationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan QueryOptimizationTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryOptimizationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)]" - } - }, - "NestedTypes": {} - }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.TimeSpan get_QueryEngineExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_SystemFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_UserDefinedFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan QueryEngineExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryEngineExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan SystemFunctionExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan SystemFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan UserDefinedFunctionExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan UserDefinedFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)]" - } - }, - "NestedTypes": {} - }, "Microsoft.Azure.Cosmos.QueryDefinition;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { From 95f8efb2d317d506891d62110781a2296e489286 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 3 Aug 2023 12:10:58 -0700 Subject: [PATCH 22/43] separate public and internal classes --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 2 +- .../src/Query/Core/Metrics/QueryMetrics.cs | 8 +- .../Core/Metrics/QueryMetricsTextWriter.cs | 4 +- .../Query/Core/Metrics/QueryMetricsWriter.cs | 4 +- .../Core/Metrics/QueryPreparationTimes.cs | 25 +-- .../QueryPreparationTimesAccumulator.cs | 12 +- .../Metrics/QueryPreparationTimesInternal.cs | 58 +++++++ .../Core/Metrics/RuntimeExecutionTimes.cs | 20 +-- .../RuntimeExecutionTimesAccumulator.cs | 12 +- .../Metrics/RuntimeExecutionTimesInternal.cs | 49 ++++++ .../Query/Core/Metrics/ServerSideMetrics.cs | 99 ++--------- .../Metrics/ServerSideMetricsAccumulator.cs | 12 +- .../Core/Metrics/ServerSideMetricsInternal.cs | 161 ++++++++++++++++++ .../Core/Metrics/ServerSideMetricsParser.cs | 12 +- .../Metrics/ServerSideMetricsTokenizer.cs | 2 +- .../Core/Metrics/ServerSideMetricsUtils.cs | 5 + .../CosmosTraceDiagnosticsTests.cs | 2 +- .../Query/Metrics/Performance.cs | 2 +- .../Query/Metrics/ServerSideMetricsTests.cs | 42 ++--- 19 files changed, 357 insertions(+), 174 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 80cdc0c823..07b402b1e1 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -53,7 +53,7 @@ public override ServerSideMetrics GetQueryMetrics() { ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - return accumulator.GetServerSideMetrics(); + return new ServerSideMetrics(accumulator.GetServerSideMetrics()); } internal bool IsGoneExceptionHit() diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs index 454df8d0e8..e35a0263fb 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs @@ -29,7 +29,7 @@ sealed class QueryMetrics clientSideMetrics: ClientSideMetrics.Empty); public QueryMetrics( - ServerSideMetrics serverSideMetrics, + ServerSideMetricsInternal serverSideMetrics, IndexUtilizationInfo indexUtilizationInfo, ClientSideMetrics clientSideMetrics) { @@ -43,13 +43,13 @@ public QueryMetrics( IndexUtilizationInfo indexUtilizationInfo, ClientSideMetrics clientSideMetrics) : this(!String.IsNullOrWhiteSpace(deliminatedString) && - ServerSideMetricsParser.TryParse(deliminatedString, out ServerSideMetrics serverSideMetrics) + ServerSideMetricsParser.TryParse(deliminatedString, out ServerSideMetricsInternal serverSideMetrics) ? serverSideMetrics - : ServerSideMetrics.Empty, indexUtilizationInfo, clientSideMetrics) + : ServerSideMetricsInternal.Empty, indexUtilizationInfo, clientSideMetrics) { } - public ServerSideMetrics ServerSideMetrics { get; } + public ServerSideMetricsInternal ServerSideMetrics { get; } public IndexUtilizationInfo IndexUtilizationInfo { get; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsTextWriter.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsTextWriter.cs index bd634815e9..1802e60e28 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsTextWriter.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsTextWriter.cs @@ -215,7 +215,7 @@ protected override void WriteTotalQueryExecutionTime(TimeSpan totalQueryExecutio indentLevel: 0); } - protected override void WriteQueryPreparationTime(QueryPreparationTimes queryPreparationTimes) + protected override void WriteQueryPreparationTime(QueryPreparationTimesInternal queryPreparationTimes) { QueryMetricsTextWriter.AppendTimeSpanToStringBuilder( this.stringBuilder, @@ -250,7 +250,7 @@ protected override void WriteVMExecutionTime(TimeSpan vmExecutionTime) // Do Nothing } - protected override void WriteRuntimeExecutionTime(RuntimeExecutionTimes runtimeExecutionTimes) + protected override void WriteRuntimeExecutionTime(RuntimeExecutionTimesInternal runtimeExecutionTimes) { QueryMetricsTextWriter.AppendTimeSpanToStringBuilder( this.stringBuilder, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs index 744f466e23..f0d6f7b0fa 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsWriter.cs @@ -70,7 +70,7 @@ public void WriteQueryMetrics(QueryMetrics queryMetrics) protected abstract void WriteTotalQueryExecutionTime(TimeSpan totalQueryExecutionTime); - protected abstract void WriteQueryPreparationTime(QueryPreparationTimes queryPreparationTimes); + protected abstract void WriteQueryPreparationTime(QueryPreparationTimesInternal queryPreparationTimes); protected abstract void WriteIndexLookupTime(TimeSpan indexLookupTime); @@ -78,7 +78,7 @@ public void WriteQueryMetrics(QueryMetrics queryMetrics) protected abstract void WriteVMExecutionTime(TimeSpan vMExecutionTime); - protected abstract void WriteRuntimeExecutionTime(RuntimeExecutionTimes runtimeExecutionTimes); + protected abstract void WriteRuntimeExecutionTime(RuntimeExecutionTimesInternal runtimeExecutionTimes); protected abstract void WriteDocumentWriteTime(TimeSpan documentWriteTime); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs index 0521665b74..b6d21c2caa 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs @@ -10,29 +10,16 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// public sealed class QueryPreparationTimes { - internal static readonly QueryPreparationTimes Zero = new QueryPreparationTimes( - queryCompilationTime: default, - logicalPlanBuildTime: default, - physicalPlanBuildTime: default, - queryOptimizationTime: default); - /// /// Initializes a new instance of the QueryPreparationTimes class. /// - /// Query compile and optimization time - /// Query logical plan build time - /// Query physical plan build time - /// Query optimization time - public QueryPreparationTimes( - TimeSpan queryCompilationTime, - TimeSpan logicalPlanBuildTime, - TimeSpan physicalPlanBuildTime, - TimeSpan queryOptimizationTime) + /// + internal QueryPreparationTimes(QueryPreparationTimesInternal queryPreparationTimesInternal) { - this.QueryCompilationTime = queryCompilationTime; - this.LogicalPlanBuildTime = logicalPlanBuildTime; - this.PhysicalPlanBuildTime = physicalPlanBuildTime; - this.QueryOptimizationTime = queryOptimizationTime; + this.QueryCompilationTime = queryPreparationTimesInternal.QueryCompilationTime; + this.LogicalPlanBuildTime = queryPreparationTimesInternal.LogicalPlanBuildTime; + this.PhysicalPlanBuildTime = queryPreparationTimesInternal.PhysicalPlanBuildTime; + this.QueryOptimizationTime = queryPreparationTimesInternal.QueryOptimizationTime; } /// diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs index 555ad1cc2b..13c2827cc0 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs @@ -9,14 +9,14 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class QueryPreparationTimesAccumulator { - private readonly List queryPreparationTimesList; + private readonly List queryPreparationTimesList; public QueryPreparationTimesAccumulator() { - this.queryPreparationTimesList = new List(); + this.queryPreparationTimesList = new List(); } - public void Accumulate(QueryPreparationTimes queryPreparationTimes) + public void Accumulate(QueryPreparationTimesInternal queryPreparationTimes) { if (queryPreparationTimes == null) { @@ -26,14 +26,14 @@ public void Accumulate(QueryPreparationTimes queryPreparationTimes) this.queryPreparationTimesList.Add(queryPreparationTimes); } - public QueryPreparationTimes GetQueryPreparationTimes() + public QueryPreparationTimesInternal GetQueryPreparationTimes() { TimeSpan queryCompilationTime = TimeSpan.Zero; TimeSpan logicalPlanBuildTime = TimeSpan.Zero; TimeSpan physicalPlanBuildTime = TimeSpan.Zero; TimeSpan queryOptimizationTime = TimeSpan.Zero; - foreach (QueryPreparationTimes queryPreparationTimes in this.queryPreparationTimesList) + foreach (QueryPreparationTimesInternal queryPreparationTimes in this.queryPreparationTimesList) { queryCompilationTime += queryPreparationTimes.QueryCompilationTime; logicalPlanBuildTime += queryPreparationTimes.LogicalPlanBuildTime; @@ -41,7 +41,7 @@ public QueryPreparationTimes GetQueryPreparationTimes() queryOptimizationTime += queryPreparationTimes.QueryOptimizationTime; } - return new QueryPreparationTimes( + return new QueryPreparationTimesInternal( queryCompilationTime: queryCompilationTime, logicalPlanBuildTime: logicalPlanBuildTime, physicalPlanBuildTime: physicalPlanBuildTime, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs new file mode 100644 index 0000000000..04244521e9 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs @@ -0,0 +1,58 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + + /// + /// Query preparation metrics in the Azure DocumentDB database service. + /// + internal sealed class QueryPreparationTimesInternal + { + public static readonly QueryPreparationTimesInternal Zero = new QueryPreparationTimesInternal( + queryCompilationTime: default, + logicalPlanBuildTime: default, + physicalPlanBuildTime: default, + queryOptimizationTime: default); + + /// + /// Initializes a new instance of the QueryPreparationTimes class. + /// + /// Query compile and optimization time + /// Query logical plan build time + /// Query physical plan build time + /// Query optimization time + public QueryPreparationTimesInternal( + TimeSpan queryCompilationTime, + TimeSpan logicalPlanBuildTime, + TimeSpan physicalPlanBuildTime, + TimeSpan queryOptimizationTime) + { + this.QueryCompilationTime = queryCompilationTime; + this.LogicalPlanBuildTime = logicalPlanBuildTime; + this.PhysicalPlanBuildTime = physicalPlanBuildTime; + this.QueryOptimizationTime = queryOptimizationTime; + } + + /// + /// Gets the query compile time in the Azure DocumentDB database service. + /// + public TimeSpan QueryCompilationTime { get; } + + /// + /// Gets the query logical plan build time in the Azure DocumentDB database service. + /// + public TimeSpan LogicalPlanBuildTime { get; } + + /// + /// Gets the query physical plan build time in the Azure DocumentDB database service. + /// + public TimeSpan PhysicalPlanBuildTime { get; } + + /// + /// Gets the query optimization time in the Azure DocumentDB database service. + /// + public TimeSpan QueryOptimizationTime { get; } + } +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs index f8ca879b63..9743d38a88 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs @@ -10,25 +10,15 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// public sealed class RuntimeExecutionTimes { - internal static readonly RuntimeExecutionTimes Empty = new RuntimeExecutionTimes( - queryEngineExecutionTime: default, - systemFunctionExecutionTime: default, - userDefinedFunctionExecutionTime: default); - /// /// Initializes a new instance of the RuntimeExecutionTimes class. /// - /// Query end - to - end execution time - /// Total time spent executing system functions - /// Total time spent executing user - defined functions - public RuntimeExecutionTimes( - TimeSpan queryEngineExecutionTime, - TimeSpan systemFunctionExecutionTime, - TimeSpan userDefinedFunctionExecutionTime) + /// + internal RuntimeExecutionTimes(RuntimeExecutionTimesInternal runtimeExecutionTimesInternal) { - this.QueryEngineExecutionTime = queryEngineExecutionTime; - this.SystemFunctionExecutionTime = systemFunctionExecutionTime; - this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTime; + this.QueryEngineExecutionTime = runtimeExecutionTimesInternal.QueryEngineExecutionTime; + this.SystemFunctionExecutionTime = runtimeExecutionTimesInternal.SystemFunctionExecutionTime; + this.UserDefinedFunctionExecutionTime = runtimeExecutionTimesInternal.UserDefinedFunctionExecutionTime; } /// diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs index c8784a9798..7bdedc7af8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs @@ -9,14 +9,14 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class RuntimeExecutionTimesAccumulator { - private readonly List runtimeExecutionTimesList; + private readonly List runtimeExecutionTimesList; public RuntimeExecutionTimesAccumulator() { - this.runtimeExecutionTimesList = new List(); + this.runtimeExecutionTimesList = new List(); } - public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) + public void Accumulate(RuntimeExecutionTimesInternal runtimeExecutionTimes) { if (runtimeExecutionTimes == null) { @@ -26,20 +26,20 @@ public void Accumulate(RuntimeExecutionTimes runtimeExecutionTimes) this.runtimeExecutionTimesList.Add(runtimeExecutionTimes); } - public RuntimeExecutionTimes GetRuntimeExecutionTimes() + public RuntimeExecutionTimesInternal GetRuntimeExecutionTimes() { TimeSpan queryEngineExecutionTime = TimeSpan.Zero; TimeSpan systemFunctionExecutionTime = TimeSpan.Zero; TimeSpan userDefinedFunctionExecutionTime = TimeSpan.Zero; - foreach (RuntimeExecutionTimes runtimeExecutionTimes in this.runtimeExecutionTimesList) + foreach (RuntimeExecutionTimesInternal runtimeExecutionTimes in this.runtimeExecutionTimesList) { queryEngineExecutionTime += runtimeExecutionTimes.QueryEngineExecutionTime; systemFunctionExecutionTime += runtimeExecutionTimes.SystemFunctionExecutionTime; userDefinedFunctionExecutionTime += runtimeExecutionTimes.UserDefinedFunctionExecutionTime; } - return new RuntimeExecutionTimes( + return new RuntimeExecutionTimesInternal( queryEngineExecutionTime: queryEngineExecutionTime, systemFunctionExecutionTime: systemFunctionExecutionTime, userDefinedFunctionExecutionTime: userDefinedFunctionExecutionTime); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs new file mode 100644 index 0000000000..0b79b6b1e6 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs @@ -0,0 +1,49 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + + /// + /// Query runtime execution times in the Azure Cosmos DB service. + /// + internal sealed class RuntimeExecutionTimesInternal + { + public static readonly RuntimeExecutionTimesInternal Empty = new RuntimeExecutionTimesInternal( + queryEngineExecutionTime: default, + systemFunctionExecutionTime: default, + userDefinedFunctionExecutionTime: default); + + /// + /// Initializes a new instance of the RuntimeExecutionTimes class. + /// + /// Query end - to - end execution time + /// Total time spent executing system functions + /// Total time spent executing user - defined functions + public RuntimeExecutionTimesInternal( + TimeSpan queryEngineExecutionTime, + TimeSpan systemFunctionExecutionTime, + TimeSpan userDefinedFunctionExecutionTime) + { + this.QueryEngineExecutionTime = queryEngineExecutionTime; + this.SystemFunctionExecutionTime = systemFunctionExecutionTime; + this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTime; + } + + /// + /// Gets the total query runtime execution time in the Azure Cosmos DB service. + /// + public TimeSpan QueryEngineExecutionTime { get; } + + /// + /// Gets the query system function execution time in the Azure Cosmos DB service. + /// + public TimeSpan SystemFunctionExecutionTime { get; } + + /// + /// Gets the query user defined function execution time in the Azure Cosmos DB service. + /// + public TimeSpan UserDefinedFunctionExecutionTime { get; } + } +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index d68125401b..aee6b7fee8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -5,71 +5,30 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; - using System.Collections.Generic; /// - /// Metrics received for queries from the backend. + /// internal implementation of metrics received for queries from the backend. /// public sealed class ServerSideMetrics { /// - /// QueryMetrics that with all members having default (but not null) members. + /// Initializes a new instance of the class. /// - internal static readonly ServerSideMetrics Empty = new ServerSideMetrics( - retrievedDocumentCount: default, - retrievedDocumentSize: default, - outputDocumentCount: default, - outputDocumentSize: default, - indexHitRatio: default, - totalQueryExecutionTime: default, - queryPreparationTimes: QueryPreparationTimes.Zero, - indexLookupTime: default, - documentLoadTime: default, - vmExecutionTime: default, - runtimeExecutionTimes: RuntimeExecutionTimes.Empty, - documentWriteTime: default); - - /// - /// Initializes a new instance of the class. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public ServerSideMetrics( - long retrievedDocumentCount, - long retrievedDocumentSize, - long outputDocumentCount, - long outputDocumentSize, - double indexHitRatio, - TimeSpan totalQueryExecutionTime, - QueryPreparationTimes queryPreparationTimes, - TimeSpan indexLookupTime, - TimeSpan documentLoadTime, - TimeSpan vmExecutionTime, - RuntimeExecutionTimes runtimeExecutionTimes, - TimeSpan documentWriteTime) + /// + internal ServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) { - this.RetrievedDocumentCount = retrievedDocumentCount; - this.RetrievedDocumentSize = retrievedDocumentSize; - this.OutputDocumentCount = outputDocumentCount; - this.OutputDocumentSize = outputDocumentSize; - this.IndexHitRatio = indexHitRatio; - this.TotalTime = totalQueryExecutionTime; - this.QueryPreparationTimes = queryPreparationTimes ?? throw new ArgumentNullException($"{nameof(queryPreparationTimes)} can not be null."); - this.IndexLookupTime = indexLookupTime; - this.DocumentLoadTime = documentLoadTime; - this.VMExecutionTime = vmExecutionTime; - this.RuntimeExecutionTimes = runtimeExecutionTimes ?? throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null."); - this.DocumentWriteTime = documentWriteTime; + this.RetrievedDocumentCount = serverSideMetricsInternal.RetrievedDocumentCount; + this.RetrievedDocumentSize = serverSideMetricsInternal.RetrievedDocumentSize; + this.OutputDocumentCount = serverSideMetricsInternal.OutputDocumentCount; + this.OutputDocumentSize = serverSideMetricsInternal.OutputDocumentSize; + this.IndexHitRatio = serverSideMetricsInternal.IndexHitRatio; + this.TotalTime = serverSideMetricsInternal.TotalTime; + this.QueryPreparationTimes = new QueryPreparationTimes(serverSideMetricsInternal.QueryPreparationTimes); + this.IndexLookupTime = serverSideMetricsInternal.IndexLookupTime; + this.DocumentLoadTime = serverSideMetricsInternal.DocumentLoadTime; + this.VMExecutionTime = serverSideMetricsInternal.VMExecutionTime; + this.RuntimeExecutionTimes = new RuntimeExecutionTimes(serverSideMetricsInternal.RuntimeExecutionTimes); + this.DocumentWriteTime = serverSideMetricsInternal.DocumentWriteTime; } /// @@ -131,31 +90,5 @@ public ServerSideMetrics( /// Gets the VMExecution Time. /// public TimeSpan VMExecutionTime { get; } - - internal static ServerSideMetrics Create(IEnumerable serverSideMetricsEnumerable) - { - ServerSideMetricsAccumulator accumulator = default; - foreach (ServerSideMetrics serverSideMetrics in serverSideMetricsEnumerable) - { - accumulator.Accumulate(serverSideMetrics); - } - - return accumulator.GetServerSideMetrics(); - } - - internal static bool TryParseFromDelimitedString(string delimitedString, out ServerSideMetrics serverSideMetrics) - { - return ServerSideMetricsParser.TryParse(delimitedString, out serverSideMetrics); - } - - internal static ServerSideMetrics ParseFromDelimitedString(string delimitedString) - { - if (!ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics serverSideMetrics)) - { - throw new FormatException(); - } - - return serverSideMetrics; - } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index 4dd0478985..d9ef1ede8d 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -11,14 +11,14 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class ServerSideMetricsAccumulator { - private readonly List serverSideMetricsList; + private readonly List serverSideMetricsList; public ServerSideMetricsAccumulator() { - this.serverSideMetricsList = new List(); + this.serverSideMetricsList = new List(); } - public void Accumulate(ServerSideMetrics serverSideMetrics) + public void Accumulate(ServerSideMetricsInternal serverSideMetrics) { if (serverSideMetrics == null) { @@ -28,7 +28,7 @@ public void Accumulate(ServerSideMetrics serverSideMetrics) this.serverSideMetricsList.Add(serverSideMetrics); } - public ServerSideMetrics GetServerSideMetrics() + public ServerSideMetricsInternal GetServerSideMetrics() { TimeSpan totalTime = TimeSpan.Zero; long retrievedDocumentCount = 0; @@ -43,7 +43,7 @@ public ServerSideMetrics GetServerSideMetrics() TimeSpan documentWriteTime = TimeSpan.Zero; TimeSpan vMExecutionTime = TimeSpan.Zero; - foreach (ServerSideMetrics serverSideMetrics in this.serverSideMetricsList) + foreach (ServerSideMetricsInternal serverSideMetrics in this.serverSideMetricsList) { indexHitRatio = ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount); totalTime += serverSideMetrics.TotalTime; @@ -59,7 +59,7 @@ public ServerSideMetrics GetServerSideMetrics() vMExecutionTime += serverSideMetrics.VMExecutionTime; } - return new ServerSideMetrics( + return new ServerSideMetricsInternal( retrievedDocumentCount: retrievedDocumentCount, retrievedDocumentSize: retrievedDocumentSize, outputDocumentCount: outputDocumentCount, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs new file mode 100644 index 0000000000..497554e676 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs @@ -0,0 +1,161 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + using System.Collections.Generic; + + /// + /// internal implementation of metrics received for queries from the backend. + /// + internal sealed class ServerSideMetricsInternal + { + /// + /// QueryMetrics that with all members having default (but not null) members. + /// + public static readonly ServerSideMetricsInternal Empty = new ServerSideMetricsInternal( + retrievedDocumentCount: default, + retrievedDocumentSize: default, + outputDocumentCount: default, + outputDocumentSize: default, + indexHitRatio: default, + totalQueryExecutionTime: default, + queryPreparationTimes: QueryPreparationTimesInternal.Zero, + indexLookupTime: default, + documentLoadTime: default, + vmExecutionTime: default, + runtimeExecutionTimes: RuntimeExecutionTimesInternal.Empty, + documentWriteTime: default); + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public ServerSideMetricsInternal( + long retrievedDocumentCount, + long retrievedDocumentSize, + long outputDocumentCount, + long outputDocumentSize, + double indexHitRatio, + TimeSpan totalQueryExecutionTime, + QueryPreparationTimesInternal queryPreparationTimes, + TimeSpan indexLookupTime, + TimeSpan documentLoadTime, + TimeSpan vmExecutionTime, + RuntimeExecutionTimesInternal runtimeExecutionTimes, + TimeSpan documentWriteTime) + { + this.RetrievedDocumentCount = retrievedDocumentCount; + this.RetrievedDocumentSize = retrievedDocumentSize; + this.OutputDocumentCount = outputDocumentCount; + this.OutputDocumentSize = outputDocumentSize; + this.IndexHitRatio = indexHitRatio; + this.TotalTime = totalQueryExecutionTime; + this.QueryPreparationTimes = queryPreparationTimes ?? throw new ArgumentNullException($"{nameof(queryPreparationTimes)} can not be null."); + this.IndexLookupTime = indexLookupTime; + this.DocumentLoadTime = documentLoadTime; + this.VMExecutionTime = vmExecutionTime; + this.RuntimeExecutionTimes = runtimeExecutionTimes ?? throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null."); + this.DocumentWriteTime = documentWriteTime; + } + + /// + /// Gets the total query time in the Azure Cosmos database service. + /// + public TimeSpan TotalTime { get; } + + /// + /// Gets the number of documents retrieved during query in the Azure Cosmos database service. + /// + public long RetrievedDocumentCount { get; } + + /// + /// Gets the size of documents retrieved in bytes during query in the Azure Cosmos DB service. + /// + public long RetrievedDocumentSize { get; } + + /// + /// Gets the number of documents returned by query in the Azure Cosmos DB service. + /// + public long OutputDocumentCount { get; } + + /// + /// Gets the size of documents outputted in bytes during query in the Azure Cosmos database service. + /// + public long OutputDocumentSize { get; } + + /// + /// Gets the query QueryPreparationTimes in the Azure Cosmos database service. + /// + public QueryPreparationTimesInternal QueryPreparationTimes { get; } + + /// + /// Gets the query index lookup time in the Azure Cosmos database service. + /// + public TimeSpan IndexLookupTime { get; } + + /// + /// Gets the document loading time during query in the Azure Cosmos database service. + /// + public TimeSpan DocumentLoadTime { get; } + + /// + /// Gets the query runtime execution times during query in the Azure Cosmos database service. + /// + public RuntimeExecutionTimesInternal RuntimeExecutionTimes { get; } + + /// + /// Gets the output writing/serializing time during query in the Azure Cosmos database service. + /// + public TimeSpan DocumentWriteTime { get; } + + /// + /// Gets the index hit ratio by query in the Azure Cosmos database service. + /// + public double IndexHitRatio { get; } + + /// + /// Gets the VMExecution Time. + /// + public TimeSpan VMExecutionTime { get; } + + public static ServerSideMetricsInternal Create(IEnumerable serverSideMetricsEnumerable) + { + ServerSideMetricsAccumulator accumulator = default; + foreach (ServerSideMetricsInternal serverSideMetrics in serverSideMetricsEnumerable) + { + accumulator.Accumulate(serverSideMetrics); + } + + return accumulator.GetServerSideMetrics(); + } + + public static bool TryParseFromDelimitedString(string delimitedString, out ServerSideMetricsInternal serverSideMetrics) + { + return ServerSideMetricsParser.TryParse(delimitedString, out serverSideMetrics); + } + + public static ServerSideMetricsInternal ParseFromDelimitedString(string delimitedString) + { + if (!ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetricsInternal serverSideMetrics)) + { + throw new FormatException(); + } + + return serverSideMetrics; + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsParser.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsParser.cs index bc21b849e9..eeba3c6c85 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsParser.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsParser.cs @@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Text; /// - /// Parser for . + /// Parser for . /// #if INTERNAL #pragma warning disable SA1600 @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics #endif static class ServerSideMetricsParser { - public static unsafe bool TryParse(string deliminatedString, out ServerSideMetrics serverSideMetrics) + public static unsafe bool TryParse(string deliminatedString, out ServerSideMetricsInternal serverSideMetrics) { if (deliminatedString == null) { @@ -30,7 +30,7 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri { // Stack allocating a zero length buffer returns a null pointer // so we special case the zero length string. - serverSideMetrics = ServerSideMetrics.Empty; + serverSideMetrics = ServerSideMetricsInternal.Empty; return true; } @@ -258,14 +258,14 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri } } - serverSideMetrics = new ServerSideMetrics( + serverSideMetrics = new ServerSideMetricsInternal( retrievedDocumentCount: retrievedDocumentCount, retrievedDocumentSize: retrievedDocumentSize, outputDocumentCount: outputDocumentCount, outputDocumentSize: outputDocumentSize, indexHitRatio: indexHitRatio, totalQueryExecutionTime: totalQueryExecutionTime, - queryPreparationTimes: new QueryPreparationTimes( + queryPreparationTimes: new QueryPreparationTimesInternal( queryCompilationTime: queryCompilationTime, logicalPlanBuildTime: logicalPlanBuildTime, physicalPlanBuildTime: physicalPlanBuildTime, @@ -273,7 +273,7 @@ public static unsafe bool TryParse(string deliminatedString, out ServerSideMetri indexLookupTime: indexLookupTime, documentLoadTime: documentLoadTime, vmExecutionTime: vmExecutionTime, - runtimeExecutionTimes: new RuntimeExecutionTimes( + runtimeExecutionTimes: new RuntimeExecutionTimesInternal( queryEngineExecutionTime: vmExecutionTime - indexLookupTime - documentLoadTime - documentWriteTime, systemFunctionExecutionTime: systemFunctionExecutionTime, userDefinedFunctionExecutionTime: userDefinedFunctionExecutionTime), diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsTokenizer.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsTokenizer.cs index bba72e211d..431f3add64 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsTokenizer.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsTokenizer.cs @@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System.Text; /// - /// Tokenizer for + /// Tokenizer for /// #if INTERNAL #pragma warning disable SA1600 diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs index 8342c24f33..11fa4f5868 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs @@ -5,6 +5,11 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { internal static class ServerSideMetricsUtils { + public static string FormatTrace(this ServerSideMetricsInternal serverSideMetrics) + { + return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; + } + public static string FormatTrace(this ServerSideMetrics serverSideMetrics) { return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs index 23cac83f93..fca25a89bb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs @@ -84,7 +84,7 @@ private async Task ValidateMetrics(int throughput) } ServerSideMetrics serverSideMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); - bool tryParseResult = ServerSideMetrics.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out ServerSideMetrics serverSideMetricsFromHeaders); + bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out ServerSideMetricsInternal serverSideMetricsFromHeaders); Assert.IsTrue(tryParseResult); headerMetricsAccumulator.Accumulate(serverSideMetricsFromHeaders); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs index e37077976e..40484e792c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs @@ -37,7 +37,7 @@ public void TestParse() ValueStopwatch stopwatch = ValueStopwatch.StartNew(); for (int i = 0; i < 100000; i++) { - ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics serverSideMetrics); + ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetricsInternal serverSideMetrics); } stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs index 79e3b18c94..c8ae95e5b2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs @@ -30,14 +30,14 @@ public class ServerSideMetricsTests private static readonly string delimitedString = $"totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds};queryCompileTimeInMs={queryCompileTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={logicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={physicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={queryOptimizationTime.TotalMilliseconds};VMExecutionTimeInMs={vmExecutionTime.TotalMilliseconds};indexLookupTimeInMs={indexLookupTime.TotalMilliseconds};documentLoadTimeInMs={documentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={systemFunctionExecuteTime.TotalMilliseconds};userFunctionExecuteTimeInMs={userFunctionExecuteTime.TotalMilliseconds};retrievedDocumentCount={retrievedDocumentCount};retrievedDocumentSize={retrievedDocumentSize};outputDocumentCount={outputDocumentCount};outputDocumentSize={outputDocumentSize};writeOutputTimeInMs={documentWriteTime.TotalMilliseconds};indexUtilizationRatio={indexHitRatio}"; - internal static readonly ServerSideMetrics ServerSideMetrics = new ServerSideMetrics( + internal static readonly ServerSideMetricsInternal ServerSideMetrics = new ServerSideMetricsInternal( retrievedDocumentCount, retrievedDocumentSize, outputDocumentCount, outputDocumentSize, indexHitRatio, totalExecutionTime, - new QueryPreparationTimes( + new QueryPreparationTimesInternal( queryCompileTime, logicalPlanBuildTime, physicalPlanBuildTime, @@ -45,7 +45,7 @@ public class ServerSideMetricsTests indexLookupTime, documentLoadTime, vmExecutionTime, - new RuntimeExecutionTimes( + new RuntimeExecutionTimesInternal( totalExecutionTime - systemFunctionExecuteTime - userFunctionExecuteTime, systemFunctionExecuteTime, userFunctionExecuteTime), @@ -61,7 +61,7 @@ public void TestParse() [TestMethod] public void TestParseEmptyString() { - ServerSideMetricsTests.ValidateParse(string.Empty, ServerSideMetrics.Empty); + ServerSideMetricsTests.ValidateParse(string.Empty, ServerSideMetricsInternal.Empty); } [TestMethod] @@ -70,14 +70,14 @@ public void TestParseStringWithMissingFields() TimeSpan totalExecutionTime = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 33.67)); string delimitedString = $"totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds}"; - ServerSideMetrics expected = new ServerSideMetrics( + ServerSideMetricsInternal expected = new ServerSideMetricsInternal( default(long), default(long), default(long), default(long), default(double), totalExecutionTime, - new QueryPreparationTimes( + new QueryPreparationTimesInternal( default(TimeSpan), default(TimeSpan), default(TimeSpan), @@ -85,7 +85,7 @@ public void TestParseStringWithMissingFields() default(TimeSpan), default(TimeSpan), default(TimeSpan), - new RuntimeExecutionTimes( + new RuntimeExecutionTimesInternal( default(TimeSpan), default(TimeSpan), default(TimeSpan)), @@ -98,14 +98,14 @@ public void TestParseStringWithMissingFields() public void TestParseStringWithTrailingUnknownField() { string delimitedString = $"thisIsNotAKnownField=asdf"; - ServerSideMetrics expected = new ServerSideMetrics( + ServerSideMetricsInternal expected = new ServerSideMetricsInternal( default(long), default(long), default(long), default(long), default(double), default(TimeSpan), - new QueryPreparationTimes( + new QueryPreparationTimesInternal( default(TimeSpan), default(TimeSpan), default(TimeSpan), @@ -113,7 +113,7 @@ public void TestParseStringWithTrailingUnknownField() default(TimeSpan), default(TimeSpan), default(TimeSpan), - new RuntimeExecutionTimes( + new RuntimeExecutionTimesInternal( default(TimeSpan), default(TimeSpan), default(TimeSpan)), @@ -127,7 +127,7 @@ public void TestParseStringWithTrailingUnknownField() [DataRow("totalExecutionTimeInMs=33.6+totalExecutionTimeInMs=33.6", DisplayName = "Wrong Delimiter")] public void TestNegativeCases(string delimitedString) { - Assert.IsFalse(ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics serverSideMetrics)); + Assert.IsFalse(ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetricsInternal serverSideMetrics)); } [TestMethod] @@ -135,14 +135,14 @@ public void TestParseStringWithUnknownField() { TimeSpan totalExecutionTime = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 33.67)); string delimitedString = $"totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds};thisIsNotAKnownField={totalExecutionTime.TotalMilliseconds};totalExecutionTimeInMs={totalExecutionTime.TotalMilliseconds}"; - ServerSideMetrics expected = new ServerSideMetrics( + ServerSideMetricsInternal expected = new ServerSideMetricsInternal( default(long), default(long), default(long), default(long), default(double), totalExecutionTime, - new QueryPreparationTimes( + new QueryPreparationTimesInternal( default(TimeSpan), default(TimeSpan), default(TimeSpan), @@ -150,7 +150,7 @@ public void TestParseStringWithUnknownField() default(TimeSpan), default(TimeSpan), default(TimeSpan), - new RuntimeExecutionTimes( + new RuntimeExecutionTimesInternal( default(TimeSpan), default(TimeSpan), default(TimeSpan)), @@ -166,15 +166,15 @@ public void TestAccumulator() accumulator.Accumulate(ServerSideMetrics); accumulator.Accumulate(ServerSideMetrics); - ServerSideMetrics serverSideMetricsFromAddition = accumulator.GetServerSideMetrics(); - ServerSideMetrics expected = new ServerSideMetrics( + ServerSideMetricsInternal serverSideMetricsFromAddition = accumulator.GetServerSideMetrics(); + ServerSideMetricsInternal expected = new ServerSideMetricsInternal( retrievedDocumentCount * 2, retrievedDocumentSize * 2, outputDocumentCount * 2, outputDocumentSize * 2, indexHitRatio, totalExecutionTime * 2, - new QueryPreparationTimes( + new QueryPreparationTimesInternal( queryCompileTime * 2, logicalPlanBuildTime * 2, physicalPlanBuildTime * 2, @@ -182,7 +182,7 @@ public void TestAccumulator() indexLookupTime * 2, documentLoadTime * 2, vmExecutionTime * 2, - new RuntimeExecutionTimes( + new RuntimeExecutionTimesInternal( (totalExecutionTime - systemFunctionExecuteTime - userFunctionExecuteTime) * 2, systemFunctionExecuteTime * 2, userFunctionExecuteTime * 2), @@ -191,13 +191,13 @@ public void TestAccumulator() ServerSideMetricsTests.ValidateServerSideMetricsEquals(expected, serverSideMetricsFromAddition); } - private static void ValidateParse(string delimitedString, ServerSideMetrics expected) + private static void ValidateParse(string delimitedString, ServerSideMetricsInternal expected) { - Assert.IsTrue(ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetrics actual)); + Assert.IsTrue(ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetricsInternal actual)); ServerSideMetricsTests.ValidateServerSideMetricsEquals(expected, actual); } - private static void ValidateServerSideMetricsEquals(ServerSideMetrics expected, ServerSideMetrics actual) + private static void ValidateServerSideMetricsEquals(ServerSideMetricsInternal expected, ServerSideMetricsInternal actual) { Assert.AreEqual(expected.DocumentLoadTime, actual.DocumentLoadTime); Assert.AreEqual(expected.DocumentWriteTime, actual.DocumentWriteTime); From 4f9dd800c79c73ab2d424e8ce74ff6f10d7b24bb Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 3 Aug 2023 12:56:54 -0700 Subject: [PATCH 23/43] API update --- .../Contracts/DotNetSDKAPI.json | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 19c6af457e..f35cf967fe 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -6291,11 +6291,6 @@ "Type": "Property", "Attributes": [], "MethodInfo": "System.TimeSpan QueryOptimizationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)]" } }, "NestedTypes": {} @@ -6338,11 +6333,6 @@ "Type": "Property", "Attributes": [], "MethodInfo": "System.TimeSpan UserDefinedFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(System.TimeSpan, System.TimeSpan, System.TimeSpan)]" } }, "NestedTypes": {} @@ -6493,11 +6483,6 @@ "Type": "Property", "Attributes": [], "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes, System.TimeSpan, System.TimeSpan, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes, System.TimeSpan)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes, System.TimeSpan, System.TimeSpan, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes, System.TimeSpan), Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes, System.TimeSpan, System.TimeSpan, System.TimeSpan, Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes, System.TimeSpan)]" } }, "NestedTypes": {} From a1a39157612a6c5d043b345127fbd325bf58532f Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 3 Aug 2023 17:14:28 -0700 Subject: [PATCH 24/43] change namespace --- .../src/Query/Core/Metrics/QueryPreparationTimes.cs | 3 ++- .../src/Query/Core/Metrics/RuntimeExecutionTimes.cs | 3 ++- .../src/Query/Core/Metrics/ServerSideMetrics.cs | 3 ++- .../Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs index b6d21c2caa..c17a79ccf4 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs @@ -1,9 +1,10 @@ //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------ -namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +namespace Microsoft.Azure.Cosmos { using System; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Query preparation metrics in the Azure DocumentDB database service. diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs index 9743d38a88..ff036fac1b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs @@ -1,9 +1,10 @@ //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------ -namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +namespace Microsoft.Azure.Cosmos { using System; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Query runtime execution times in the Azure Cosmos DB service. diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index aee6b7fee8..6f11f5eb91 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -2,9 +2,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------ -namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +namespace Microsoft.Azure.Cosmos { using System; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// internal implementation of metrics received for queries from the backend. diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs index 48c3e5accc..a4d295a634 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/ContractTests.cs @@ -38,7 +38,7 @@ public void ClientDllNamespaceTest() #if INTERNAL int expected = 7; #else - int expected = 6; + int expected = 5; #endif ContractTests.NamespaceCountTest(typeof(CosmosClient), expected); } From eccf865a92967281b411e6deb33c05e07577c068 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 3 Aug 2023 18:48:43 -0700 Subject: [PATCH 25/43] Pr comments --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 10 +- .../CosmosItemTests.cs | 9 + .../CosmosTraceDiagnosticsTests.cs | 97 ---- .../Contracts/DotNetSDKAPI.json | 458 +++++++++--------- 4 files changed, 247 insertions(+), 327 deletions(-) delete mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 07b402b1e1..1aca644320 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -15,6 +15,7 @@ namespace Microsoft.Azure.Cosmos.Diagnostics internal sealed class CosmosTraceDiagnostics : CosmosDiagnostics { + private ServerSideMetrics cachedServerSideMetrics { get; set; } public CosmosTraceDiagnostics(ITrace trace) { if (trace == null) @@ -30,6 +31,7 @@ public CosmosTraceDiagnostics(ITrace trace) } this.Value = rootTrace; + this.cachedServerSideMetrics = null; } public ITrace Value { get; } @@ -51,9 +53,15 @@ public override TimeSpan GetClientElapsedTime() public override ServerSideMetrics GetQueryMetrics() { + if (this.cachedServerSideMetrics != null) + { + return this.cachedServerSideMetrics; + } + ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - return new ServerSideMetrics(accumulator.GetServerSideMetrics()); + this.cachedServerSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); + return this.cachedServerSideMetrics; } internal bool IsGoneExceptionHit() diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index b237c68c2a..aee2f1caeb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -33,6 +33,7 @@ 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 @@ -1261,6 +1262,7 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max do { iterationCount++; + ServerSideMetricsAccumulator headerMetricsAccumulator = new ServerSideMetricsAccumulator(); FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator( sql, continuationToken: lastContinuationToken, @@ -1278,6 +1280,13 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max System.Diagnostics.Trace.TraceInformation($"ContinuationToken: {lastContinuationToken}"); Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); + // verify ServerSideMetrics matches metrics retrieved from header + ServerSideMetrics serverSideMetricsFromDiagnostics = response.Diagnostics.GetQueryMetrics(); + bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(response.Headers.QueryMetricsText, out ServerSideMetricsInternal serverSideMetricsFromHeaders); + Assert.IsTrue(tryParseResult); + headerMetricsAccumulator.Accumulate(serverSideMetricsFromHeaders); + Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == serverSideMetricsFromDiagnostics.FormatTrace()); + using (StreamReader sr = new StreamReader(response.Content)) using (JsonTextReader jtr = new JsonTextReader(sr)) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs deleted file mode 100644 index fca25a89bb..0000000000 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosTraceDiagnosticsTests.cs +++ /dev/null @@ -1,97 +0,0 @@ -namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.Azure.Cosmos.Query.Core.Metrics; - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [TestClass] - public class CosmosTraceDiagnosticsTests : BaseCosmosClientHelper - { - [TestInitialize] - public async Task TestInitialize() - { - await base.TestInit(validateSinglePartitionKeyRangeCacheCall: true); - } - - [TestCleanup] - public async Task Cleanup() - { - await base.TestCleanup(); - } - - /// - /// Validate QueryMetrics retrieved from Diagnostics for single partition query. - /// - [TestMethod] - public async Task ValidateMetricsSinglePartitionQuery() - { - await this.ValidateMetrics(throughput: 5000); - } - - /// - /// Validate QueryMetrics retrieved from Diagnostics for multi-partition query. - /// - [TestMethod] - public async Task ValidateMetricsMultiplePartitionQuery() - { - await this.ValidateMetrics(throughput: 15000); - } - - private async Task ValidateMetrics(int throughput) - { - string PartitionKey = "/pk"; - ContainerProperties containerSettings = new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKey); - ContainerResponse containerResponse = await this.database.CreateContainerAsync( - containerSettings, - throughput: throughput, - cancellationToken: this.cancellationToken); - Assert.IsNotNull(containerResponse); - Assert.IsNotNull(containerResponse.Container); - Assert.IsNotNull(containerResponse.Resource); - Container container = containerResponse; - - IList deleteList = await ToDoActivity.CreateRandomItems(container, 3, randomPartitionKey: true); - - ToDoActivity find = deleteList.First(); - QueryDefinition sql = new QueryDefinition("select * from toDoActivity t where t.id = '" + find.id + "'"); - - QueryRequestOptions requestOptions = new QueryRequestOptions() - { - MaxBufferedItemCount = 10, - ResponseContinuationTokenLimitInKb = 500, - MaxItemCount = 1, - MaxConcurrency = 1, - }; - - FeedIterator feedIterator = container.GetItemQueryIterator( - sql, - requestOptions: requestOptions); - - bool found = false; - ServerSideMetricsAccumulator headerMetricsAccumulator = new ServerSideMetricsAccumulator(); - while (feedIterator.HasMoreResults) - { - FeedResponse iter = await feedIterator.ReadNextAsync(); - Assert.IsTrue(iter.Count() <= 1); - if (iter.Count() == 1) - { - found = true; - ToDoActivity response = iter.First(); - Assert.AreEqual(find.id, response.id); - } - - ServerSideMetrics serverSideMetricsFromDiagnostics = iter.Diagnostics.GetQueryMetrics(); - bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(iter.Headers.QueryMetricsText, out ServerSideMetricsInternal serverSideMetricsFromHeaders); - Assert.IsTrue(tryParseResult); - - headerMetricsAccumulator.Accumulate(serverSideMetricsFromHeaders); - Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == serverSideMetricsFromDiagnostics.FormatTrace()); - } - - Assert.IsTrue(found); - } - } -} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index f35cf967fe..a2c4415301 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -3124,10 +3124,10 @@ "Attributes": [], "MethodInfo": "Int32 GetFailedRequestCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.ServerSideMetrics GetQueryMetrics()": { + "Microsoft.Azure.Cosmos.ServerSideMetrics GetQueryMetrics()": { "Type": "Method", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.ServerSideMetrics GetQueryMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics GetQueryMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Uri]] GetContactedRegions()": { "Type": "Method", @@ -6241,288 +6241,96 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.QueryDefinition;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { - "System.TimeSpan get_LogicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_PhysicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_QueryCompilationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_QueryOptimizationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Microsoft.Azure.Cosmos.QueryDefinition WithParameter(System.String, System.Object)": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan LogicalPlanBuildTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan LogicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan PhysicalPlanBuildTime": { - "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan PhysicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.QueryDefinition WithParameter(System.String, System.Object);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan QueryCompilationTime": { - "Type": "Property", + "Microsoft.Azure.Cosmos.QueryDefinition WithParameterStream(System.String, System.IO.Stream)": { + "Type": "Method", "Attributes": [], - "MethodInfo": "System.TimeSpan QueryCompilationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.QueryDefinition WithParameterStream(System.String, System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan QueryOptimizationTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryOptimizationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - } - }, - "NestedTypes": {} - }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.TimeSpan get_QueryEngineExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Object]] GetQueryParameters()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Object]] GetQueryParameters();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_SystemFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.String get_QueryText()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.String get_QueryText();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_UserDefinedFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", + "System.String QueryText[Newtonsoft.Json.JsonPropertyAttribute(Order = 0, PropertyName = \"query\")]": { + "Type": "Property", "Attributes": [ - "CompilerGeneratedAttribute" + "JsonPropertyAttribute" ], - "MethodInfo": "System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan QueryEngineExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryEngineExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan SystemFunctionExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan SystemFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.String QueryText;CanRead:True;CanWrite:False;System.String get_QueryText();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan UserDefinedFunctionExecutionTime": { - "Type": "Property", + "Void .ctor(System.String)": { + "Type": "Constructor", "Attributes": [], - "MethodInfo": "System.TimeSpan UserDefinedFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "[Void .ctor(System.String), Void .ctor(System.String)]" } }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.ServerSideMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.QueryPreparationTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { - "Double get_IndexHitRatio()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Double IndexHitRatio": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Double IndexHitRatio;CanRead:True;CanWrite:False;Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 get_OutputDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 get_OutputDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 get_RetrievedDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 get_RetrievedDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 OutputDocumentCount": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Int64 OutputDocumentCount;CanRead:True;CanWrite:False;Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 OutputDocumentSize": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Int64 OutputDocumentSize;CanRead:True;CanWrite:False;Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 RetrievedDocumentCount": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Int64 RetrievedDocumentCount;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int64 RetrievedDocumentSize": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes get_QueryPreparationTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes QueryPreparationTimes": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes QueryPreparationTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.Query.Core.Metrics.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes get_RuntimeExecutionTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes RuntimeExecutionTimes": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes RuntimeExecutionTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.Query.Core.Metrics.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan DocumentLoadTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan DocumentLoadTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan DocumentWriteTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan DocumentWriteTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_DocumentLoadTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_DocumentWriteTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_LogicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_IndexLookupTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_PhysicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_TotalTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_QueryCompilationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_VMExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_QueryOptimizationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan IndexLookupTime": { + "System.TimeSpan LogicalPlanBuildTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan LogicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan TotalTime": { + "System.TimeSpan PhysicalPlanBuildTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan TotalTime;CanRead:True;CanWrite:False;System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan PhysicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan VMExecutionTime": { + "System.TimeSpan QueryCompilationTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - } - }, - "NestedTypes": {} - }, - "Microsoft.Azure.Cosmos.QueryDefinition;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "Microsoft.Azure.Cosmos.QueryDefinition WithParameter(System.String, System.Object)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.QueryDefinition WithParameter(System.String, System.Object);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.QueryDefinition WithParameterStream(System.String, System.IO.Stream)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.QueryDefinition WithParameterStream(System.String, System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Object]] GetQueryParameters()": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Object]] GetQueryParameters();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.String get_QueryText()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.String get_QueryText();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan QueryCompilationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.String QueryText[Newtonsoft.Json.JsonPropertyAttribute(Order = 0, PropertyName = \"query\")]": { + "System.TimeSpan QueryOptimizationTime": { "Type": "Property", - "Attributes": [ - "JsonPropertyAttribute" - ], - "MethodInfo": "System.String QueryText;CanRead:True;CanWrite:False;System.String get_QueryText();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.String)": { - "Type": "Constructor", "Attributes": [], - "MethodInfo": "[Void .ctor(System.String), Void .ctor(System.String)]" + "MethodInfo": "System.TimeSpan QueryOptimizationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -8338,6 +8146,48 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.RuntimeExecutionTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.TimeSpan get_QueryEngineExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_SystemFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_UserDefinedFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan QueryEngineExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryEngineExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan SystemFunctionExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan SystemFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan UserDefinedFunctionExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan UserDefinedFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.Scripts.Scripts;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { @@ -9280,6 +9130,156 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.ServerSideMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "Double get_IndexHitRatio()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Double IndexHitRatio": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Double IndexHitRatio;CanRead:True;CanWrite:False;Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_OutputDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_OutputDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_RetrievedDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 get_RetrievedDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 OutputDocumentCount": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 OutputDocumentCount;CanRead:True;CanWrite:False;Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 OutputDocumentSize": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 OutputDocumentSize;CanRead:True;CanWrite:False;Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 RetrievedDocumentCount": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 RetrievedDocumentCount;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int64 RetrievedDocumentSize": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.QueryPreparationTimes get_QueryPreparationTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.QueryPreparationTimes QueryPreparationTimes": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.QueryPreparationTimes QueryPreparationTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.RuntimeExecutionTimes get_RuntimeExecutionTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.RuntimeExecutionTimes RuntimeExecutionTimes": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.RuntimeExecutionTimes RuntimeExecutionTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan DocumentLoadTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan DocumentLoadTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan DocumentWriteTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan DocumentWriteTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_DocumentLoadTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_DocumentWriteTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_IndexLookupTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_TotalTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_VMExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan IndexLookupTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan TotalTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan TotalTime;CanRead:True;CanWrite:False;System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan VMExecutionTime": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.Spatial.BoundingBox;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { From 120bccf9d0d3b637491c2e624855f83d0287498d Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 7 Aug 2023 15:46:01 -0700 Subject: [PATCH 26/43] public constructors and bug fix --- .../src/Query/Core/Metrics/QueryMetrics.cs | 6 +-- .../Core/Metrics/QueryPreparationTimes.cs | 19 ++++++++ .../Core/Metrics/RuntimeExecutionTimes.cs | 16 +++++++ .../Query/Core/Metrics/ServerSideMetrics.cs | 43 +++++++++++++++++++ .../Metrics/ServerSideMetricsAccumulator.cs | 4 +- 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs index e35a0263fb..ed3993d47e 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetrics.cs @@ -29,9 +29,9 @@ sealed class QueryMetrics clientSideMetrics: ClientSideMetrics.Empty); public QueryMetrics( - ServerSideMetricsInternal serverSideMetrics, - IndexUtilizationInfo indexUtilizationInfo, - ClientSideMetrics clientSideMetrics) + ServerSideMetricsInternal serverSideMetrics, + IndexUtilizationInfo indexUtilizationInfo, + ClientSideMetrics clientSideMetrics) { this.ServerSideMetrics = serverSideMetrics ?? throw new ArgumentNullException(nameof(serverSideMetrics)); this.IndexUtilizationInfo = indexUtilizationInfo ?? throw new ArgumentNullException(nameof(indexUtilizationInfo)); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs index c17a79ccf4..1555054eb7 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs @@ -23,6 +23,25 @@ internal QueryPreparationTimes(QueryPreparationTimesInternal queryPreparationTim this.QueryOptimizationTime = queryPreparationTimesInternal.QueryOptimizationTime; } + /// + /// Initializes a new instance of the QueryPreparationTimes class. + /// + /// Query compile and optimization time + /// Query logical plan build time + /// Query physical plan build time + /// Query optimization time + public QueryPreparationTimes( + TimeSpan queryCompilationTime, + TimeSpan logicalPlanBuildTime, + TimeSpan physicalPlanBuildTime, + TimeSpan queryOptimizationTime) + { + this.QueryCompilationTime = queryCompilationTime; + this.LogicalPlanBuildTime = logicalPlanBuildTime; + this.PhysicalPlanBuildTime = physicalPlanBuildTime; + this.QueryOptimizationTime = queryOptimizationTime; + } + /// /// Gets the query compile time in the Azure DocumentDB database service. /// diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs index ff036fac1b..b49d5204a5 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs @@ -22,6 +22,22 @@ internal RuntimeExecutionTimes(RuntimeExecutionTimesInternal runtimeExecutionTim this.UserDefinedFunctionExecutionTime = runtimeExecutionTimesInternal.UserDefinedFunctionExecutionTime; } + /// + /// Initializes a new instance of the RuntimeExecutionTimes class. + /// + /// Query end - to - end execution time + /// Total time spent executing system functions + /// Total time spent executing user - defined functions + public RuntimeExecutionTimes( + TimeSpan queryEngineExecutionTime, + TimeSpan systemFunctionExecutionTime, + TimeSpan userDefinedFunctionExecutionTime) + { + this.QueryEngineExecutionTime = queryEngineExecutionTime; + this.SystemFunctionExecutionTime = systemFunctionExecutionTime; + this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTime; + } + /// /// Gets the total query runtime execution time in the Azure Cosmos DB service. /// diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 6f11f5eb91..99b126719f 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -32,6 +32,49 @@ internal ServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) this.DocumentWriteTime = serverSideMetricsInternal.DocumentWriteTime; } + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public ServerSideMetrics( + long retrievedDocumentCount, + long retrievedDocumentSize, + long outputDocumentCount, + long outputDocumentSize, + double indexHitRatio, + TimeSpan totalQueryExecutionTime, + QueryPreparationTimes queryPreparationTimes, + TimeSpan indexLookupTime, + TimeSpan documentLoadTime, + TimeSpan vmExecutionTime, + RuntimeExecutionTimes runtimeExecutionTimes, + TimeSpan documentWriteTime) + { + this.RetrievedDocumentCount = retrievedDocumentCount; + this.RetrievedDocumentSize = retrievedDocumentSize; + this.OutputDocumentCount = outputDocumentCount; + this.OutputDocumentSize = outputDocumentSize; + this.IndexHitRatio = indexHitRatio; + this.TotalTime = totalQueryExecutionTime; + this.QueryPreparationTimes = queryPreparationTimes ?? throw new ArgumentNullException($"{nameof(queryPreparationTimes)} can not be null."); + this.IndexLookupTime = indexLookupTime; + this.DocumentLoadTime = documentLoadTime; + this.VMExecutionTime = vmExecutionTime; + this.RuntimeExecutionTimes = runtimeExecutionTimes ?? throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null."); + this.DocumentWriteTime = documentWriteTime; + } + /// /// Gets the total query time in the Azure Cosmos database service. /// diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index d9ef1ede8d..f70e3d468e 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -45,7 +45,9 @@ public ServerSideMetricsInternal GetServerSideMetrics() foreach (ServerSideMetricsInternal serverSideMetrics in this.serverSideMetricsList) { - indexHitRatio = ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount); + indexHitRatio = (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) != 0 ? + ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : + 0; totalTime += serverSideMetrics.TotalTime; retrievedDocumentCount += serverSideMetrics.RetrievedDocumentCount; retrievedDocumentSize += serverSideMetrics.RetrievedDocumentSize; From 94f56120e553ecf25394318f96de16c6ababd9cf Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 8 Aug 2023 10:34:59 -0700 Subject: [PATCH 27/43] API updates --- .../src/Diagnostics/CosmosDiagnostics.cs | 5 +- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 20 +++++--- .../Query/Core/Metrics/ClientSideMetrics.cs | 1 - .../Metrics/PartitionedServerSideMetrics.cs | 49 +++++++++++++++++++ .../Metrics/ServerSideAccumulatedMetrics.cs | 34 +++++++++++++ .../Query/Core/Metrics/ServerSideMetrics.cs | 2 +- .../Metrics/ServerSideMetricsAccumulator.cs | 36 +++++++++++++- .../Core/Metrics/ServerSideMetricsInternal.cs | 18 ++++++- .../CosmosItemTests.cs | 4 +- 9 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs index 98e2ddaf42..cbb29eb0ca 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs @@ -5,7 +5,6 @@ namespace Microsoft.Azure.Cosmos { using System; using System.Collections.Generic; - using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Contains the cosmos diagnostic information for the current request to Azure Cosmos DB service. @@ -45,10 +44,10 @@ public virtual int GetFailedRequestCount() } /// - /// This represents the accumulated backend query metrics for the request. + /// This represents the backend query metrics for the request. /// /// The accumulated backend metrics for the request. - public virtual ServerSideMetrics GetQueryMetrics() + public virtual ServerSideAccumulatedMetrics GetQueryMetrics() { // Default implementation avoids breaking change for users upgrading. throw new NotImplementedException($"{nameof(CosmosDiagnostics)}.{nameof(GetQueryMetrics)}"); diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 1aca644320..01a63732f9 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos.Diagnostics { using System; using System.Collections.Generic; + using System.Linq; using System.Text; using Microsoft.Azure.Cosmos.Json; using Microsoft.Azure.Cosmos.Query.Core.Metrics; @@ -15,7 +16,7 @@ namespace Microsoft.Azure.Cosmos.Diagnostics internal sealed class CosmosTraceDiagnostics : CosmosDiagnostics { - private ServerSideMetrics cachedServerSideMetrics { get; set; } + private ServerSideAccumulatedMetrics cachedServerSideAccumulatedMetrics { get; set; } public CosmosTraceDiagnostics(ITrace trace) { if (trace == null) @@ -31,7 +32,7 @@ public CosmosTraceDiagnostics(ITrace trace) } this.Value = rootTrace; - this.cachedServerSideMetrics = null; + this.cachedServerSideAccumulatedMetrics = null; } public ITrace Value { get; } @@ -51,17 +52,22 @@ public override TimeSpan GetClientElapsedTime() return this.Value?.Summary?.RegionsContacted; } - public override ServerSideMetrics GetQueryMetrics() + public override ServerSideAccumulatedMetrics GetQueryMetrics() { - if (this.cachedServerSideMetrics != null) + if (this.cachedServerSideAccumulatedMetrics != null) { - return this.cachedServerSideMetrics; + return this.cachedServerSideAccumulatedMetrics; } ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - this.cachedServerSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); - return this.cachedServerSideMetrics; + + ServerSideMetrics serverSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); + List partitionedServerSideMetrics = + accumulator.GetPartitionedServerSideMetrics().Select(metrics => new PartitionedServerSideMetrics(metrics)).ToList(); + + this.cachedServerSideAccumulatedMetrics = new ServerSideAccumulatedMetrics(serverSideMetrics, partitionedServerSideMetrics); + return this.cachedServerSideAccumulatedMetrics; } internal bool IsGoneExceptionHit() diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs index 287c433c38..ff68271a69 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetrics.cs @@ -5,7 +5,6 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; using System.Collections.Generic; - using System.Linq; /// /// Stores client side QueryMetrics. diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs new file mode 100644 index 0000000000..00931525b3 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs @@ -0,0 +1,49 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + using Microsoft.Azure.Cosmos.Query.Core.Metrics; + + /// + /// Per-partition metrics for queries from the backend. + /// + public sealed class PartitionedServerSideMetrics + { + internal PartitionedServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) + { + this.ServerSideMetrics = new ServerSideMetrics(serverSideMetricsInternal); + this.FeedRange = serverSideMetricsInternal.FeedRange; + this.PartitionKeyRangeId = serverSideMetricsInternal.PartitionKeyRangeId; + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + public PartitionedServerSideMetrics(ServerSideMetrics serverSideMetrics, string feedRange, string partitionKeyRangeId) + { + this.ServerSideMetrics = serverSideMetrics; + this.FeedRange = feedRange; + this.PartitionKeyRangeId = partitionKeyRangeId; + } + + /// + /// Gets the backend metrics for the request. + /// + public ServerSideMetrics ServerSideMetrics { get; } + + /// + /// Gets the FeedRange for a single backend call. + /// + public string FeedRange { get; } + + /// + /// Gets the partition key range id for a single backend call. + /// + public string PartitionKeyRangeId { get; } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs new file mode 100644 index 0000000000..e8e195a6b6 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs @@ -0,0 +1,34 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos +{ + using System.Collections.Generic; + + /// + /// Metrics received for queries from the backend. + /// + public sealed class ServerSideAccumulatedMetrics + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + internal ServerSideAccumulatedMetrics(ServerSideMetrics serverSideMetrics, List serverSideMetricsList) + { + this.ServerSideMetrics = serverSideMetrics; + this.PartitionedServerSideMetrics = serverSideMetricsList; + } + + /// + /// Gets the ServerSideMetrics accumulated for a single round trip. + /// + public ServerSideMetrics ServerSideMetrics { get; } + + /// + /// Gets the list of ServerSideMetrics, one for for each partition. + /// + public List PartitionedServerSideMetrics { get; } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 99b126719f..592599d49c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// - /// internal implementation of metrics received for queries from the backend. + /// Metrics received for queries from the backend. /// public sealed class ServerSideMetrics { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index f70e3d468e..ef7287c050 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -11,7 +11,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal class ServerSideMetricsAccumulator { - private readonly List serverSideMetricsList; + internal readonly List serverSideMetricsList; public ServerSideMetricsAccumulator() { @@ -76,6 +76,11 @@ public ServerSideMetricsInternal GetServerSideMetrics() documentWriteTime: documentWriteTime); } + public List GetPartitionedServerSideMetrics() + { + return this.serverSideMetricsList; + } + public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideMetricsAccumulator accumulator) { if (currentTrace == null) @@ -87,6 +92,8 @@ public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideM { if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) { + queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.FeedRange = currentTrace.Name; + queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.PartitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(currentTrace); accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics); return; } @@ -99,5 +106,32 @@ public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideM return; } + + private static string WalkTraceTreeForPartitionKeyRangeId(ITrace currentTrace) + { + if (currentTrace == null) + { + return null; + } + + foreach (Object datum in currentTrace.Data.Values) + { + if (datum is ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum) + { + return clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList[0].StoreResult.PartitionKeyRangeId; + } + } + + foreach (ITrace childTrace in currentTrace.Children) + { + String partitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(childTrace); + if (partitionKeyRangeId != null) + { + return partitionKeyRangeId; + } + } + + return null; + } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs index 497554e676..3070db88c7 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs @@ -44,6 +44,8 @@ internal sealed class ServerSideMetricsInternal /// /// /// + /// + /// public ServerSideMetricsInternal( long retrievedDocumentCount, long retrievedDocumentSize, @@ -56,7 +58,9 @@ public ServerSideMetricsInternal( TimeSpan documentLoadTime, TimeSpan vmExecutionTime, RuntimeExecutionTimesInternal runtimeExecutionTimes, - TimeSpan documentWriteTime) + TimeSpan documentWriteTime, + string feedRange = null, + string partitionKeyRangeId = null) { this.RetrievedDocumentCount = retrievedDocumentCount; this.RetrievedDocumentSize = retrievedDocumentSize; @@ -70,6 +74,8 @@ public ServerSideMetricsInternal( this.VMExecutionTime = vmExecutionTime; this.RuntimeExecutionTimes = runtimeExecutionTimes ?? throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null."); this.DocumentWriteTime = documentWriteTime; + this.FeedRange = feedRange; + this.PartitionKeyRangeId = partitionKeyRangeId; } /// @@ -132,6 +138,16 @@ public ServerSideMetricsInternal( /// public TimeSpan VMExecutionTime { get; } + /// + /// Gets the FeedRange for a single backend call. + /// + public string FeedRange { get; set; } + + /// + /// Gets the partition key range id for a single backend call. + /// + public string PartitionKeyRangeId { get; set; } + public static ServerSideMetricsInternal Create(IEnumerable serverSideMetricsEnumerable) { ServerSideMetricsAccumulator accumulator = default; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index aee2f1caeb..9b907157d3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1281,11 +1281,11 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); // verify ServerSideMetrics matches metrics retrieved from header - ServerSideMetrics serverSideMetricsFromDiagnostics = response.Diagnostics.GetQueryMetrics(); + ServerSideAccumulatedMetrics serverSideMetricsFromDiagnostics = response.Diagnostics.GetQueryMetrics(); bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(response.Headers.QueryMetricsText, out ServerSideMetricsInternal serverSideMetricsFromHeaders); Assert.IsTrue(tryParseResult); headerMetricsAccumulator.Accumulate(serverSideMetricsFromHeaders); - Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == serverSideMetricsFromDiagnostics.FormatTrace()); + Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == serverSideMetricsFromDiagnostics.ServerSideMetrics.FormatTrace()); using (StreamReader sr = new StreamReader(response.Content)) using (JsonTextReader jtr = new JsonTextReader(sr)) From 065d32330a87b74ab18bbd28e2b8011c08ff00a9 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 11 Aug 2023 09:43:12 -0700 Subject: [PATCH 28/43] renaming and test updates --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 7 ++++++- .../Core/Metrics/ServerSideAccumulatedMetrics.cs | 8 ++++---- .../CosmosItemTests.cs | 13 +++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 01a63732f9..002b8880cc 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -62,10 +62,15 @@ public override ServerSideAccumulatedMetrics GetQueryMetrics() ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - ServerSideMetrics serverSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); List partitionedServerSideMetrics = accumulator.GetPartitionedServerSideMetrics().Select(metrics => new PartitionedServerSideMetrics(metrics)).ToList(); + if (partitionedServerSideMetrics.Count == 0) + { + return null; + } + + ServerSideMetrics serverSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); this.cachedServerSideAccumulatedMetrics = new ServerSideAccumulatedMetrics(serverSideMetrics, partitionedServerSideMetrics); return this.cachedServerSideAccumulatedMetrics; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs index e8e195a6b6..bdbf5cec97 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs @@ -13,18 +13,18 @@ public sealed class ServerSideAccumulatedMetrics /// /// Initializes a new instance of the class. /// - /// + /// /// - internal ServerSideAccumulatedMetrics(ServerSideMetrics serverSideMetrics, List serverSideMetricsList) + internal ServerSideAccumulatedMetrics(ServerSideMetrics cumulativeServerSideMetrics, List serverSideMetricsList) { - this.ServerSideMetrics = serverSideMetrics; + this.CumulativeServerSideMetrics = cumulativeServerSideMetrics; this.PartitionedServerSideMetrics = serverSideMetricsList; } /// /// Gets the ServerSideMetrics accumulated for a single round trip. /// - public ServerSideMetrics ServerSideMetrics { get; } + public ServerSideMetrics CumulativeServerSideMetrics { get; } /// /// Gets the list of ServerSideMetrics, one for for each partition. diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 9b907157d3..08b0ae99b2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -142,6 +142,7 @@ public async Task CreateDropItemTest() Assert.IsFalse(string.IsNullOrEmpty(diagnostics.ToString())); Assert.IsTrue(diagnostics.GetClientElapsedTime() > TimeSpan.Zero); Assert.AreEqual(0, response.Diagnostics.GetFailedRequestCount()); + Assert.IsNull(response.Diagnostics.GetQueryMetrics()); response = await this.Container.ReadItemAsync(testItem.id, new Cosmos.PartitionKey(testItem.pk)); Assert.IsNotNull(response); @@ -159,6 +160,7 @@ public async Task CreateDropItemTest() Assert.IsNotNull(response.Diagnostics); Assert.IsFalse(string.IsNullOrEmpty(response.Diagnostics.ToString())); Assert.IsTrue(response.Diagnostics.GetClientElapsedTime() > TimeSpan.Zero); + Assert.IsNull(response.Diagnostics.GetQueryMetrics()); } [TestMethod] @@ -604,6 +606,7 @@ public async Task UpsertItemTest() Assert.IsNotNull(response); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.IsNotNull(response.Headers.Session); + Assert.IsNull(response.Diagnostics.GetQueryMetrics()); } { @@ -1281,11 +1284,13 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); // verify ServerSideMetrics matches metrics retrieved from header - ServerSideAccumulatedMetrics serverSideMetricsFromDiagnostics = response.Diagnostics.GetQueryMetrics(); - bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(response.Headers.QueryMetricsText, out ServerSideMetricsInternal serverSideMetricsFromHeaders); + ServerSideAccumulatedMetrics metricsFromDiagnostics = response.Diagnostics.GetQueryMetrics(); + bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(response.Headers.QueryMetricsText, out ServerSideMetricsInternal metricsFromHeaders); Assert.IsTrue(tryParseResult); - headerMetricsAccumulator.Accumulate(serverSideMetricsFromHeaders); - Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == serverSideMetricsFromDiagnostics.ServerSideMetrics.FormatTrace()); + headerMetricsAccumulator.Accumulate(metricsFromHeaders); + Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == metricsFromDiagnostics.CumulativeServerSideMetrics.FormatTrace()); + + Assert.IsTrue(metricsFromDiagnostics.PartitionedServerSideMetrics.Count == 1); // can we guarantee this? using (StreamReader sr = new StreamReader(response.Content)) using (JsonTextReader jtr = new JsonTextReader(sr)) From 99679c0677968fc36855eb2ace6404ff98fbfac9 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 11 Aug 2023 13:02:49 -0700 Subject: [PATCH 29/43] PR comments --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 16 +++++++--------- .../Core/Metrics/PartitionedServerSideMetrics.cs | 10 ++++------ .../Metrics/QueryPreparationTimesInternal.cs | 8 ++++---- .../Metrics/RuntimeExecutionTimesInternal.cs | 6 +++--- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index 002b8880cc..b018fb26dc 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -16,7 +16,10 @@ namespace Microsoft.Azure.Cosmos.Diagnostics internal sealed class CosmosTraceDiagnostics : CosmosDiagnostics { - private ServerSideAccumulatedMetrics cachedServerSideAccumulatedMetrics { get; set; } + private readonly Lazy accumulatedMetrics; + + public ServerSideAccumulatedMetrics AccumulatedMetrics => this.accumulatedMetrics.Value; + public CosmosTraceDiagnostics(ITrace trace) { if (trace == null) @@ -32,7 +35,7 @@ public CosmosTraceDiagnostics(ITrace trace) } this.Value = rootTrace; - this.cachedServerSideAccumulatedMetrics = null; + this.accumulatedMetrics = this.accumulatedMetrics = new Lazy(() => this.GetQueryMetrics()); } public ITrace Value { get; } @@ -54,11 +57,6 @@ public override TimeSpan GetClientElapsedTime() public override ServerSideAccumulatedMetrics GetQueryMetrics() { - if (this.cachedServerSideAccumulatedMetrics != null) - { - return this.cachedServerSideAccumulatedMetrics; - } - ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); @@ -71,8 +69,8 @@ public override ServerSideAccumulatedMetrics GetQueryMetrics() } ServerSideMetrics serverSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); - this.cachedServerSideAccumulatedMetrics = new ServerSideAccumulatedMetrics(serverSideMetrics, partitionedServerSideMetrics); - return this.cachedServerSideAccumulatedMetrics; + ServerSideAccumulatedMetrics accumulatedMetrics = new ServerSideAccumulatedMetrics(serverSideMetrics, partitionedServerSideMetrics); + return accumulatedMetrics; } internal bool IsGoneExceptionHit() diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs index 00931525b3..65e56df503 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs @@ -7,15 +7,13 @@ namespace Microsoft.Azure.Cosmos using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// - /// Per-partition metrics for queries from the backend. + /// Represents server side metrics specific for a single partition. /// public sealed class PartitionedServerSideMetrics { internal PartitionedServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) + : this(new ServerSideMetrics(serverSideMetricsInternal), serverSideMetricsInternal.FeedRange, serverSideMetricsInternal.PartitionKeyRangeId) { - this.ServerSideMetrics = new ServerSideMetrics(serverSideMetricsInternal); - this.FeedRange = serverSideMetricsInternal.FeedRange; - this.PartitionKeyRangeId = serverSideMetricsInternal.PartitionKeyRangeId; } /// @@ -37,12 +35,12 @@ public PartitionedServerSideMetrics(ServerSideMetrics serverSideMetrics, string public ServerSideMetrics ServerSideMetrics { get; } /// - /// Gets the FeedRange for a single backend call. + /// Gets the FeedRange for the partition. /// public string FeedRange { get; } /// - /// Gets the partition key range id for a single backend call. + /// Gets the partition key range id for the partition. /// public string PartitionKeyRangeId { get; } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs index 04244521e9..de037a9b98 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs @@ -11,10 +11,10 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal sealed class QueryPreparationTimesInternal { public static readonly QueryPreparationTimesInternal Zero = new QueryPreparationTimesInternal( - queryCompilationTime: default, - logicalPlanBuildTime: default, - physicalPlanBuildTime: default, - queryOptimizationTime: default); + queryCompilationTime: TimeSpan.Zero, + logicalPlanBuildTime: TimeSpan.Zero, + physicalPlanBuildTime: TimeSpan.Zero, + queryOptimizationTime: TimeSpan.Zero); /// /// Initializes a new instance of the QueryPreparationTimes class. diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs index 0b79b6b1e6..c92f376262 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs @@ -11,9 +11,9 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal sealed class RuntimeExecutionTimesInternal { public static readonly RuntimeExecutionTimesInternal Empty = new RuntimeExecutionTimesInternal( - queryEngineExecutionTime: default, - systemFunctionExecutionTime: default, - userDefinedFunctionExecutionTime: default); + queryEngineExecutionTime: TimeSpan.Zero, + systemFunctionExecutionTime: TimeSpan.Zero, + userDefinedFunctionExecutionTime: TimeSpan.Zero); /// /// Initializes a new instance of the RuntimeExecutionTimes class. From 41af90a41d060d6577bfcfa69746a0b69e0c7b5b Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 11 Aug 2023 13:38:32 -0700 Subject: [PATCH 30/43] more PR comments --- .../Core/Metrics/ServerSideMetricsInternal.cs | 24 +++++++++---------- .../Core/Metrics/ServerSideMetricsUtils.cs | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs index 3070db88c7..3d69a5ca93 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs @@ -13,21 +13,21 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics internal sealed class ServerSideMetricsInternal { /// - /// QueryMetrics that with all members having default (but not null) members. + /// QueryMetrics with all members having default (but not null) members. /// public static readonly ServerSideMetricsInternal Empty = new ServerSideMetricsInternal( - retrievedDocumentCount: default, - retrievedDocumentSize: default, - outputDocumentCount: default, - outputDocumentSize: default, - indexHitRatio: default, - totalQueryExecutionTime: default, + retrievedDocumentCount: 0, + retrievedDocumentSize: 0, + outputDocumentCount: 0, + outputDocumentSize: 0, + indexHitRatio: 0, + totalQueryExecutionTime: TimeSpan.Zero, queryPreparationTimes: QueryPreparationTimesInternal.Zero, - indexLookupTime: default, - documentLoadTime: default, - vmExecutionTime: default, + indexLookupTime: TimeSpan.Zero, + documentLoadTime: TimeSpan.Zero, + vmExecutionTime: TimeSpan.Zero, runtimeExecutionTimes: RuntimeExecutionTimesInternal.Empty, - documentWriteTime: default); + documentWriteTime: TimeSpan.Zero); /// /// Initializes a new instance of the class. @@ -150,7 +150,7 @@ public ServerSideMetricsInternal( public static ServerSideMetricsInternal Create(IEnumerable serverSideMetricsEnumerable) { - ServerSideMetricsAccumulator accumulator = default; + ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); foreach (ServerSideMetricsInternal serverSideMetrics in serverSideMetricsEnumerable) { accumulator.Accumulate(serverSideMetrics); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs index 11fa4f5868..d640cada98 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs @@ -10,7 +10,7 @@ public static string FormatTrace(this ServerSideMetricsInternal serverSideMetric return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; } - public static string FormatTrace(this ServerSideMetrics serverSideMetrics) + internal static string FormatTrace(this ServerSideMetrics serverSideMetrics) { return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; } From b31e382f5e28e9191829bb35927bf8898c00c2eb Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 14 Aug 2023 09:42:41 -0700 Subject: [PATCH 31/43] PR comments, test additions --- .../Query/Core/Metrics/ServerSideAccumulatedMetrics.cs | 2 +- .../src/Query/Core/Metrics/ServerSideMetricsUtils.cs | 5 ----- .../CosmosItemTests.cs | 9 +++++++-- .../Query/Metrics/ServerSideMetricsTests.cs | 8 ++++++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs index bdbf5cec97..ac7ea4c410 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs @@ -15,7 +15,7 @@ public sealed class ServerSideAccumulatedMetrics /// /// /// - internal ServerSideAccumulatedMetrics(ServerSideMetrics cumulativeServerSideMetrics, List serverSideMetricsList) + public ServerSideAccumulatedMetrics(ServerSideMetrics cumulativeServerSideMetrics, List serverSideMetricsList) { this.CumulativeServerSideMetrics = cumulativeServerSideMetrics; this.PartitionedServerSideMetrics = serverSideMetricsList; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs index d640cada98..a439bdfd57 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsUtils.cs @@ -9,10 +9,5 @@ public static string FormatTrace(this ServerSideMetricsInternal serverSideMetric { return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; } - - internal static string FormatTrace(this ServerSideMetrics serverSideMetrics) - { - return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; - } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 08b0ae99b2..9001383bf1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1288,9 +1288,9 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(response.Headers.QueryMetricsText, out ServerSideMetricsInternal metricsFromHeaders); Assert.IsTrue(tryParseResult); headerMetricsAccumulator.Accumulate(metricsFromHeaders); - Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == metricsFromDiagnostics.CumulativeServerSideMetrics.FormatTrace()); + Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == SerializeServerSideMetrics(metricsFromDiagnostics.CumulativeServerSideMetrics)); - Assert.IsTrue(metricsFromDiagnostics.PartitionedServerSideMetrics.Count == 1); // can we guarantee this? + Assert.IsTrue(metricsFromDiagnostics.PartitionedServerSideMetrics.Count == 1); //TODO: can we guarantee this? using (StreamReader sr = new StreamReader(response.Content)) using (JsonTextReader jtr = new JsonTextReader(sr)) @@ -3157,5 +3157,10 @@ private static async Task TestNonePKForNonExistingContainer(Container container) Assert.AreEqual(HttpStatusCode.NotFound, ex.StatusCode); } } + + private static string SerializeServerSideMetrics(ServerSideMetrics serverSideMetrics) + { + return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; + } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs index c8ae95e5b2..8a827c130e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs @@ -7,6 +7,7 @@ namespace Microsoft.Azure.Cosmos.Tests.Query.Metrics using System; using VisualStudio.TestTools.UnitTesting; using Microsoft.Azure.Cosmos.Query.Core.Metrics; + using System.Collections.Generic; [TestClass] public class ServerSideMetricsTests @@ -165,8 +166,11 @@ public void TestAccumulator() ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); accumulator.Accumulate(ServerSideMetrics); accumulator.Accumulate(ServerSideMetrics); - ServerSideMetricsInternal serverSideMetricsFromAddition = accumulator.GetServerSideMetrics(); + + List metricsList = new List { ServerSideMetrics, ServerSideMetrics }; + ServerSideMetricsInternal serverSideMetricsFromCreate = ServerSideMetricsInternal.Create(metricsList); + ServerSideMetricsInternal expected = new ServerSideMetricsInternal( retrievedDocumentCount * 2, retrievedDocumentSize * 2, @@ -189,8 +193,8 @@ public void TestAccumulator() documentWriteTime * 2); ServerSideMetricsTests.ValidateServerSideMetricsEquals(expected, serverSideMetricsFromAddition); + ServerSideMetricsTests.ValidateServerSideMetricsEquals(expected, serverSideMetricsFromCreate); } - private static void ValidateParse(string delimitedString, ServerSideMetricsInternal expected) { Assert.IsTrue(ServerSideMetricsParser.TryParse(delimitedString, out ServerSideMetricsInternal actual)); From e6825c398f6610681de8ee089f4c9a8d284e7a8f Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 14 Aug 2023 14:39:33 -0700 Subject: [PATCH 32/43] API updates and more tests --- .../src/Diagnostics/CosmosDiagnostics.cs | 2 +- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 14 +- .../Core/Metrics/QueryPreparationTimes.cs | 65 ----- .../Core/Metrics/RuntimeExecutionTimes.cs | 56 ----- ...rics.cs => ServerSideCumulativeMetrics.cs} | 16 +- .../Query/Core/Metrics/ServerSideMetrics.cs | 25 +- ...ics.cs => ServerSidePartitionedMetrics.cs} | 8 +- .../CosmosItemTests.cs | 51 +++- .../Contracts/DotNetSDKAPI.json | 235 +++++++++--------- 9 files changed, 186 insertions(+), 286 deletions(-) delete mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs delete mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs rename Microsoft.Azure.Cosmos/src/Query/Core/Metrics/{ServerSideAccumulatedMetrics.cs => ServerSideCumulativeMetrics.cs} (57%) rename Microsoft.Azure.Cosmos/src/Query/Core/Metrics/{PartitionedServerSideMetrics.cs => ServerSidePartitionedMetrics.cs} (84%) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs index 26dc69b036..27f6eb7087 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs @@ -47,7 +47,7 @@ public virtual int GetFailedRequestCount() /// This represents the backend query metrics for the request. /// /// The accumulated backend metrics for the request. - public virtual ServerSideAccumulatedMetrics GetQueryMetrics() + public virtual ServerSideCumulativeMetrics GetQueryMetrics() { // Default implementation avoids breaking change for users upgrading. throw new NotImplementedException($"{nameof(CosmosDiagnostics)}.{nameof(GetQueryMetrics)}"); diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index b018fb26dc..da975600e0 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -16,9 +16,9 @@ namespace Microsoft.Azure.Cosmos.Diagnostics internal sealed class CosmosTraceDiagnostics : CosmosDiagnostics { - private readonly Lazy accumulatedMetrics; + private readonly Lazy accumulatedMetrics; - public ServerSideAccumulatedMetrics AccumulatedMetrics => this.accumulatedMetrics.Value; + public ServerSideCumulativeMetrics AccumulatedMetrics => this.accumulatedMetrics.Value; public CosmosTraceDiagnostics(ITrace trace) { @@ -35,7 +35,7 @@ public CosmosTraceDiagnostics(ITrace trace) } this.Value = rootTrace; - this.accumulatedMetrics = this.accumulatedMetrics = new Lazy(() => this.GetQueryMetrics()); + this.accumulatedMetrics = this.accumulatedMetrics = new Lazy(() => this.GetQueryMetrics()); } public ITrace Value { get; } @@ -55,13 +55,13 @@ public override TimeSpan GetClientElapsedTime() return this.Value?.Summary?.RegionsContacted; } - public override ServerSideAccumulatedMetrics GetQueryMetrics() + public override ServerSideCumulativeMetrics GetQueryMetrics() { ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - List partitionedServerSideMetrics = - accumulator.GetPartitionedServerSideMetrics().Select(metrics => new PartitionedServerSideMetrics(metrics)).ToList(); + List partitionedServerSideMetrics = + accumulator.GetPartitionedServerSideMetrics().Select(metrics => new ServerSidePartitionedMetrics(metrics)).ToList(); if (partitionedServerSideMetrics.Count == 0) { @@ -69,7 +69,7 @@ public override ServerSideAccumulatedMetrics GetQueryMetrics() } ServerSideMetrics serverSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); - ServerSideAccumulatedMetrics accumulatedMetrics = new ServerSideAccumulatedMetrics(serverSideMetrics, partitionedServerSideMetrics); + ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(serverSideMetrics, partitionedServerSideMetrics); return accumulatedMetrics; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs deleted file mode 100644 index 1555054eb7..0000000000 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimes.cs +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ -namespace Microsoft.Azure.Cosmos -{ - using System; - using Microsoft.Azure.Cosmos.Query.Core.Metrics; - - /// - /// Query preparation metrics in the Azure DocumentDB database service. - /// - public sealed class QueryPreparationTimes - { - /// - /// Initializes a new instance of the QueryPreparationTimes class. - /// - /// - internal QueryPreparationTimes(QueryPreparationTimesInternal queryPreparationTimesInternal) - { - this.QueryCompilationTime = queryPreparationTimesInternal.QueryCompilationTime; - this.LogicalPlanBuildTime = queryPreparationTimesInternal.LogicalPlanBuildTime; - this.PhysicalPlanBuildTime = queryPreparationTimesInternal.PhysicalPlanBuildTime; - this.QueryOptimizationTime = queryPreparationTimesInternal.QueryOptimizationTime; - } - - /// - /// Initializes a new instance of the QueryPreparationTimes class. - /// - /// Query compile and optimization time - /// Query logical plan build time - /// Query physical plan build time - /// Query optimization time - public QueryPreparationTimes( - TimeSpan queryCompilationTime, - TimeSpan logicalPlanBuildTime, - TimeSpan physicalPlanBuildTime, - TimeSpan queryOptimizationTime) - { - this.QueryCompilationTime = queryCompilationTime; - this.LogicalPlanBuildTime = logicalPlanBuildTime; - this.PhysicalPlanBuildTime = physicalPlanBuildTime; - this.QueryOptimizationTime = queryOptimizationTime; - } - - /// - /// Gets the query compile time in the Azure DocumentDB database service. - /// - public TimeSpan QueryCompilationTime { get; } - - /// - /// Gets the query logical plan build time in the Azure DocumentDB database service. - /// - public TimeSpan LogicalPlanBuildTime { get; } - - /// - /// Gets the query physical plan build time in the Azure DocumentDB database service. - /// - public TimeSpan PhysicalPlanBuildTime { get; } - - /// - /// Gets the query optimization time in the Azure DocumentDB database service. - /// - public TimeSpan QueryOptimizationTime { get; } - } -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs deleted file mode 100644 index b49d5204a5..0000000000 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimes.cs +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ -namespace Microsoft.Azure.Cosmos -{ - using System; - using Microsoft.Azure.Cosmos.Query.Core.Metrics; - - /// - /// Query runtime execution times in the Azure Cosmos DB service. - /// - public sealed class RuntimeExecutionTimes - { - /// - /// Initializes a new instance of the RuntimeExecutionTimes class. - /// - /// - internal RuntimeExecutionTimes(RuntimeExecutionTimesInternal runtimeExecutionTimesInternal) - { - this.QueryEngineExecutionTime = runtimeExecutionTimesInternal.QueryEngineExecutionTime; - this.SystemFunctionExecutionTime = runtimeExecutionTimesInternal.SystemFunctionExecutionTime; - this.UserDefinedFunctionExecutionTime = runtimeExecutionTimesInternal.UserDefinedFunctionExecutionTime; - } - - /// - /// Initializes a new instance of the RuntimeExecutionTimes class. - /// - /// Query end - to - end execution time - /// Total time spent executing system functions - /// Total time spent executing user - defined functions - public RuntimeExecutionTimes( - TimeSpan queryEngineExecutionTime, - TimeSpan systemFunctionExecutionTime, - TimeSpan userDefinedFunctionExecutionTime) - { - this.QueryEngineExecutionTime = queryEngineExecutionTime; - this.SystemFunctionExecutionTime = systemFunctionExecutionTime; - this.UserDefinedFunctionExecutionTime = userDefinedFunctionExecutionTime; - } - - /// - /// Gets the total query runtime execution time in the Azure Cosmos DB service. - /// - public TimeSpan QueryEngineExecutionTime { get; } - - /// - /// Gets the query system function execution time in the Azure Cosmos DB service. - /// - public TimeSpan SystemFunctionExecutionTime { get; } - - /// - /// Gets the query user defined function execution time in the Azure Cosmos DB service. - /// - public TimeSpan UserDefinedFunctionExecutionTime { get; } - } -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs similarity index 57% rename from Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs rename to Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs index ac7ea4c410..69e1c80dfa 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideAccumulatedMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs @@ -8,27 +8,27 @@ namespace Microsoft.Azure.Cosmos /// /// Metrics received for queries from the backend. /// - public sealed class ServerSideAccumulatedMetrics + public sealed class ServerSideCumulativeMetrics { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// + /// /// - public ServerSideAccumulatedMetrics(ServerSideMetrics cumulativeServerSideMetrics, List serverSideMetricsList) + public ServerSideCumulativeMetrics(ServerSideMetrics cumulativeMetrics, List serverSideMetricsList) { - this.CumulativeServerSideMetrics = cumulativeServerSideMetrics; - this.PartitionedServerSideMetrics = serverSideMetricsList; + this.CumulativeMetrics = cumulativeMetrics; + this.PartitionedMetrics = serverSideMetricsList; } /// /// Gets the ServerSideMetrics accumulated for a single round trip. /// - public ServerSideMetrics CumulativeServerSideMetrics { get; } + public ServerSideMetrics CumulativeMetrics { get; } /// /// Gets the list of ServerSideMetrics, one for for each partition. /// - public List PartitionedServerSideMetrics { get; } + public List PartitionedMetrics { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 592599d49c..35bf61cada 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -24,11 +24,16 @@ internal ServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) this.OutputDocumentSize = serverSideMetricsInternal.OutputDocumentSize; this.IndexHitRatio = serverSideMetricsInternal.IndexHitRatio; this.TotalTime = serverSideMetricsInternal.TotalTime; - this.QueryPreparationTimes = new QueryPreparationTimes(serverSideMetricsInternal.QueryPreparationTimes); + this.QueryPreparationTimes = serverSideMetricsInternal.QueryPreparationTimes.LogicalPlanBuildTime + + serverSideMetricsInternal.QueryPreparationTimes.PhysicalPlanBuildTime + + serverSideMetricsInternal.QueryPreparationTimes.QueryCompilationTime + + serverSideMetricsInternal.QueryPreparationTimes.QueryOptimizationTime; this.IndexLookupTime = serverSideMetricsInternal.IndexLookupTime; this.DocumentLoadTime = serverSideMetricsInternal.DocumentLoadTime; this.VMExecutionTime = serverSideMetricsInternal.VMExecutionTime; - this.RuntimeExecutionTimes = new RuntimeExecutionTimes(serverSideMetricsInternal.RuntimeExecutionTimes); + this.RuntimeExecutionTimes = serverSideMetricsInternal.RuntimeExecutionTimes.QueryEngineExecutionTime + + serverSideMetricsInternal.RuntimeExecutionTimes.SystemFunctionExecutionTime + + serverSideMetricsInternal.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime; this.DocumentWriteTime = serverSideMetricsInternal.DocumentWriteTime; } @@ -54,11 +59,11 @@ public ServerSideMetrics( long outputDocumentSize, double indexHitRatio, TimeSpan totalQueryExecutionTime, - QueryPreparationTimes queryPreparationTimes, + TimeSpan queryPreparationTimes, TimeSpan indexLookupTime, TimeSpan documentLoadTime, TimeSpan vmExecutionTime, - RuntimeExecutionTimes runtimeExecutionTimes, + TimeSpan runtimeExecutionTimes, TimeSpan documentWriteTime) { this.RetrievedDocumentCount = retrievedDocumentCount; @@ -67,11 +72,11 @@ public ServerSideMetrics( this.OutputDocumentSize = outputDocumentSize; this.IndexHitRatio = indexHitRatio; this.TotalTime = totalQueryExecutionTime; - this.QueryPreparationTimes = queryPreparationTimes ?? throw new ArgumentNullException($"{nameof(queryPreparationTimes)} can not be null."); + this.QueryPreparationTimes = queryPreparationTimes; this.IndexLookupTime = indexLookupTime; this.DocumentLoadTime = documentLoadTime; this.VMExecutionTime = vmExecutionTime; - this.RuntimeExecutionTimes = runtimeExecutionTimes ?? throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null."); + this.RuntimeExecutionTimes = runtimeExecutionTimes; this.DocumentWriteTime = documentWriteTime; } @@ -101,9 +106,9 @@ public ServerSideMetrics( public long OutputDocumentSize { get; } /// - /// Gets the query QueryPreparationTimes in the Azure Cosmos database service. + /// Gets the query preparation time in the Azure Cosmos database service. /// - public QueryPreparationTimes QueryPreparationTimes { get; } + public TimeSpan QueryPreparationTimes { get; } /// /// Gets the query index lookup time in the Azure Cosmos database service. @@ -116,9 +121,9 @@ public ServerSideMetrics( public TimeSpan DocumentLoadTime { get; } /// - /// Gets the query runtime execution times during query in the Azure Cosmos database service. + /// Gets the query runtime execution time during query in the Azure Cosmos database service. /// - public RuntimeExecutionTimes RuntimeExecutionTimes { get; } + public TimeSpan RuntimeExecutionTimes { get; } /// /// Gets the output writing/serializing time during query in the Azure Cosmos database service. diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs similarity index 84% rename from Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs rename to Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs index 65e56df503..5515c80282 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/PartitionedServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs @@ -9,20 +9,20 @@ namespace Microsoft.Azure.Cosmos /// /// Represents server side metrics specific for a single partition. /// - public sealed class PartitionedServerSideMetrics + public sealed class ServerSidePartitionedMetrics { - internal PartitionedServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) + internal ServerSidePartitionedMetrics(ServerSideMetricsInternal serverSideMetricsInternal) : this(new ServerSideMetrics(serverSideMetricsInternal), serverSideMetricsInternal.FeedRange, serverSideMetricsInternal.PartitionKeyRangeId) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// /// - public PartitionedServerSideMetrics(ServerSideMetrics serverSideMetrics, string feedRange, string partitionKeyRangeId) + public ServerSidePartitionedMetrics(ServerSideMetrics serverSideMetrics, string feedRange, string partitionKeyRangeId) { this.ServerSideMetrics = serverSideMetrics; this.FeedRange = feedRange; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 9001383bf1..bf65115a7a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -389,6 +389,7 @@ public async Task CreateDropItemMultiPartPartitionKeyTest() ItemResponse response = await multiPartPkContainer.CreateItemAsync(item: testItem); Assert.IsNotNull(response); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); + Assert.IsNull(response.Diagnostics.GetQueryMetrics()); ItemResponse readResponse = await multiPartPkContainer.ReadItemAsync(id: testItem.id, partitionKey: new Cosmos.PartitionKey("pk1")); Assert.IsNotNull(readResponse); @@ -617,6 +618,7 @@ public async Task UpsertItemTest() Assert.IsNotNull(response); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsNotNull(response.Headers.Session); + Assert.IsNull(response.Diagnostics.GetQueryMetrics()); } } @@ -707,6 +709,7 @@ await feedIterator.ReadNextAsync(this.cancellationToken)) } } + Assert.IsNull(responseMessage.Diagnostics.GetQueryMetrics()); } } @@ -846,7 +849,7 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() } [TestMethod] - public async Task ItemCustomSerialzierTest() + public async Task ItemCustomSerializerTest() { DateTime createDateTime = DateTime.UtcNow; Dictionary keyValuePairs = new Dictionary() @@ -1283,14 +1286,21 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max System.Diagnostics.Trace.TraceInformation($"ContinuationToken: {lastContinuationToken}"); Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); - // verify ServerSideMetrics matches metrics retrieved from header - ServerSideAccumulatedMetrics metricsFromDiagnostics = response.Diagnostics.GetQueryMetrics(); - bool tryParseResult = ServerSideMetricsInternal.TryParseFromDelimitedString(response.Headers.QueryMetricsText, out ServerSideMetricsInternal metricsFromHeaders); - Assert.IsTrue(tryParseResult); - headerMetricsAccumulator.Accumulate(metricsFromHeaders); - Assert.IsTrue(headerMetricsAccumulator.GetServerSideMetrics().FormatTrace() == SerializeServerSideMetrics(metricsFromDiagnostics.CumulativeServerSideMetrics)); + ServerSideCumulativeMetrics metrics = response.Diagnostics.GetQueryMetrics(); + Assert.IsTrue(metrics.PartitionedMetrics.Count == 1); + Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTimes > TimeSpan.Zero); - Assert.IsTrue(metricsFromDiagnostics.PartitionedServerSideMetrics.Count == 1); //TODO: can we guarantee this? + if (metrics.CumulativeMetrics.RetrievedDocumentCount >= 1) + { + Assert.IsTrue(metrics.CumulativeMetrics.RetrievedDocumentSize > 0); + Assert.IsTrue(metrics.CumulativeMetrics.DocumentLoadTime > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTimes > TimeSpan.Zero); + } + else + { + Assert.AreEqual(0, metrics.CumulativeMetrics.RetrievedDocumentSize); + } using (StreamReader sr = new StreamReader(response.Content)) using (JsonTextReader jtr = new JsonTextReader(sr)) @@ -1359,6 +1369,26 @@ public async Task ItemMultiplePartitionQuery() ToDoActivity response = iter.First(); Assert.AreEqual(find.id, response.id); } + + ServerSideCumulativeMetrics metrics = iter.Diagnostics.GetQueryMetrics(); + + if (metrics != null) + { + Assert.IsTrue(metrics.PartitionedMetrics.Count == 3); + Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTimes > TimeSpan.Zero); + + if (metrics.CumulativeMetrics.RetrievedDocumentCount >= 1) + { + Assert.IsTrue(metrics.CumulativeMetrics.RetrievedDocumentSize > 0); + Assert.IsTrue(metrics.CumulativeMetrics.DocumentLoadTime > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTimes > TimeSpan.Zero); + } + else + { + Assert.AreEqual(0, metrics.CumulativeMetrics.RetrievedDocumentSize); + } + } } Assert.IsTrue(found); @@ -3157,10 +3187,5 @@ private static async Task TestNonePKForNonExistingContainer(Container container) Assert.AreEqual(HttpStatusCode.NotFound, ex.StatusCode); } } - - private static string SerializeServerSideMetrics(ServerSideMetrics serverSideMetrics) - { - return $"totalExecutionTimeInMs={serverSideMetrics.TotalTime.TotalMilliseconds};queryCompileTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryCompilationTime.TotalMilliseconds};queryLogicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.LogicalPlanBuildTime.TotalMilliseconds};queryPhysicalPlanBuildTimeInMs={serverSideMetrics.QueryPreparationTimes.PhysicalPlanBuildTime.TotalMilliseconds};queryOptimizationTimeInMs={serverSideMetrics.QueryPreparationTimes.QueryOptimizationTime.TotalMilliseconds};indexLookupTimeInMs={serverSideMetrics.IndexLookupTime.TotalMilliseconds};documentLoadTimeInMs={serverSideMetrics.DocumentLoadTime.TotalMilliseconds};systemFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.SystemFunctionExecutionTime.TotalMilliseconds};userFunctionExecuteTimeInMs={serverSideMetrics.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime.TotalMilliseconds};retrievedDocumentCount={serverSideMetrics.RetrievedDocumentCount};retrievedDocumentSize={serverSideMetrics.RetrievedDocumentSize};outputDocumentCount={serverSideMetrics.OutputDocumentCount};outputDocumentSize={serverSideMetrics.OutputDocumentSize};writeOutputTimeInMs={serverSideMetrics.DocumentWriteTime.TotalMilliseconds};indexUtilizationRatio={serverSideMetrics.IndexHitRatio}"; - } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index a2c4415301..586b9a121b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -3124,10 +3124,10 @@ "Attributes": [], "MethodInfo": "Int32 GetFailedRequestCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.ServerSideMetrics GetQueryMetrics()": { + "Microsoft.Azure.Cosmos.ServerSideCumulativeMetrics GetQueryMetrics()": { "Type": "Method", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics GetQueryMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideCumulativeMetrics GetQueryMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Collections.Generic.IReadOnlyList`1[System.ValueTuple`2[System.String,System.Uri]] GetContactedRegions()": { "Type": "Method", @@ -6281,60 +6281,6 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.QueryPreparationTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.TimeSpan get_LogicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_PhysicalPlanBuildTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_QueryCompilationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_QueryOptimizationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan LogicalPlanBuildTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan LogicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_LogicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan PhysicalPlanBuildTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan PhysicalPlanBuildTime;CanRead:True;CanWrite:False;System.TimeSpan get_PhysicalPlanBuildTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan QueryCompilationTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryCompilationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryCompilationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan QueryOptimizationTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryOptimizationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryOptimizationTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - } - }, - "NestedTypes": {} - }, "Microsoft.Azure.Cosmos.QueryRequestOptions;Microsoft.Azure.Cosmos.RequestOptions;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { @@ -8146,48 +8092,6 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.RuntimeExecutionTimes;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.TimeSpan get_QueryEngineExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_SystemFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan get_UserDefinedFunctionExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan QueryEngineExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan QueryEngineExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryEngineExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan SystemFunctionExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan SystemFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_SystemFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.TimeSpan UserDefinedFunctionExecutionTime": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.TimeSpan UserDefinedFunctionExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_UserDefinedFunctionExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - } - }, - "NestedTypes": {} - }, "Microsoft.Azure.Cosmos.Scripts.Scripts;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { @@ -9130,6 +9034,41 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.ServerSideCumulativeMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics;CanRead:True;CanWrite:False;System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics])": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics]), Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics])]" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.ServerSideMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { @@ -9193,30 +9132,6 @@ "Attributes": [], "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.QueryPreparationTimes get_QueryPreparationTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Microsoft.Azure.Cosmos.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.QueryPreparationTimes QueryPreparationTimes": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.QueryPreparationTimes QueryPreparationTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.QueryPreparationTimes get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.RuntimeExecutionTimes get_RuntimeExecutionTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Microsoft.Azure.Cosmos.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.RuntimeExecutionTimes RuntimeExecutionTimes": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.RuntimeExecutionTimes RuntimeExecutionTimes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.RuntimeExecutionTimes get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "System.TimeSpan DocumentLoadTime": { "Type": "Property", "Attributes": [], @@ -9248,6 +9163,20 @@ ], "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "System.TimeSpan get_QueryPreparationTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_RuntimeExecutionTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.TimeSpan get_TotalTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -9267,6 +9196,16 @@ "Attributes": [], "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "System.TimeSpan QueryPreparationTimes": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan QueryPreparationTimes;CanRead:True;CanWrite:False;System.TimeSpan get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan RuntimeExecutionTimes": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan RuntimeExecutionTimes;CanRead:True;CanWrite:False;System.TimeSpan get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.TimeSpan TotalTime": { "Type": "Property", "Attributes": [], @@ -9276,6 +9215,58 @@ "Type": "Property", "Attributes": [], "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)]" + } + }, + "NestedTypes": {} + }, + "Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.String FeedRange": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.String FeedRange;CanRead:True;CanWrite:False;System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.String get_FeedRange()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.String get_PartitionKeyRangeId()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.String get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.String PartitionKeyRangeId": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.String PartitionKeyRangeId;CanRead:True;CanWrite:False;System.String get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.String)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.String), Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.String)]" } }, "NestedTypes": {} From 2bb36c8b1a9aad60d6263dd9288e25df2914802e Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 14 Aug 2023 19:36:58 -0700 Subject: [PATCH 33/43] tests and pkrangeid update --- .../Metrics/ServerSideMetricsAccumulator.cs | 15 +++- .../Core/Metrics/ServerSideMetricsInternal.cs | 4 +- .../Metrics/ServerSidePartitionedMetrics.cs | 4 +- .../CosmosItemTests.cs | 89 ++++++++++++++++++- .../Contracts/DotNetSDKAPI.json | 28 +++--- 5 files changed, 117 insertions(+), 23 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index ef7287c050..123c1adcd8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -107,7 +107,7 @@ public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideM return; } - private static string WalkTraceTreeForPartitionKeyRangeId(ITrace currentTrace) + private static int? WalkTraceTreeForPartitionKeyRangeId(ITrace currentTrace) { if (currentTrace == null) { @@ -118,13 +118,22 @@ private static string WalkTraceTreeForPartitionKeyRangeId(ITrace currentTrace) { if (datum is ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum) { - return clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList[0].StoreResult.PartitionKeyRangeId; + if (clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList.Count > 0) + { + return int.TryParse(clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList[0].StoreResult.PartitionKeyRangeId, out int pKRangeId) + ? pKRangeId + : null; + } + else + { + return null; + } } } foreach (ITrace childTrace in currentTrace.Children) { - String partitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(childTrace); + int? partitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(childTrace); if (partitionKeyRangeId != null) { return partitionKeyRangeId; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs index 3d69a5ca93..124f02c3fe 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs @@ -60,7 +60,7 @@ public ServerSideMetricsInternal( RuntimeExecutionTimesInternal runtimeExecutionTimes, TimeSpan documentWriteTime, string feedRange = null, - string partitionKeyRangeId = null) + int? partitionKeyRangeId = null) { this.RetrievedDocumentCount = retrievedDocumentCount; this.RetrievedDocumentSize = retrievedDocumentSize; @@ -146,7 +146,7 @@ public ServerSideMetricsInternal( /// /// Gets the partition key range id for a single backend call. /// - public string PartitionKeyRangeId { get; set; } + public int? PartitionKeyRangeId { get; set; } public static ServerSideMetricsInternal Create(IEnumerable serverSideMetricsEnumerable) { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs index 5515c80282..01fcd32847 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs @@ -22,7 +22,7 @@ internal ServerSidePartitionedMetrics(ServerSideMetricsInternal serverSideMetric /// /// /// - public ServerSidePartitionedMetrics(ServerSideMetrics serverSideMetrics, string feedRange, string partitionKeyRangeId) + public ServerSidePartitionedMetrics(ServerSideMetrics serverSideMetrics, string feedRange, int? partitionKeyRangeId) { this.ServerSideMetrics = serverSideMetrics; this.FeedRange = feedRange; @@ -42,6 +42,6 @@ public ServerSidePartitionedMetrics(ServerSideMetrics serverSideMetrics, string /// /// Gets the partition key range id for the partition. /// - public string PartitionKeyRangeId { get; } + public int? PartitionKeyRangeId { get; } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index bf65115a7a..55e1346b87 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1341,9 +1341,9 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max [TestMethod] public async Task ItemMultiplePartitionQuery() { - IList deleteList = await ToDoActivity.CreateRandomItems(this.Container, 3, randomPartitionKey: true); + IList itemList = await ToDoActivity.CreateRandomItems(this.Container, 3, randomPartitionKey: true); - ToDoActivity find = deleteList.First(); + ToDoActivity find = itemList.First(); QueryDefinition sql = new QueryDefinition("select * from toDoActivity t where t.id = '" + find.id + "'"); QueryRequestOptions requestOptions = new QueryRequestOptions() @@ -1378,6 +1378,91 @@ public async Task ItemMultiplePartitionQuery() Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero); Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTimes > TimeSpan.Zero); + foreach (ServerSidePartitionedMetrics partitionedMetrics in metrics.PartitionedMetrics) + { + Assert.IsNotNull(partitionedMetrics); + Assert.IsNotNull(partitionedMetrics.PartitionKeyRangeId); + } + + if (metrics.CumulativeMetrics.RetrievedDocumentCount >= 1) + { + Assert.IsTrue(metrics.CumulativeMetrics.RetrievedDocumentSize > 0); + Assert.IsTrue(metrics.CumulativeMetrics.DocumentLoadTime > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTimes > TimeSpan.Zero); + } + else + { + Assert.AreEqual(0, metrics.CumulativeMetrics.RetrievedDocumentSize); + } + } + else + { + string diag = iter.Diagnostics.ToString(); + Assert.IsNotNull(diag); + } + } + + Assert.IsTrue(found); + } + + /// + /// Validate single partition query using gateway mode. + /// + [TestMethod] + public async Task ItemSinglePartitionQueryGateway() + { + ContainerResponse containerResponse = await this.database.CreateContainerAsync( + new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: "/pk")); + + Container createdContainer = (ContainerInlineCore)containerResponse; + CosmosClient client1 = TestCommon.CreateCosmosClient(useGateway: true); + + Container container = client1.GetContainer(this.database.Id, createdContainer.Id); + + string findId = "id2002"; + ToDoActivity item = ToDoActivity.CreateRandomToDoActivity("pk2002", findId); + await container.CreateItemAsync(item); + + QueryDefinition sql = new QueryDefinition("select * from toDoActivity t where t.id = '" + findId + "'"); + + QueryRequestOptions requestOptions = new QueryRequestOptions() + { + MaxBufferedItemCount = 10, + ResponseContinuationTokenLimitInKb = 500, + MaxItemCount = 1, + MaxConcurrency = 1, + }; + + FeedIterator feedIterator = container.GetItemQueryIterator( + sql, + requestOptions: requestOptions); + + bool found = false; + while (feedIterator.HasMoreResults) + { + FeedResponse iter = await feedIterator.ReadNextAsync(); + Assert.IsTrue(iter.Count() <= 1); + if (iter.Count() == 1) + { + found = true; + ToDoActivity response = iter.First(); + Assert.AreEqual(findId, response.id); + } + + ServerSideCumulativeMetrics metrics = iter.Diagnostics.GetQueryMetrics(); + + if (metrics != null) + { + Assert.IsTrue(metrics.PartitionedMetrics.Count == 1); + Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTimes > TimeSpan.Zero); + + foreach (ServerSidePartitionedMetrics partitionedMetrics in metrics.PartitionedMetrics) + { + Assert.IsNotNull(partitionedMetrics); + Assert.IsNull(partitionedMetrics.PartitionKeyRangeId); + } + if (metrics.CumulativeMetrics.RetrievedDocumentCount >= 1) { Assert.IsTrue(metrics.CumulativeMetrics.RetrievedDocumentSize > 0); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 586b9a121b..26fe275e49 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -9239,6 +9239,18 @@ "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "System.Nullable`1[System.Int32] get_PartitionKeyRangeId()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.Nullable`1[System.Int32] PartitionKeyRangeId": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.Nullable`1[System.Int32] PartitionKeyRangeId;CanRead:True;CanWrite:False;System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.String FeedRange": { "Type": "Property", "Attributes": [], @@ -9251,22 +9263,10 @@ ], "MethodInfo": "System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.String get_PartitionKeyRangeId()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.String get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.String PartitionKeyRangeId": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.String PartitionKeyRangeId;CanRead:True;CanWrite:False;System.String get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.String)": { + "Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.Nullable`1[System.Int32])": { "Type": "Constructor", "Attributes": [], - "MethodInfo": "[Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.String), Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.String)]" + "MethodInfo": "[Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.Nullable`1[System.Int32]), Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.Nullable`1[System.Int32])]" } }, "NestedTypes": {} From 466be56f4f3686fa83afe96928da130fa74f4ab5 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 15 Aug 2023 14:50:42 -0700 Subject: [PATCH 34/43] PR comments --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 15 +---- .../Metrics/QueryPreparationTimesInternal.cs | 9 ++- .../Metrics/RuntimeExecutionTimesInternal.cs | 9 ++- .../Metrics/ServerSideCumulativeMetrics.cs | 24 ++++--- .../Query/Core/Metrics/ServerSideMetrics.cs | 65 +++++-------------- .../Core/Metrics/ServerSideMetricsInternal.cs | 9 ++- .../Metrics/ServerSidePartitionedMetrics.cs | 17 +++-- 7 files changed, 70 insertions(+), 78 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index da975600e0..a3869784e8 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -35,7 +35,7 @@ public CosmosTraceDiagnostics(ITrace trace) } this.Value = rootTrace; - this.accumulatedMetrics = this.accumulatedMetrics = new Lazy(() => this.GetQueryMetrics()); + this.accumulatedMetrics = new Lazy(() => this.GetQueryMetrics()); } public ITrace Value { get; } @@ -60,17 +60,8 @@ public override ServerSideCumulativeMetrics GetQueryMetrics() ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - List partitionedServerSideMetrics = - accumulator.GetPartitionedServerSideMetrics().Select(metrics => new ServerSidePartitionedMetrics(metrics)).ToList(); - - if (partitionedServerSideMetrics.Count == 0) - { - return null; - } - - ServerSideMetrics serverSideMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); - ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(serverSideMetrics, partitionedServerSideMetrics); - return accumulatedMetrics; + ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(accumulator); + return accumulatedMetrics.PartitionedMetrics.Count != 0 ? accumulatedMetrics : null; } internal bool IsGoneExceptionHit() diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs index de037a9b98..4e8ee38276 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesInternal.cs @@ -8,7 +8,14 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// /// Query preparation metrics in the Azure DocumentDB database service. /// - internal sealed class QueryPreparationTimesInternal +#if INTERNAL +#pragma warning disable SA1600 +#pragma warning disable CS1591 + public +#else + internal +#endif + sealed class QueryPreparationTimesInternal { public static readonly QueryPreparationTimesInternal Zero = new QueryPreparationTimesInternal( queryCompilationTime: TimeSpan.Zero, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs index c92f376262..bbd97ca45d 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesInternal.cs @@ -8,7 +8,14 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// /// Query runtime execution times in the Azure Cosmos DB service. /// - internal sealed class RuntimeExecutionTimesInternal +#if INTERNAL +#pragma warning disable SA1600 +#pragma warning disable CS1591 + public +#else + internal +#endif + sealed class RuntimeExecutionTimesInternal { public static readonly RuntimeExecutionTimesInternal Empty = new RuntimeExecutionTimesInternal( queryEngineExecutionTime: TimeSpan.Zero, diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs index 69e1c80dfa..7d6008851b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs @@ -4,31 +4,39 @@ namespace Microsoft.Azure.Cosmos { using System.Collections.Generic; + using System.Linq; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Metrics received for queries from the backend. /// - public sealed class ServerSideCumulativeMetrics + public class ServerSideCumulativeMetrics { /// /// Initializes a new instance of the class. /// - /// - /// - public ServerSideCumulativeMetrics(ServerSideMetrics cumulativeMetrics, List serverSideMetricsList) + /// + internal ServerSideCumulativeMetrics(ServerSideMetricsAccumulator accumulator) + { + this.PartitionedMetrics = accumulator.GetPartitionedServerSideMetrics().Select(metrics => new ServerSidePartitionedMetrics(metrics)).ToList(); + this.CumulativeMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); + } + + /// + /// Initializes a new instance of the class. + /// + public ServerSideCumulativeMetrics() { - this.CumulativeMetrics = cumulativeMetrics; - this.PartitionedMetrics = serverSideMetricsList; } /// /// Gets the ServerSideMetrics accumulated for a single round trip. /// - public ServerSideMetrics CumulativeMetrics { get; } + public virtual ServerSideMetrics CumulativeMetrics { get; } /// /// Gets the list of ServerSideMetrics, one for for each partition. /// - public List PartitionedMetrics { get; } + public virtual IReadOnlyList PartitionedMetrics { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 35bf61cada..88a7009873 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -5,12 +5,13 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.Collections.Generic; using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Metrics received for queries from the backend. /// - public sealed class ServerSideMetrics + public class ServerSideMetrics { /// /// Initializes a new instance of the class. @@ -40,104 +41,68 @@ internal ServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) /// /// Initializes a new instance of the class. /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public ServerSideMetrics( - long retrievedDocumentCount, - long retrievedDocumentSize, - long outputDocumentCount, - long outputDocumentSize, - double indexHitRatio, - TimeSpan totalQueryExecutionTime, - TimeSpan queryPreparationTimes, - TimeSpan indexLookupTime, - TimeSpan documentLoadTime, - TimeSpan vmExecutionTime, - TimeSpan runtimeExecutionTimes, - TimeSpan documentWriteTime) + public ServerSideMetrics() { - this.RetrievedDocumentCount = retrievedDocumentCount; - this.RetrievedDocumentSize = retrievedDocumentSize; - this.OutputDocumentCount = outputDocumentCount; - this.OutputDocumentSize = outputDocumentSize; - this.IndexHitRatio = indexHitRatio; - this.TotalTime = totalQueryExecutionTime; - this.QueryPreparationTimes = queryPreparationTimes; - this.IndexLookupTime = indexLookupTime; - this.DocumentLoadTime = documentLoadTime; - this.VMExecutionTime = vmExecutionTime; - this.RuntimeExecutionTimes = runtimeExecutionTimes; - this.DocumentWriteTime = documentWriteTime; } /// /// Gets the total query time in the Azure Cosmos database service. /// - public TimeSpan TotalTime { get; } + public virtual TimeSpan TotalTime { get; } /// /// Gets the number of documents retrieved during query in the Azure Cosmos database service. /// - public long RetrievedDocumentCount { get; } + public virtual long RetrievedDocumentCount { get; } /// /// Gets the size of documents retrieved in bytes during query in the Azure Cosmos DB service. /// - public long RetrievedDocumentSize { get; } + public virtual long RetrievedDocumentSize { get; } /// /// Gets the number of documents returned by query in the Azure Cosmos DB service. /// - public long OutputDocumentCount { get; } + public virtual long OutputDocumentCount { get; } /// /// Gets the size of documents outputted in bytes during query in the Azure Cosmos database service. /// - public long OutputDocumentSize { get; } + public virtual long OutputDocumentSize { get; } /// /// Gets the query preparation time in the Azure Cosmos database service. /// - public TimeSpan QueryPreparationTimes { get; } + public virtual TimeSpan QueryPreparationTimes { get; } /// /// Gets the query index lookup time in the Azure Cosmos database service. /// - public TimeSpan IndexLookupTime { get; } + public virtual TimeSpan IndexLookupTime { get; } /// /// Gets the document loading time during query in the Azure Cosmos database service. /// - public TimeSpan DocumentLoadTime { get; } + public virtual TimeSpan DocumentLoadTime { get; } /// /// Gets the query runtime execution time during query in the Azure Cosmos database service. /// - public TimeSpan RuntimeExecutionTimes { get; } + public virtual TimeSpan RuntimeExecutionTimes { get; } /// /// Gets the output writing/serializing time during query in the Azure Cosmos database service. /// - public TimeSpan DocumentWriteTime { get; } + public virtual TimeSpan DocumentWriteTime { get; } /// /// Gets the index hit ratio by query in the Azure Cosmos database service. /// - public double IndexHitRatio { get; } + public virtual double IndexHitRatio { get; } /// /// Gets the VMExecution Time. /// - public TimeSpan VMExecutionTime { get; } + public virtual TimeSpan VMExecutionTime { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs index 124f02c3fe..309311d461 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs @@ -10,7 +10,14 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics /// /// internal implementation of metrics received for queries from the backend. /// - internal sealed class ServerSideMetricsInternal +#if INTERNAL +#pragma warning disable SA1600 +#pragma warning disable CS1591 + public +#else + internal +#endif + sealed class ServerSideMetricsInternal { /// /// QueryMetrics with all members having default (but not null) members. diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs index 01fcd32847..8c23970b51 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs @@ -9,7 +9,7 @@ namespace Microsoft.Azure.Cosmos /// /// Represents server side metrics specific for a single partition. /// - public sealed class ServerSidePartitionedMetrics + public class ServerSidePartitionedMetrics { internal ServerSidePartitionedMetrics(ServerSideMetricsInternal serverSideMetricsInternal) : this(new ServerSideMetrics(serverSideMetricsInternal), serverSideMetricsInternal.FeedRange, serverSideMetricsInternal.PartitionKeyRangeId) @@ -22,26 +22,33 @@ internal ServerSidePartitionedMetrics(ServerSideMetricsInternal serverSideMetric /// /// /// - public ServerSidePartitionedMetrics(ServerSideMetrics serverSideMetrics, string feedRange, int? partitionKeyRangeId) + internal ServerSidePartitionedMetrics(ServerSideMetrics serverSideMetrics, string feedRange, int? partitionKeyRangeId) { this.ServerSideMetrics = serverSideMetrics; this.FeedRange = feedRange; this.PartitionKeyRangeId = partitionKeyRangeId; } + /// + /// Initializes a new instance of the class. + /// + public ServerSidePartitionedMetrics() + { + } + /// /// Gets the backend metrics for the request. /// - public ServerSideMetrics ServerSideMetrics { get; } + public virtual ServerSideMetrics ServerSideMetrics { get; } /// /// Gets the FeedRange for the partition. /// - public string FeedRange { get; } + public virtual string FeedRange { get; } /// /// Gets the partition key range id for the partition. /// - public int? PartitionKeyRangeId { get; } + public virtual int? PartitionKeyRangeId { get; } } } From 6abd122ee743119645a64dd1d6330cbd7cbc3c91 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 15 Aug 2023 17:15:02 -0700 Subject: [PATCH 35/43] more PR comments --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 20 ++++++++++--------- .../Query/Core/Metrics/ServerSideMetrics.cs | 1 - 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index a3869784e8..e7803e1a48 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -6,7 +6,6 @@ namespace Microsoft.Azure.Cosmos.Diagnostics { using System; using System.Collections.Generic; - using System.Linq; using System.Text; using Microsoft.Azure.Cosmos.Json; using Microsoft.Azure.Cosmos.Query.Core.Metrics; @@ -18,8 +17,6 @@ internal sealed class CosmosTraceDiagnostics : CosmosDiagnostics { private readonly Lazy accumulatedMetrics; - public ServerSideCumulativeMetrics AccumulatedMetrics => this.accumulatedMetrics.Value; - public CosmosTraceDiagnostics(ITrace trace) { if (trace == null) @@ -35,7 +32,7 @@ public CosmosTraceDiagnostics(ITrace trace) } this.Value = rootTrace; - this.accumulatedMetrics = new Lazy(() => this.GetQueryMetrics()); + this.accumulatedMetrics = new Lazy(() => PopulateServerSideCumulativeMetrics(this.Value)); } public ITrace Value { get; } @@ -57,11 +54,7 @@ public override TimeSpan GetClientElapsedTime() public override ServerSideCumulativeMetrics GetQueryMetrics() { - ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); - ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(this.Value, accumulator); - - ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(accumulator); - return accumulatedMetrics.PartitionedMetrics.Count != 0 ? accumulatedMetrics : null; + return this.accumulatedMetrics.Value; } internal bool IsGoneExceptionHit() @@ -114,6 +107,15 @@ private ReadOnlyMemory WriteTraceToJsonWriter(JsonSerializationFormat json return jsonTextWriter.GetResult(); } + private static ServerSideCumulativeMetrics PopulateServerSideCumulativeMetrics(ITrace trace) + { + ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); + ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(trace, accumulator); + + ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(accumulator); + return accumulatedMetrics.PartitionedMetrics.Count != 0 ? accumulatedMetrics : null; + } + public override DateTime? GetStartTimeUtc() { if (this.Value == null || this.Value.StartTime == null) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 88a7009873..10a2707a7c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -5,7 +5,6 @@ namespace Microsoft.Azure.Cosmos { using System; - using System.Collections.Generic; using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// From 0b4fcbaa98021a398b6440ca7a5ab2fe56d526ee Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 15 Aug 2023 18:22:48 -0700 Subject: [PATCH 36/43] smol test fix --- .../Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 55e1346b87..156f94bc6f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1268,7 +1268,6 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max do { iterationCount++; - ServerSideMetricsAccumulator headerMetricsAccumulator = new ServerSideMetricsAccumulator(); FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator( sql, continuationToken: lastContinuationToken, From eca129225521e9f8c002022ff02ef205739b4663 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 16 Aug 2023 09:42:01 -0700 Subject: [PATCH 37/43] PR comments - renaming properties and constructor rehash --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 9 +- .../Core/Metrics/QueryMetricsAccumulator.cs | 2 +- .../Metrics/ServerSideCumulativeMetrics.cs | 9 +- .../Query/Core/Metrics/ServerSideMetrics.cs | 63 +++++++- .../Metrics/ServerSideMetricsAccumulator.cs | 93 ++--------- .../Core/Metrics/ServerSideMetricsInternal.cs | 2 +- .../ServerSideMetricsInternalAccumulator.cs | 146 ++++++++++++++++++ .../CosmosItemTests.cs | 12 +- .../Query/Metrics/ServerSideMetricsTests.cs | 2 +- 9 files changed, 236 insertions(+), 102 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index e7803e1a48..d2a39e85ce 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos.Diagnostics { using System; using System.Collections.Generic; + using System.Linq; using System.Text; using Microsoft.Azure.Cosmos.Json; using Microsoft.Azure.Cosmos.Query.Core.Metrics; @@ -109,10 +110,12 @@ private ReadOnlyMemory WriteTraceToJsonWriter(JsonSerializationFormat json private static ServerSideCumulativeMetrics PopulateServerSideCumulativeMetrics(ITrace trace) { - ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); - ServerSideMetricsAccumulator.WalkTraceTreeForQueryMetrics(trace, accumulator); + ServerSideMetricsInternalAccumulator accumulator = new ServerSideMetricsInternalAccumulator(); + ServerSideMetricsInternalAccumulator.WalkTraceTreeForQueryMetrics(trace, accumulator); - ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(accumulator); + IReadOnlyList serverSideMetricsList = accumulator.GetPartitionedServerSideMetrics().Select(metrics => new ServerSidePartitionedMetrics(metrics)).ToList(); + + ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(serverSideMetricsList); return accumulatedMetrics.PartitionedMetrics.Count != 0 ? accumulatedMetrics : null; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs index ecfe6b92a6..db566515a8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs @@ -28,7 +28,7 @@ public void Accumulate(QueryMetrics queryMetrics) public QueryMetrics GetQueryMetrics() { - ServerSideMetricsAccumulator serverSideMetricsAccumulator = new ServerSideMetricsAccumulator(); + ServerSideMetricsInternalAccumulator serverSideMetricsAccumulator = new ServerSideMetricsInternalAccumulator(); IndexUtilizationInfoAccumulator indexUtilizationInfoAccumulator = new IndexUtilizationInfoAccumulator(); ClientSideMetricsAccumulator clientSideMetricsAccumulator = new ClientSideMetricsAccumulator(); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs index 7d6008851b..34826f9e7f 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs @@ -5,7 +5,6 @@ namespace Microsoft.Azure.Cosmos { using System.Collections.Generic; using System.Linq; - using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Metrics received for queries from the backend. @@ -15,11 +14,11 @@ public class ServerSideCumulativeMetrics /// /// Initializes a new instance of the class. /// - /// - internal ServerSideCumulativeMetrics(ServerSideMetricsAccumulator accumulator) + /// + internal ServerSideCumulativeMetrics(IEnumerable serverSideMetricsList) { - this.PartitionedMetrics = accumulator.GetPartitionedServerSideMetrics().Select(metrics => new ServerSidePartitionedMetrics(metrics)).ToList(); - this.CumulativeMetrics = new ServerSideMetrics(accumulator.GetServerSideMetrics()); + this.PartitionedMetrics = serverSideMetricsList.ToList(); + this.CumulativeMetrics = ServerSideMetrics.Create(serverSideMetricsList.Select(partitionedMetrics => partitionedMetrics.ServerSideMetrics)); } /// diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 10a2707a7c..22c61f34c4 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -5,6 +5,7 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.Collections.Generic; using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// @@ -24,19 +25,62 @@ internal ServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) this.OutputDocumentSize = serverSideMetricsInternal.OutputDocumentSize; this.IndexHitRatio = serverSideMetricsInternal.IndexHitRatio; this.TotalTime = serverSideMetricsInternal.TotalTime; - this.QueryPreparationTimes = serverSideMetricsInternal.QueryPreparationTimes.LogicalPlanBuildTime + this.QueryPreparationTime = serverSideMetricsInternal.QueryPreparationTimes.LogicalPlanBuildTime + serverSideMetricsInternal.QueryPreparationTimes.PhysicalPlanBuildTime + serverSideMetricsInternal.QueryPreparationTimes.QueryCompilationTime + serverSideMetricsInternal.QueryPreparationTimes.QueryOptimizationTime; this.IndexLookupTime = serverSideMetricsInternal.IndexLookupTime; this.DocumentLoadTime = serverSideMetricsInternal.DocumentLoadTime; this.VMExecutionTime = serverSideMetricsInternal.VMExecutionTime; - this.RuntimeExecutionTimes = serverSideMetricsInternal.RuntimeExecutionTimes.QueryEngineExecutionTime + this.RuntimeExecutionTime = serverSideMetricsInternal.RuntimeExecutionTimes.QueryEngineExecutionTime + serverSideMetricsInternal.RuntimeExecutionTimes.SystemFunctionExecutionTime + serverSideMetricsInternal.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime; this.DocumentWriteTime = serverSideMetricsInternal.DocumentWriteTime; } + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + internal ServerSideMetrics( + long retrievedDocumentCount, + long retrievedDocumentSize, + long outputDocumentCount, + long outputDocumentSize, + double indexHitRatio, + TimeSpan totalQueryExecutionTime, + TimeSpan queryPreparationTimes, + TimeSpan indexLookupTime, + TimeSpan documentLoadTime, + TimeSpan vmExecutionTime, + TimeSpan runtimeExecutionTimes, + TimeSpan documentWriteTime) + { + this.RetrievedDocumentCount = retrievedDocumentCount; + this.RetrievedDocumentSize = retrievedDocumentSize; + this.OutputDocumentCount = outputDocumentCount; + this.OutputDocumentSize = outputDocumentSize; + this.IndexHitRatio = indexHitRatio; + this.TotalTime = totalQueryExecutionTime; + this.QueryPreparationTime = queryPreparationTimes; + this.IndexLookupTime = indexLookupTime; + this.DocumentLoadTime = documentLoadTime; + this.VMExecutionTime = vmExecutionTime; + this.RuntimeExecutionTime = runtimeExecutionTimes; + this.DocumentWriteTime = documentWriteTime; + } + /// /// Initializes a new instance of the class. /// @@ -72,7 +116,7 @@ public ServerSideMetrics() /// /// Gets the query preparation time in the Azure Cosmos database service. /// - public virtual TimeSpan QueryPreparationTimes { get; } + public virtual TimeSpan QueryPreparationTime { get; } /// /// Gets the query index lookup time in the Azure Cosmos database service. @@ -87,7 +131,7 @@ public ServerSideMetrics() /// /// Gets the query runtime execution time during query in the Azure Cosmos database service. /// - public virtual TimeSpan RuntimeExecutionTimes { get; } + public virtual TimeSpan RuntimeExecutionTime { get; } /// /// Gets the output writing/serializing time during query in the Azure Cosmos database service. @@ -103,5 +147,16 @@ public ServerSideMetrics() /// Gets the VMExecution Time. /// public virtual TimeSpan VMExecutionTime { get; } + + internal static ServerSideMetrics Create(IEnumerable serverSideMetricsEnumerable) + { + ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); + foreach (ServerSideMetrics serverSideMetrics in serverSideMetricsEnumerable) + { + accumulator.Accumulate(serverSideMetrics); + } + + return accumulator.GetServerSideMetrics(); + } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index 123c1adcd8..6daf56c622 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -6,19 +6,17 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; using System.Collections.Generic; - using Microsoft.Azure.Cosmos.Tracing; - using Microsoft.Azure.Cosmos.Tracing.TraceData; internal class ServerSideMetricsAccumulator { - internal readonly List serverSideMetricsList; + internal readonly List serverSideMetricsList; public ServerSideMetricsAccumulator() { - this.serverSideMetricsList = new List(); + this.serverSideMetricsList = new List(); } - public void Accumulate(ServerSideMetricsInternal serverSideMetrics) + public void Accumulate(ServerSideMetrics serverSideMetrics) { if (serverSideMetrics == null) { @@ -28,7 +26,7 @@ public void Accumulate(ServerSideMetricsInternal serverSideMetrics) this.serverSideMetricsList.Add(serverSideMetrics); } - public ServerSideMetricsInternal GetServerSideMetrics() + public ServerSideMetrics GetServerSideMetrics() { TimeSpan totalTime = TimeSpan.Zero; long retrievedDocumentCount = 0; @@ -36,14 +34,14 @@ public ServerSideMetricsInternal GetServerSideMetrics() long outputDocumentCount = 0; long outputDocumentSize = 0; double indexHitRatio = 0; - QueryPreparationTimesAccumulator queryPreparationTimesAccumulator = new QueryPreparationTimesAccumulator(); + TimeSpan queryPreparationTime = TimeSpan.Zero; TimeSpan indexLookupTime = TimeSpan.Zero; TimeSpan documentLoadTime = TimeSpan.Zero; - RuntimeExecutionTimesAccumulator runtimeExecutionTimesAccumulator = new RuntimeExecutionTimesAccumulator(); + TimeSpan runtimeExecutionTime = TimeSpan.Zero; TimeSpan documentWriteTime = TimeSpan.Zero; TimeSpan vMExecutionTime = TimeSpan.Zero; - foreach (ServerSideMetricsInternal serverSideMetrics in this.serverSideMetricsList) + foreach (ServerSideMetrics serverSideMetrics in this.serverSideMetricsList) { indexHitRatio = (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) != 0 ? ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : @@ -53,94 +51,27 @@ public ServerSideMetricsInternal GetServerSideMetrics() retrievedDocumentSize += serverSideMetrics.RetrievedDocumentSize; outputDocumentCount += serverSideMetrics.OutputDocumentCount; outputDocumentSize += serverSideMetrics.OutputDocumentSize; - queryPreparationTimesAccumulator.Accumulate(serverSideMetrics.QueryPreparationTimes); + queryPreparationTime += serverSideMetrics.QueryPreparationTime; indexLookupTime += serverSideMetrics.IndexLookupTime; documentLoadTime += serverSideMetrics.DocumentLoadTime; - runtimeExecutionTimesAccumulator.Accumulate(serverSideMetrics.RuntimeExecutionTimes); + runtimeExecutionTime += serverSideMetrics.RuntimeExecutionTime; documentWriteTime += serverSideMetrics.DocumentWriteTime; vMExecutionTime += serverSideMetrics.VMExecutionTime; } - return new ServerSideMetricsInternal( + return new ServerSideMetrics( retrievedDocumentCount: retrievedDocumentCount, retrievedDocumentSize: retrievedDocumentSize, outputDocumentCount: outputDocumentCount, outputDocumentSize: outputDocumentSize, indexHitRatio: indexHitRatio, totalQueryExecutionTime: totalTime, - queryPreparationTimes: queryPreparationTimesAccumulator.GetQueryPreparationTimes(), + queryPreparationTimes: queryPreparationTime, indexLookupTime: indexLookupTime, documentLoadTime: documentLoadTime, vmExecutionTime: vMExecutionTime, - runtimeExecutionTimes: runtimeExecutionTimesAccumulator.GetRuntimeExecutionTimes(), + runtimeExecutionTimes: runtimeExecutionTime, documentWriteTime: documentWriteTime); } - - public List GetPartitionedServerSideMetrics() - { - return this.serverSideMetricsList; - } - - public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideMetricsAccumulator accumulator) - { - if (currentTrace == null) - { - return; - } - - foreach (object datum in currentTrace.Data.Values) - { - if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) - { - queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.FeedRange = currentTrace.Name; - queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.PartitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(currentTrace); - accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics); - return; - } - } - - foreach (ITrace childTrace in currentTrace.Children) - { - WalkTraceTreeForQueryMetrics(childTrace, accumulator); - } - - return; - } - - private static int? WalkTraceTreeForPartitionKeyRangeId(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 int.TryParse(clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList[0].StoreResult.PartitionKeyRangeId, out int pKRangeId) - ? pKRangeId - : null; - } - else - { - return null; - } - } - } - - foreach (ITrace childTrace in currentTrace.Children) - { - int? partitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(childTrace); - if (partitionKeyRangeId != null) - { - return partitionKeyRangeId; - } - } - - return null; - } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs index 309311d461..d3e8e52a01 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs @@ -157,7 +157,7 @@ public ServerSideMetricsInternal( public static ServerSideMetricsInternal Create(IEnumerable serverSideMetricsEnumerable) { - ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); + ServerSideMetricsInternalAccumulator accumulator = new ServerSideMetricsInternalAccumulator(); foreach (ServerSideMetricsInternal serverSideMetrics in serverSideMetricsEnumerable) { accumulator.Accumulate(serverSideMetrics); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs new file mode 100644 index 0000000000..70b007a0c8 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs @@ -0,0 +1,146 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos.Query.Core.Metrics +{ + using System; + using System.Collections.Generic; + using Microsoft.Azure.Cosmos.Tracing; + using Microsoft.Azure.Cosmos.Tracing.TraceData; + + internal class ServerSideMetricsInternalAccumulator + { + internal readonly List serverSideMetricsList; + + public ServerSideMetricsInternalAccumulator() + { + this.serverSideMetricsList = new List(); + } + + public void Accumulate(ServerSideMetricsInternal serverSideMetrics) + { + if (serverSideMetrics == null) + { + throw new ArgumentNullException(nameof(serverSideMetrics)); + } + + this.serverSideMetricsList.Add(serverSideMetrics); + } + + public ServerSideMetricsInternal GetServerSideMetrics() + { + TimeSpan totalTime = TimeSpan.Zero; + long retrievedDocumentCount = 0; + long retrievedDocumentSize = 0; + long outputDocumentCount = 0; + long outputDocumentSize = 0; + double indexHitRatio = 0; + QueryPreparationTimesAccumulator queryPreparationTimesAccumulator = new QueryPreparationTimesAccumulator(); + TimeSpan indexLookupTime = TimeSpan.Zero; + TimeSpan documentLoadTime = TimeSpan.Zero; + RuntimeExecutionTimesAccumulator runtimeExecutionTimesAccumulator = new RuntimeExecutionTimesAccumulator(); + TimeSpan documentWriteTime = TimeSpan.Zero; + TimeSpan vMExecutionTime = TimeSpan.Zero; + + foreach (ServerSideMetricsInternal serverSideMetrics in this.serverSideMetricsList) + { + indexHitRatio = (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) != 0 ? + ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : + 0; + totalTime += serverSideMetrics.TotalTime; + retrievedDocumentCount += serverSideMetrics.RetrievedDocumentCount; + retrievedDocumentSize += serverSideMetrics.RetrievedDocumentSize; + outputDocumentCount += serverSideMetrics.OutputDocumentCount; + outputDocumentSize += serverSideMetrics.OutputDocumentSize; + queryPreparationTimesAccumulator.Accumulate(serverSideMetrics.QueryPreparationTimes); + indexLookupTime += serverSideMetrics.IndexLookupTime; + documentLoadTime += serverSideMetrics.DocumentLoadTime; + runtimeExecutionTimesAccumulator.Accumulate(serverSideMetrics.RuntimeExecutionTimes); + documentWriteTime += serverSideMetrics.DocumentWriteTime; + vMExecutionTime += serverSideMetrics.VMExecutionTime; + } + + return new ServerSideMetricsInternal( + retrievedDocumentCount: retrievedDocumentCount, + retrievedDocumentSize: retrievedDocumentSize, + outputDocumentCount: outputDocumentCount, + outputDocumentSize: outputDocumentSize, + indexHitRatio: indexHitRatio, + totalQueryExecutionTime: totalTime, + queryPreparationTimes: queryPreparationTimesAccumulator.GetQueryPreparationTimes(), + indexLookupTime: indexLookupTime, + documentLoadTime: documentLoadTime, + vmExecutionTime: vMExecutionTime, + runtimeExecutionTimes: runtimeExecutionTimesAccumulator.GetRuntimeExecutionTimes(), + documentWriteTime: documentWriteTime); + } + + public List GetPartitionedServerSideMetrics() + { + return this.serverSideMetricsList; + } + + public static void WalkTraceTreeForQueryMetrics(ITrace currentTrace, ServerSideMetricsInternalAccumulator accumulator) + { + if (currentTrace == null) + { + return; + } + + foreach (object datum in currentTrace.Data.Values) + { + if (datum is QueryMetricsTraceDatum queryMetricsTraceDatum) + { + queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.FeedRange = currentTrace.Name; + queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics.PartitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(currentTrace); + accumulator.Accumulate(queryMetricsTraceDatum.QueryMetrics.ServerSideMetrics); + return; + } + } + + foreach (ITrace childTrace in currentTrace.Children) + { + WalkTraceTreeForQueryMetrics(childTrace, accumulator); + } + + return; + } + + private static int? WalkTraceTreeForPartitionKeyRangeId(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 int.TryParse(clientSideRequestStatisticsTraceDatum.StoreResponseStatisticsList[0].StoreResult.PartitionKeyRangeId, out int pKRangeId) + ? pKRangeId + : null; + } + else + { + return null; + } + } + } + + foreach (ITrace childTrace in currentTrace.Children) + { + int? partitionKeyRangeId = WalkTraceTreeForPartitionKeyRangeId(childTrace); + if (partitionKeyRangeId != null) + { + return partitionKeyRangeId; + } + } + + return null; + } + } +} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 156f94bc6f..dd09fde938 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1288,13 +1288,13 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max ServerSideCumulativeMetrics metrics = response.Diagnostics.GetQueryMetrics(); Assert.IsTrue(metrics.PartitionedMetrics.Count == 1); Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero); - Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTimes > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTime > TimeSpan.Zero); if (metrics.CumulativeMetrics.RetrievedDocumentCount >= 1) { Assert.IsTrue(metrics.CumulativeMetrics.RetrievedDocumentSize > 0); Assert.IsTrue(metrics.CumulativeMetrics.DocumentLoadTime > TimeSpan.Zero); - Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTimes > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTime > TimeSpan.Zero); } else { @@ -1375,7 +1375,7 @@ public async Task ItemMultiplePartitionQuery() { Assert.IsTrue(metrics.PartitionedMetrics.Count == 3); Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero); - Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTimes > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTime > TimeSpan.Zero); foreach (ServerSidePartitionedMetrics partitionedMetrics in metrics.PartitionedMetrics) { @@ -1387,7 +1387,7 @@ public async Task ItemMultiplePartitionQuery() { Assert.IsTrue(metrics.CumulativeMetrics.RetrievedDocumentSize > 0); Assert.IsTrue(metrics.CumulativeMetrics.DocumentLoadTime > TimeSpan.Zero); - Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTimes > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTime > TimeSpan.Zero); } else { @@ -1454,7 +1454,7 @@ public async Task ItemSinglePartitionQueryGateway() { Assert.IsTrue(metrics.PartitionedMetrics.Count == 1); Assert.IsTrue(metrics.CumulativeMetrics.TotalTime > TimeSpan.Zero); - Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTimes > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.QueryPreparationTime > TimeSpan.Zero); foreach (ServerSidePartitionedMetrics partitionedMetrics in metrics.PartitionedMetrics) { @@ -1466,7 +1466,7 @@ public async Task ItemSinglePartitionQueryGateway() { Assert.IsTrue(metrics.CumulativeMetrics.RetrievedDocumentSize > 0); Assert.IsTrue(metrics.CumulativeMetrics.DocumentLoadTime > TimeSpan.Zero); - Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTimes > TimeSpan.Zero); + Assert.IsTrue(metrics.CumulativeMetrics.RuntimeExecutionTime > TimeSpan.Zero); } else { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs index 8a827c130e..4c6e382ebf 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Metrics/ServerSideMetricsTests.cs @@ -163,7 +163,7 @@ public void TestParseStringWithUnknownField() [TestMethod] public void TestAccumulator() { - ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); + ServerSideMetricsInternalAccumulator accumulator = new ServerSideMetricsInternalAccumulator(); accumulator.Accumulate(ServerSideMetrics); accumulator.Accumulate(ServerSideMetrics); ServerSideMetricsInternal serverSideMetricsFromAddition = accumulator.GetServerSideMetrics(); From f19bafc99df0b098a93f7a09a0adb9239934d432 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 16 Aug 2023 11:30:25 -0700 Subject: [PATCH 38/43] contract update --- .../Contracts/DotNetSDKAPI.json | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 26fe275e49..d1f26fe878 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -9034,42 +9034,42 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.ServerSideCumulativeMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.ServerSideCumulativeMetrics;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics": { "Type": "Property", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics": { + "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics;CanRead:True;CanWrite:False;System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics;CanRead:True;CanWrite:False;System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics])": { + "Void .ctor()": { "Type": "Constructor", "Attributes": [], - "MethodInfo": "[Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics]), Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.Collections.Generic.List`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics])]" + "MethodInfo": "[Void .ctor(), Void .ctor()]" } }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.ServerSideMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.ServerSideMetrics;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { "Double get_IndexHitRatio()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { @@ -9077,154 +9077,154 @@ "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Double IndexHitRatio": { "Type": "Property", "Attributes": [], - "MethodInfo": "Double IndexHitRatio;CanRead:True;CanWrite:False;Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Double IndexHitRatio;CanRead:True;CanWrite:False;Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 get_OutputDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 get_OutputDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 get_RetrievedDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 get_RetrievedDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 OutputDocumentCount": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 OutputDocumentCount;CanRead:True;CanWrite:False;Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 OutputDocumentCount;CanRead:True;CanWrite:False;Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 OutputDocumentSize": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 OutputDocumentSize;CanRead:True;CanWrite:False;Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 OutputDocumentSize;CanRead:True;CanWrite:False;Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 RetrievedDocumentCount": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 RetrievedDocumentCount;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 RetrievedDocumentCount;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 RetrievedDocumentSize": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan DocumentLoadTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan DocumentLoadTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan DocumentLoadTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan DocumentWriteTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan DocumentWriteTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan DocumentWriteTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_DocumentLoadTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_DocumentWriteTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_IndexLookupTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_QueryPreparationTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_QueryPreparationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_QueryPreparationTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_RuntimeExecutionTimes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_RuntimeExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_RuntimeExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_TotalTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_VMExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan IndexLookupTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan QueryPreparationTimes": { + "System.TimeSpan QueryPreparationTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan QueryPreparationTimes;CanRead:True;CanWrite:False;System.TimeSpan get_QueryPreparationTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan QueryPreparationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryPreparationTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan RuntimeExecutionTimes": { + "System.TimeSpan RuntimeExecutionTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan RuntimeExecutionTimes;CanRead:True;CanWrite:False;System.TimeSpan get_RuntimeExecutionTimes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan RuntimeExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_RuntimeExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan TotalTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan TotalTime;CanRead:True;CanWrite:False;System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan TotalTime;CanRead:True;CanWrite:False;System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan VMExecutionTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)": { + "Void .ctor()": { "Type": "Constructor", "Attributes": [], - "MethodInfo": "[Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan), Void .ctor(Int64, Int64, Int64, Int64, Double, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan, System.TimeSpan)]" + "MethodInfo": "[Void .ctor(), Void .ctor()]" } }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { @@ -9232,41 +9232,41 @@ "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics": { "Type": "Property", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Nullable`1[System.Int32] get_PartitionKeyRangeId()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Nullable`1[System.Int32] PartitionKeyRangeId": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.Nullable`1[System.Int32] PartitionKeyRangeId;CanRead:True;CanWrite:False;System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Nullable`1[System.Int32] PartitionKeyRangeId;CanRead:True;CanWrite:False;System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.String FeedRange": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.String FeedRange;CanRead:True;CanWrite:False;System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.String FeedRange;CanRead:True;CanWrite:False;System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.String get_FeedRange()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.Nullable`1[System.Int32])": { + "Void .ctor()": { "Type": "Constructor", "Attributes": [], - "MethodInfo": "[Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.Nullable`1[System.Int32]), Void .ctor(Microsoft.Azure.Cosmos.ServerSideMetrics, System.String, System.Nullable`1[System.Int32])]" + "MethodInfo": "[Void .ctor(), Void .ctor()]" } }, "NestedTypes": {} From e08aff71efbc3a8205e90503dea0d57baa636403 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 23 Aug 2023 13:02:59 -0700 Subject: [PATCH 39/43] seal classes and private fields. --- .../src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs | 3 +-- .../src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs | 3 +-- .../src/Query/Core/Metrics/QueryMetricsAccumulator.cs | 2 +- .../Query/Core/Metrics/QueryPreparationTimesAccumulator.cs | 2 +- .../Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs | 2 +- .../src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs | 4 ++-- .../Core/Metrics/ServerSideMetricsInternalAccumulator.cs | 4 ++-- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs index f0e43b61dc..57816580b6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ClientSideMetricsAccumulator.cs @@ -5,9 +5,8 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; using System.Collections.Generic; - using System.Linq; - internal class ClientSideMetricsAccumulator + internal sealed class ClientSideMetricsAccumulator { private readonly List clientSideMetricsList; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs index 89a1e193db..978abba77a 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfoAccumulator.cs @@ -6,9 +6,8 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System; using System.Collections.Generic; - using System.Linq; - internal class IndexUtilizationInfoAccumulator + internal sealed class IndexUtilizationInfoAccumulator { private readonly List indexUtilizationInfoList; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs index db566515a8..b6b817e95d 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryMetricsAccumulator.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System; using System.Collections.Generic; - internal class QueryMetricsAccumulator + internal sealed class QueryMetricsAccumulator { private readonly List queryMetricsList; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs index 13c2827cc0..6b79e8c1f8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/QueryPreparationTimesAccumulator.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System; using System.Collections.Generic; - internal class QueryPreparationTimesAccumulator + internal sealed class QueryPreparationTimesAccumulator { private readonly List queryPreparationTimesList; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs index 7bdedc7af8..60f5e37573 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/RuntimeExecutionTimesAccumulator.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System; using System.Collections.Generic; - internal class RuntimeExecutionTimesAccumulator + internal sealed class RuntimeExecutionTimesAccumulator { private readonly List runtimeExecutionTimesList; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index 6daf56c622..6f415a2084 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -7,9 +7,9 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System; using System.Collections.Generic; - internal class ServerSideMetricsAccumulator + internal sealed class ServerSideMetricsAccumulator { - internal readonly List serverSideMetricsList; + private readonly List serverSideMetricsList; public ServerSideMetricsAccumulator() { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs index 70b007a0c8..e2683c8554 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs @@ -9,9 +9,9 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using Microsoft.Azure.Cosmos.Tracing; using Microsoft.Azure.Cosmos.Tracing.TraceData; - internal class ServerSideMetricsInternalAccumulator + internal sealed class ServerSideMetricsInternalAccumulator { - internal readonly List serverSideMetricsList; + private readonly List serverSideMetricsList; public ServerSideMetricsInternalAccumulator() { From 2f0cf75c8b724e6033c92768b6e144cb0d090ecf Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 23 Aug 2023 13:32:51 -0700 Subject: [PATCH 40/43] update indexHitRatio calc --- .../src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs | 2 +- .../Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs index 6f415a2084..d45f1a4a60 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs @@ -44,7 +44,7 @@ public ServerSideMetrics GetServerSideMetrics() foreach (ServerSideMetrics serverSideMetrics in this.serverSideMetricsList) { indexHitRatio = (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) != 0 ? - ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : + ((retrievedDocumentCount * indexHitRatio) + (serverSideMetrics.RetrievedDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : 0; totalTime += serverSideMetrics.TotalTime; retrievedDocumentCount += serverSideMetrics.RetrievedDocumentCount; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs index e2683c8554..64be05e6b8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternalAccumulator.cs @@ -46,7 +46,7 @@ public ServerSideMetricsInternal GetServerSideMetrics() foreach (ServerSideMetricsInternal serverSideMetrics in this.serverSideMetricsList) { indexHitRatio = (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) != 0 ? - ((outputDocumentCount * indexHitRatio) + (serverSideMetrics.OutputDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : + ((retrievedDocumentCount * indexHitRatio) + (serverSideMetrics.RetrievedDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : 0; totalTime += serverSideMetrics.TotalTime; retrievedDocumentCount += serverSideMetrics.RetrievedDocumentCount; From 4a0b17f7c6ecb848ab36c6a4a09038073b1171c7 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 25 Aug 2023 02:03:01 -0700 Subject: [PATCH 41/43] mocking refactor to abstract classes --- .../src/Diagnostics/CosmosTraceDiagnostics.cs | 4 +- .../Metrics/ServerSideCumulativeMetrics.cs | 24 +--- .../ServerSideCumulativeMetricsInternal.cs | 29 +++++ .../Query/Core/Metrics/ServerSideMetrics.cs | 114 ++---------------- .../Metrics/ServerSideMetricsAccumulator.cs | 77 ------------ .../Core/Metrics/ServerSideMetricsInternal.cs | 75 ++++-------- .../Metrics/ServerSidePartitionedMetrics.cs | 35 +----- .../ServerSidePartitionedMetricsInternal.cs | 40 ++++++ 8 files changed, 113 insertions(+), 285 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetricsInternal.cs delete mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs create mode 100644 Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetricsInternal.cs diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs index d2a39e85ce..2d92a2cfb7 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs @@ -113,9 +113,9 @@ private static ServerSideCumulativeMetrics PopulateServerSideCumulativeMetrics(I ServerSideMetricsInternalAccumulator accumulator = new ServerSideMetricsInternalAccumulator(); ServerSideMetricsInternalAccumulator.WalkTraceTreeForQueryMetrics(trace, accumulator); - IReadOnlyList serverSideMetricsList = accumulator.GetPartitionedServerSideMetrics().Select(metrics => new ServerSidePartitionedMetrics(metrics)).ToList(); + IReadOnlyList serverSideMetricsList = accumulator.GetPartitionedServerSideMetrics().Select(metrics => new ServerSidePartitionedMetricsInternal(metrics)).ToList(); - ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetrics(serverSideMetricsList); + ServerSideCumulativeMetrics accumulatedMetrics = new ServerSideCumulativeMetricsInternal(serverSideMetricsList); return accumulatedMetrics.PartitionedMetrics.Count != 0 ? accumulatedMetrics : null; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs index 34826f9e7f..3e7364f957 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetrics.cs @@ -4,38 +4,20 @@ namespace Microsoft.Azure.Cosmos { using System.Collections.Generic; - using System.Linq; /// /// Metrics received for queries from the backend. /// - public class ServerSideCumulativeMetrics + public abstract class ServerSideCumulativeMetrics { - /// - /// Initializes a new instance of the class. - /// - /// - internal ServerSideCumulativeMetrics(IEnumerable serverSideMetricsList) - { - this.PartitionedMetrics = serverSideMetricsList.ToList(); - this.CumulativeMetrics = ServerSideMetrics.Create(serverSideMetricsList.Select(partitionedMetrics => partitionedMetrics.ServerSideMetrics)); - } - - /// - /// Initializes a new instance of the class. - /// - public ServerSideCumulativeMetrics() - { - } - /// /// Gets the ServerSideMetrics accumulated for a single round trip. /// - public virtual ServerSideMetrics CumulativeMetrics { get; } + public abstract ServerSideMetrics CumulativeMetrics { get; } /// /// Gets the list of ServerSideMetrics, one for for each partition. /// - public virtual IReadOnlyList PartitionedMetrics { get; } + public abstract IReadOnlyList PartitionedMetrics { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetricsInternal.cs new file mode 100644 index 0000000000..5405482bb5 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideCumulativeMetricsInternal.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos +{ + using System.Collections.Generic; + using System.Linq; + using Microsoft.Azure.Cosmos.Query.Core.Metrics; + + /// + /// Internal implementation of metrics received for queries from the backend. + /// + internal class ServerSideCumulativeMetricsInternal : ServerSideCumulativeMetrics + { + /// + /// Initializes a new instance of the class. + /// + /// + internal ServerSideCumulativeMetricsInternal(IEnumerable serverSideMetricsList) + { + this.PartitionedMetrics = serverSideMetricsList.ToList(); + this.CumulativeMetrics = ServerSideMetricsInternal.Create(serverSideMetricsList.Select(partitionedMetrics => partitionedMetrics.ServerSideMetricsInternal)); + } + + public override ServerSideMetrics CumulativeMetrics { get; } + + public override IReadOnlyList PartitionedMetrics { get; } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index 22c61f34c4..dcc39e4202 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -5,158 +5,70 @@ namespace Microsoft.Azure.Cosmos { using System; - using System.Collections.Generic; - using Microsoft.Azure.Cosmos.Query.Core.Metrics; /// /// Metrics received for queries from the backend. /// - public class ServerSideMetrics + public abstract class ServerSideMetrics { - /// - /// Initializes a new instance of the class. - /// - /// - internal ServerSideMetrics(ServerSideMetricsInternal serverSideMetricsInternal) - { - this.RetrievedDocumentCount = serverSideMetricsInternal.RetrievedDocumentCount; - this.RetrievedDocumentSize = serverSideMetricsInternal.RetrievedDocumentSize; - this.OutputDocumentCount = serverSideMetricsInternal.OutputDocumentCount; - this.OutputDocumentSize = serverSideMetricsInternal.OutputDocumentSize; - this.IndexHitRatio = serverSideMetricsInternal.IndexHitRatio; - this.TotalTime = serverSideMetricsInternal.TotalTime; - this.QueryPreparationTime = serverSideMetricsInternal.QueryPreparationTimes.LogicalPlanBuildTime - + serverSideMetricsInternal.QueryPreparationTimes.PhysicalPlanBuildTime - + serverSideMetricsInternal.QueryPreparationTimes.QueryCompilationTime - + serverSideMetricsInternal.QueryPreparationTimes.QueryOptimizationTime; - this.IndexLookupTime = serverSideMetricsInternal.IndexLookupTime; - this.DocumentLoadTime = serverSideMetricsInternal.DocumentLoadTime; - this.VMExecutionTime = serverSideMetricsInternal.VMExecutionTime; - this.RuntimeExecutionTime = serverSideMetricsInternal.RuntimeExecutionTimes.QueryEngineExecutionTime - + serverSideMetricsInternal.RuntimeExecutionTimes.SystemFunctionExecutionTime - + serverSideMetricsInternal.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime; - this.DocumentWriteTime = serverSideMetricsInternal.DocumentWriteTime; - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - internal ServerSideMetrics( - long retrievedDocumentCount, - long retrievedDocumentSize, - long outputDocumentCount, - long outputDocumentSize, - double indexHitRatio, - TimeSpan totalQueryExecutionTime, - TimeSpan queryPreparationTimes, - TimeSpan indexLookupTime, - TimeSpan documentLoadTime, - TimeSpan vmExecutionTime, - TimeSpan runtimeExecutionTimes, - TimeSpan documentWriteTime) - { - this.RetrievedDocumentCount = retrievedDocumentCount; - this.RetrievedDocumentSize = retrievedDocumentSize; - this.OutputDocumentCount = outputDocumentCount; - this.OutputDocumentSize = outputDocumentSize; - this.IndexHitRatio = indexHitRatio; - this.TotalTime = totalQueryExecutionTime; - this.QueryPreparationTime = queryPreparationTimes; - this.IndexLookupTime = indexLookupTime; - this.DocumentLoadTime = documentLoadTime; - this.VMExecutionTime = vmExecutionTime; - this.RuntimeExecutionTime = runtimeExecutionTimes; - this.DocumentWriteTime = documentWriteTime; - } - - /// - /// Initializes a new instance of the class. - /// - public ServerSideMetrics() - { - } - /// /// Gets the total query time in the Azure Cosmos database service. /// - public virtual TimeSpan TotalTime { get; } + public abstract TimeSpan TotalTime { get; } /// /// Gets the number of documents retrieved during query in the Azure Cosmos database service. /// - public virtual long RetrievedDocumentCount { get; } + public abstract long RetrievedDocumentCount { get; } /// /// Gets the size of documents retrieved in bytes during query in the Azure Cosmos DB service. /// - public virtual long RetrievedDocumentSize { get; } + public abstract long RetrievedDocumentSize { get; } /// /// Gets the number of documents returned by query in the Azure Cosmos DB service. /// - public virtual long OutputDocumentCount { get; } + public abstract long OutputDocumentCount { get; } /// /// Gets the size of documents outputted in bytes during query in the Azure Cosmos database service. /// - public virtual long OutputDocumentSize { get; } + public abstract long OutputDocumentSize { get; } /// /// Gets the query preparation time in the Azure Cosmos database service. /// - public virtual TimeSpan QueryPreparationTime { get; } + public abstract TimeSpan QueryPreparationTime { get; } /// /// Gets the query index lookup time in the Azure Cosmos database service. /// - public virtual TimeSpan IndexLookupTime { get; } + public abstract TimeSpan IndexLookupTime { get; } /// /// Gets the document loading time during query in the Azure Cosmos database service. /// - public virtual TimeSpan DocumentLoadTime { get; } + public abstract TimeSpan DocumentLoadTime { get; } /// /// Gets the query runtime execution time during query in the Azure Cosmos database service. /// - public virtual TimeSpan RuntimeExecutionTime { get; } + public abstract TimeSpan RuntimeExecutionTime { get; } /// /// Gets the output writing/serializing time during query in the Azure Cosmos database service. /// - public virtual TimeSpan DocumentWriteTime { get; } + public abstract TimeSpan DocumentWriteTime { get; } /// /// Gets the index hit ratio by query in the Azure Cosmos database service. /// - public virtual double IndexHitRatio { get; } + public abstract double IndexHitRatio { get; } /// /// Gets the VMExecution Time. /// - public virtual TimeSpan VMExecutionTime { get; } - - internal static ServerSideMetrics Create(IEnumerable serverSideMetricsEnumerable) - { - ServerSideMetricsAccumulator accumulator = new ServerSideMetricsAccumulator(); - foreach (ServerSideMetrics serverSideMetrics in serverSideMetricsEnumerable) - { - accumulator.Accumulate(serverSideMetrics); - } - - return accumulator.GetServerSideMetrics(); - } + public abstract TimeSpan VMExecutionTime { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs deleted file mode 100644 index d45f1a4a60..0000000000 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsAccumulator.cs +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -namespace Microsoft.Azure.Cosmos.Query.Core.Metrics -{ - using System; - using System.Collections.Generic; - - internal sealed class ServerSideMetricsAccumulator - { - private readonly List serverSideMetricsList; - - public ServerSideMetricsAccumulator() - { - this.serverSideMetricsList = new List(); - } - - public void Accumulate(ServerSideMetrics serverSideMetrics) - { - if (serverSideMetrics == null) - { - throw new ArgumentNullException(nameof(serverSideMetrics)); - } - - this.serverSideMetricsList.Add(serverSideMetrics); - } - - public ServerSideMetrics GetServerSideMetrics() - { - TimeSpan totalTime = TimeSpan.Zero; - long retrievedDocumentCount = 0; - long retrievedDocumentSize = 0; - long outputDocumentCount = 0; - long outputDocumentSize = 0; - double indexHitRatio = 0; - TimeSpan queryPreparationTime = TimeSpan.Zero; - TimeSpan indexLookupTime = TimeSpan.Zero; - TimeSpan documentLoadTime = TimeSpan.Zero; - TimeSpan runtimeExecutionTime = TimeSpan.Zero; - TimeSpan documentWriteTime = TimeSpan.Zero; - TimeSpan vMExecutionTime = TimeSpan.Zero; - - foreach (ServerSideMetrics serverSideMetrics in this.serverSideMetricsList) - { - indexHitRatio = (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) != 0 ? - ((retrievedDocumentCount * indexHitRatio) + (serverSideMetrics.RetrievedDocumentCount * serverSideMetrics.IndexHitRatio)) / (retrievedDocumentCount + serverSideMetrics.RetrievedDocumentCount) : - 0; - totalTime += serverSideMetrics.TotalTime; - retrievedDocumentCount += serverSideMetrics.RetrievedDocumentCount; - retrievedDocumentSize += serverSideMetrics.RetrievedDocumentSize; - outputDocumentCount += serverSideMetrics.OutputDocumentCount; - outputDocumentSize += serverSideMetrics.OutputDocumentSize; - queryPreparationTime += serverSideMetrics.QueryPreparationTime; - indexLookupTime += serverSideMetrics.IndexLookupTime; - documentLoadTime += serverSideMetrics.DocumentLoadTime; - runtimeExecutionTime += serverSideMetrics.RuntimeExecutionTime; - documentWriteTime += serverSideMetrics.DocumentWriteTime; - vMExecutionTime += serverSideMetrics.VMExecutionTime; - } - - return new ServerSideMetrics( - retrievedDocumentCount: retrievedDocumentCount, - retrievedDocumentSize: retrievedDocumentSize, - outputDocumentCount: outputDocumentCount, - outputDocumentSize: outputDocumentSize, - indexHitRatio: indexHitRatio, - totalQueryExecutionTime: totalTime, - queryPreparationTimes: queryPreparationTime, - indexLookupTime: indexLookupTime, - documentLoadTime: documentLoadTime, - vmExecutionTime: vMExecutionTime, - runtimeExecutionTimes: runtimeExecutionTime, - documentWriteTime: documentWriteTime); - } - } -} diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs index d3e8e52a01..6e80de06a5 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetricsInternal.cs @@ -17,7 +17,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics #else internal #endif - sealed class ServerSideMetricsInternal + sealed class ServerSideMetricsInternal : ServerSideMetrics { /// /// QueryMetrics with all members having default (but not null) members. @@ -85,74 +85,43 @@ public ServerSideMetricsInternal( this.PartitionKeyRangeId = partitionKeyRangeId; } - /// - /// Gets the total query time in the Azure Cosmos database service. - /// - public TimeSpan TotalTime { get; } + public override TimeSpan TotalTime { get; } - /// - /// Gets the number of documents retrieved during query in the Azure Cosmos database service. - /// - public long RetrievedDocumentCount { get; } + public override long RetrievedDocumentCount { get; } - /// - /// Gets the size of documents retrieved in bytes during query in the Azure Cosmos DB service. - /// - public long RetrievedDocumentSize { get; } + public override long RetrievedDocumentSize { get; } - /// - /// Gets the number of documents returned by query in the Azure Cosmos DB service. - /// - public long OutputDocumentCount { get; } + public override long OutputDocumentCount { get; } - /// - /// Gets the size of documents outputted in bytes during query in the Azure Cosmos database service. - /// - public long OutputDocumentSize { get; } + public override long OutputDocumentSize { get; } - /// - /// Gets the query QueryPreparationTimes in the Azure Cosmos database service. - /// public QueryPreparationTimesInternal QueryPreparationTimes { get; } - /// - /// Gets the query index lookup time in the Azure Cosmos database service. - /// - public TimeSpan IndexLookupTime { get; } + public override TimeSpan QueryPreparationTime => + this.QueryPreparationTimes.LogicalPlanBuildTime + + this.QueryPreparationTimes.PhysicalPlanBuildTime + + this.QueryPreparationTimes.QueryCompilationTime + + this.QueryPreparationTimes.QueryOptimizationTime; - /// - /// Gets the document loading time during query in the Azure Cosmos database service. - /// - public TimeSpan DocumentLoadTime { get; } + public override TimeSpan IndexLookupTime { get; } + + public override TimeSpan DocumentLoadTime { get; } - /// - /// Gets the query runtime execution times during query in the Azure Cosmos database service. - /// public RuntimeExecutionTimesInternal RuntimeExecutionTimes { get; } - /// - /// Gets the output writing/serializing time during query in the Azure Cosmos database service. - /// - public TimeSpan DocumentWriteTime { get; } + public override TimeSpan RuntimeExecutionTime => + this.RuntimeExecutionTimes.QueryEngineExecutionTime + + this.RuntimeExecutionTimes.SystemFunctionExecutionTime + + this.RuntimeExecutionTimes.UserDefinedFunctionExecutionTime; - /// - /// Gets the index hit ratio by query in the Azure Cosmos database service. - /// - public double IndexHitRatio { get; } + public override TimeSpan DocumentWriteTime { get; } - /// - /// Gets the VMExecution Time. - /// - public TimeSpan VMExecutionTime { get; } + public override double IndexHitRatio { get; } + + public override TimeSpan VMExecutionTime { get; } - /// - /// Gets the FeedRange for a single backend call. - /// public string FeedRange { get; set; } - /// - /// Gets the partition key range id for a single backend call. - /// public int? PartitionKeyRangeId { get; set; } public static ServerSideMetricsInternal Create(IEnumerable serverSideMetricsEnumerable) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs index 8c23970b51..3fd1f47094 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetrics.cs @@ -4,51 +4,24 @@ namespace Microsoft.Azure.Cosmos { - using Microsoft.Azure.Cosmos.Query.Core.Metrics; - /// /// Represents server side metrics specific for a single partition. /// - public class ServerSidePartitionedMetrics + public abstract class ServerSidePartitionedMetrics { - internal ServerSidePartitionedMetrics(ServerSideMetricsInternal serverSideMetricsInternal) - : this(new ServerSideMetrics(serverSideMetricsInternal), serverSideMetricsInternal.FeedRange, serverSideMetricsInternal.PartitionKeyRangeId) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// - /// - internal ServerSidePartitionedMetrics(ServerSideMetrics serverSideMetrics, string feedRange, int? partitionKeyRangeId) - { - this.ServerSideMetrics = serverSideMetrics; - this.FeedRange = feedRange; - this.PartitionKeyRangeId = partitionKeyRangeId; - } - - /// - /// Initializes a new instance of the class. - /// - public ServerSidePartitionedMetrics() - { - } - /// /// Gets the backend metrics for the request. /// - public virtual ServerSideMetrics ServerSideMetrics { get; } + public abstract ServerSideMetrics ServerSideMetrics { get; } /// /// Gets the FeedRange for the partition. /// - public virtual string FeedRange { get; } + public abstract string FeedRange { get; } /// /// Gets the partition key range id for the partition. /// - public virtual int? PartitionKeyRangeId { get; } + public abstract int? PartitionKeyRangeId { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetricsInternal.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetricsInternal.cs new file mode 100644 index 0000000000..9ed30963a6 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSidePartitionedMetricsInternal.cs @@ -0,0 +1,40 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + using Microsoft.Azure.Cosmos.Query.Core.Metrics; + + /// + /// The internal implementation for server side metrics specific for a single partition. + /// + internal class ServerSidePartitionedMetricsInternal : ServerSidePartitionedMetrics + { + internal ServerSidePartitionedMetricsInternal(ServerSideMetricsInternal serverSideMetricsInternal) + : this(serverSideMetricsInternal, serverSideMetricsInternal.FeedRange, serverSideMetricsInternal.PartitionKeyRangeId) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + internal ServerSidePartitionedMetricsInternal(ServerSideMetricsInternal serverSideMetricsInternal, string feedRange, int? partitionKeyRangeId) + { + this.ServerSideMetricsInternal = serverSideMetricsInternal; + this.FeedRange = feedRange; + this.PartitionKeyRangeId = partitionKeyRangeId; + } + + public ServerSideMetricsInternal ServerSideMetricsInternal { get; } + + public override ServerSideMetrics ServerSideMetrics => this.ServerSideMetricsInternal; + + public override string FeedRange { get; } + + public override int? PartitionKeyRangeId { get; } + } +} From e30b8bcd0b59c7fdd2f79085fd1d06518fa56c05 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 5 Sep 2023 06:58:46 -0700 Subject: [PATCH 42/43] contract updates --- .../Contracts/DotNetSDKAPI.json | 189 +++++++----------- 1 file changed, 70 insertions(+), 119 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index d1f26fe878..759762f21f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -9034,239 +9034,190 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.ServerSideCumulativeMetrics;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.ServerSideCumulativeMetrics;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics": { "Type": "Property", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics CumulativeMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_CumulativeMetrics();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics;CanRead:True;CanWrite:False;System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor()": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(), Void .ctor()]" + "MethodInfo": "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] PartitionedMetrics;CanRead:True;CanWrite:False;System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics] get_PartitionedMetrics();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.ServerSideMetrics;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.ServerSideMetrics;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { - "Double get_IndexHitRatio()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Double get_IndexHitRatio()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "Double get_IndexHitRatio();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Double IndexHitRatio": { "Type": "Property", "Attributes": [], - "MethodInfo": "Double IndexHitRatio;CanRead:True;CanWrite:False;Double get_IndexHitRatio();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Double IndexHitRatio;CanRead:True;CanWrite:False;Double get_IndexHitRatio();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Int64 get_OutputDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Int64 get_OutputDocumentCount()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "Int64 get_OutputDocumentCount();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Int64 get_OutputDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Int64 get_OutputDocumentSize()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "Int64 get_OutputDocumentSize();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Int64 get_RetrievedDocumentCount()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Int64 get_RetrievedDocumentCount()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "Int64 get_RetrievedDocumentCount();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Int64 get_RetrievedDocumentSize()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Int64 get_RetrievedDocumentSize()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "Int64 get_RetrievedDocumentSize();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 OutputDocumentCount": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 OutputDocumentCount;CanRead:True;CanWrite:False;Int64 get_OutputDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 OutputDocumentCount;CanRead:True;CanWrite:False;Int64 get_OutputDocumentCount();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 OutputDocumentSize": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 OutputDocumentSize;CanRead:True;CanWrite:False;Int64 get_OutputDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 OutputDocumentSize;CanRead:True;CanWrite:False;Int64 get_OutputDocumentSize();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 RetrievedDocumentCount": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 RetrievedDocumentCount;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentCount();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 RetrievedDocumentCount;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentCount();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Int64 RetrievedDocumentSize": { "Type": "Property", "Attributes": [], - "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Int64 RetrievedDocumentSize;CanRead:True;CanWrite:False;Int64 get_RetrievedDocumentSize();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan DocumentLoadTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan DocumentLoadTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan DocumentLoadTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentLoadTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan DocumentWriteTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan DocumentWriteTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan DocumentWriteTime;CanRead:True;CanWrite:False;System.TimeSpan get_DocumentWriteTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_DocumentLoadTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_DocumentLoadTime()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_DocumentLoadTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.TimeSpan get_DocumentLoadTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_DocumentWriteTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_DocumentWriteTime()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_DocumentWriteTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.TimeSpan get_DocumentWriteTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_IndexLookupTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_IndexLookupTime()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.TimeSpan get_IndexLookupTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_QueryPreparationTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_QueryPreparationTime()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_QueryPreparationTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.TimeSpan get_QueryPreparationTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_RuntimeExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_RuntimeExecutionTime()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_RuntimeExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.TimeSpan get_RuntimeExecutionTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_TotalTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_TotalTime()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.TimeSpan get_TotalTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.TimeSpan get_VMExecutionTime()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.TimeSpan get_VMExecutionTime()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.TimeSpan get_VMExecutionTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan IndexLookupTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan IndexLookupTime;CanRead:True;CanWrite:False;System.TimeSpan get_IndexLookupTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan QueryPreparationTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan QueryPreparationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryPreparationTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan QueryPreparationTime;CanRead:True;CanWrite:False;System.TimeSpan get_QueryPreparationTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan RuntimeExecutionTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan RuntimeExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_RuntimeExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan RuntimeExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_RuntimeExecutionTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan TotalTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan TotalTime;CanRead:True;CanWrite:False;System.TimeSpan get_TotalTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.TimeSpan TotalTime;CanRead:True;CanWrite:False;System.TimeSpan get_TotalTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan VMExecutionTime": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor()": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(), Void .ctor()]" + "MethodInfo": "System.TimeSpan VMExecutionTime;CanRead:True;CanWrite:False;System.TimeSpan get_VMExecutionTime();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Microsoft.Azure.Cosmos.ServerSidePartitionedMetrics;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { - "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics": { "Type": "Property", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.ServerSideMetrics ServerSideMetrics;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ServerSideMetrics get_ServerSideMetrics();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "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.Int32] get_PartitionKeyRangeId()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.Nullable`1[System.Int32] get_PartitionKeyRangeId()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "Attributes": [], + "MethodInfo": "System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Nullable`1[System.Int32] PartitionKeyRangeId": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.Nullable`1[System.Int32] PartitionKeyRangeId;CanRead:True;CanWrite:False;System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Nullable`1[System.Int32] PartitionKeyRangeId;CanRead:True;CanWrite:False;System.Nullable`1[System.Int32] get_PartitionKeyRangeId();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.String FeedRange": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.String FeedRange;CanRead:True;CanWrite:False;System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.String FeedRange;CanRead:True;CanWrite:False;System.String get_FeedRange();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.String get_FeedRange()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.String get_FeedRange()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.String get_FeedRange();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor()": { - "Type": "Constructor", "Attributes": [], - "MethodInfo": "[Void .ctor(), Void .ctor()]" + "MethodInfo": "System.String get_FeedRange();IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} From 806a1602311f329460c4695155c0d9407a43c6a1 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 8 Sep 2023 06:32:22 -0700 Subject: [PATCH 43/43] PR comments - Update documentation --- Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs | 5 ++++- .../src/Query/Core/Metrics/ServerSideMetrics.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs index 0bd67de840..b88eaa8efe 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs @@ -44,8 +44,11 @@ public virtual int GetFailedRequestCount() } /// - /// This represents the backend query metrics for the request. + /// This represents the backend query metrics for the request. /// + /// + /// This is only applicable for query operations. For all other operations this will return null. + /// /// The accumulated backend metrics for the request. public virtual ServerSideCumulativeMetrics GetQueryMetrics() { diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs index dcc39e4202..ff215a582e 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/ServerSideMetrics.cs @@ -62,7 +62,7 @@ public abstract class ServerSideMetrics public abstract TimeSpan DocumentWriteTime { get; } /// - /// Gets the index hit ratio by query in the Azure Cosmos database service. + /// Gets the index hit ratio by query in the Azure Cosmos database service. Value is within the range [0,1]. /// public abstract double IndexHitRatio { get; }