diff --git a/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs b/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
index 9694a14713..60ff675172 100644
--- a/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
+++ b/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
@@ -251,21 +251,27 @@ private void CheckDisposed()
/// Decode the Index Metrics from the response headers, if exists.
///
/// The response headers
- /// The encoding of the IndexMetrics response
+ /// The encoding of the IndexMetrics response
/// Lazy implementation of the pretty-printed IndexMetrics
- static internal Lazy DecodeIndexMetrics(Headers responseMessageHeaders, bool isBse64Encoded)
+ static internal Lazy DecodeIndexMetrics(Headers responseMessageHeaders, bool isBase64Encoded)
{
if (responseMessageHeaders?.IndexUtilizationText != null)
{
return new Lazy(() =>
{
- IndexUtilizationInfo parsedIndexUtilizationInfo = IndexUtilizationInfo.CreateFromString(responseMessageHeaders.IndexUtilizationText, isBse64Encoded);
-
- StringBuilder stringBuilder = new StringBuilder();
- IndexMetricWriter indexMetricWriter = new IndexMetricWriter(stringBuilder);
- indexMetricWriter.WriteIndexMetrics(parsedIndexUtilizationInfo);
+ if (isBase64Encoded)
+ {
+ IndexUtilizationInfo parsedIndexUtilizationInfo = IndexUtilizationInfo.CreateFromString(responseMessageHeaders.IndexUtilizationText);
- return stringBuilder.ToString();
+ StringBuilder stringBuilder = new StringBuilder();
+ IndexMetricsWriter indexMetricWriter = new IndexMetricsWriter(stringBuilder);
+ indexMetricWriter.WriteIndexMetrics(parsedIndexUtilizationInfo);
+
+ return stringBuilder.ToString();
+ }
+
+ // Return the JSON from the response header
+ return responseMessageHeaders.IndexUtilizationText;
});
}
diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/CompositeIndexIndexMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/CompositeIndexIndexMetrics.cs
new file mode 100644
index 0000000000..5ee147dc87
--- /dev/null
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/CompositeIndexIndexMetrics.cs
@@ -0,0 +1,48 @@
+//------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//------------------------------------------------------------
+namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
+{
+ using System;
+ using System.Collections.Generic;
+ using Newtonsoft.Json;
+
+ ///
+ /// Query index utilization data for composite indexes (sub-structure of the Index Metrics class) in the Azure Cosmos database service.
+ ///
+ #if INTERNAL
+#pragma warning disable SA1600
+#pragma warning disable CS1591
+ public
+#else
+ internal
+#endif
+ sealed class CompositeIndexIndexMetrics
+ {
+ ///
+ /// Initialized a new instance of an Index Metrics' Composite Index class.
+ ///
+ /// The string list representation of the composite index.
+ /// The index impact score.
+ [JsonConstructor]
+ private CompositeIndexIndexMetrics(
+ IReadOnlyList indexDocumentExpressions,
+ string indexImpactScore)
+ {
+ this.IndexSpecs = indexDocumentExpressions;
+ this.IndexImpactScore = indexImpactScore;
+ }
+
+ ///
+ /// String list representation of index paths of a composite index.
+ ///
+ [JsonProperty(PropertyName = "IndexSpecs")]
+ public IReadOnlyList IndexSpecs { get; }
+
+ ///
+ /// The index impact score of the composite index.
+ ///
+ [JsonProperty(PropertyName = "IndexImpactScore")]
+ public string IndexImpactScore { get; }
+ }
+}
\ No newline at end of file
diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsInfo.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsInfo.cs
new file mode 100644
index 0000000000..4156e520a7
--- /dev/null
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsInfo.cs
@@ -0,0 +1,83 @@
+//------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//------------------------------------------------------------
+namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Microsoft.Azure.Cosmos.Core;
+ using Microsoft.Azure.Cosmos.Core.Utf8;
+ using Newtonsoft.Json;
+
+ ///
+ /// Query index utilization data for composite indexes (sub-structure of the Index Metrics class) in the Azure Cosmos database service.
+ ///
+#if INTERNAL
+#pragma warning disable SA1600
+#pragma warning disable CS1591
+ public
+#else
+ internal
+#endif
+ sealed class IndexMetricsInfo
+ {
+ ///
+ /// Initializes a new instance of the Index Metrics class.
+ ///
+ /// The utilized indexes
+ /// The potential indexes
+ [JsonConstructor]
+ public IndexMetricsInfo(
+ IndexMetricsInfoEntity utilizedEntity,
+ IndexMetricsInfoEntity potentialEntity)
+ {
+ this.UtilizedEntity = utilizedEntity;
+ this.PotentialEntity = potentialEntity;
+ }
+
+ [JsonProperty("Utilized")]
+ public IndexMetricsInfoEntity UtilizedEntity { get; }
+
+ [JsonProperty("Potential")]
+ public IndexMetricsInfoEntity PotentialEntity { get; }
+
+ ///
+ /// Creates a new IndexMetricsInfo from the backend delimited string.
+ ///
+ /// The backend delimited string to deserialize from.
+ /// The parsed index utilization info
+ /// A new IndexMetricsInfo from the backend delimited string.
+ public static bool TryCreateFromString(string delimitedString, out IndexMetricsInfo result)
+ {
+ if (delimitedString == null)
+ {
+ result = null;
+ return false;
+ }
+
+ try
+ {
+ // Decode and deserialize the response string
+ string decodedString = System.Web.HttpUtility.UrlDecode(delimitedString, Encoding.UTF8);
+
+ result = JsonConvert.DeserializeObject(decodedString, new JsonSerializerSettings()
+ {
+ // Allowing null values to be resilient to Json structure change
+ MissingMemberHandling = MissingMemberHandling.Ignore,
+ NullValueHandling = NullValueHandling.Ignore,
+ // Ignore parsing error encountered in deserialization
+ Error = (sender, parsingErrorEvent) => parsingErrorEvent.ErrorContext.Handled = true
+ }) ?? null;
+
+ return true;
+ }
+ catch (JsonException)
+ {
+ result = null;
+ return false;
+ }
+ }
+ }
+}
diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsInfoEntity.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsInfoEntity.cs
new file mode 100644
index 0000000000..69a0f3270a
--- /dev/null
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsInfoEntity.cs
@@ -0,0 +1,43 @@
+//------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//------------------------------------------------------------
+namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Microsoft.Azure.Cosmos.Core;
+ using Microsoft.Azure.Cosmos.Core.Utf8;
+ using Newtonsoft.Json;
+
+ ///
+ /// Query index utilization metrics in the Azure Cosmos database service.
+ ///
+#if INTERNAL
+#pragma warning disable SA1600
+#pragma warning disable CS1591
+ public
+#else
+ internal
+#endif
+ sealed class IndexMetricsInfoEntity
+ {
+ ///
+ /// Initializes a new instance of the Index Utilization class. This is the legacy class of IndexMetricsInfoEntity.
+ ///
+ /// The utilized single indexes list
+ /// The potential single indexes list
+ [JsonConstructor]
+ public IndexMetricsInfoEntity(
+ IReadOnlyList singleIndexes,
+ IReadOnlyList compositeIndexes)
+ {
+ this.SingleIndexes = (singleIndexes ?? Enumerable.Empty()).Where(item => item != null).ToList();
+ this.CompositeIndexes = (compositeIndexes ?? Enumerable.Empty()).Where(item => item != null).ToList();
+ }
+
+ public IReadOnlyList SingleIndexes { get; }
+ public IReadOnlyList CompositeIndexes { get; }
+ }
+}
diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricWriter.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsWriter.cs
similarity index 65%
rename from Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricWriter.cs
rename to Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsWriter.cs
index 7deb1f767b..138275fda9 100644
--- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricWriter.cs
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexMetricsWriter.cs
@@ -9,7 +9,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
using System.Text;
///
- /// Base class for visiting and serializing a .
+ /// Base class for visiting and serializing a .
///
#if INTERNAL
#pragma warning disable SA1600
@@ -18,7 +18,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
#else
internal
#endif
- class IndexMetricWriter
+ class IndexMetricsWriter
{
private const string IndexUtilizationInfo = "Index Utilization Information";
private const string UtilizedSingleIndexes = "Utilized Single Indexes";
@@ -32,7 +32,7 @@ class IndexMetricWriter
private readonly StringBuilder stringBuilder;
- public IndexMetricWriter(StringBuilder stringBuilder)
+ public IndexMetricsWriter(StringBuilder stringBuilder)
{
this.stringBuilder = stringBuilder ?? throw new ArgumentNullException($"{nameof(stringBuilder)} must not be null.");
}
@@ -50,37 +50,37 @@ public void WriteIndexMetrics(IndexUtilizationInfo indexUtilizationInfo)
#region IndexUtilizationInfo
protected void WriteBeforeIndexUtilizationInfo()
{
- IndexMetricWriter.AppendNewlineToStringBuilder(this.stringBuilder);
- IndexMetricWriter.AppendHeaderToStringBuilder(
+ IndexMetricsWriter.AppendNewlineToStringBuilder(this.stringBuilder);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(
this.stringBuilder,
- IndexMetricWriter.IndexUtilizationInfo,
+ IndexMetricsWriter.IndexUtilizationInfo,
indentLevel: 0);
}
protected void WriteIndexUtilizationInfo(IndexUtilizationInfo indexUtilizationInfo)
{
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricWriter.UtilizedSingleIndexes, indentLevel: 1);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricsWriter.UtilizedSingleIndexes, indentLevel: 1);
foreach (SingleIndexUtilizationEntity indexUtilizationEntity in indexUtilizationInfo.UtilizedSingleIndexes)
{
WriteSingleIndexUtilizationEntity(indexUtilizationEntity);
}
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricWriter.PotentialSingleIndexes, indentLevel: 1);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricsWriter.PotentialSingleIndexes, indentLevel: 1);
foreach (SingleIndexUtilizationEntity indexUtilizationEntity in indexUtilizationInfo.PotentialSingleIndexes)
{
WriteSingleIndexUtilizationEntity(indexUtilizationEntity);
}
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricWriter.UtilizedCompositeIndexes, indentLevel: 1);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricsWriter.UtilizedCompositeIndexes, indentLevel: 1);
foreach (CompositeIndexUtilizationEntity indexUtilizationEntity in indexUtilizationInfo.UtilizedCompositeIndexes)
{
WriteCompositeIndexUtilizationEntity(indexUtilizationEntity);
}
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricWriter.PotentialCompositeIndexes, indentLevel: 1);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricsWriter.PotentialCompositeIndexes, indentLevel: 1);
foreach (CompositeIndexUtilizationEntity indexUtilizationEntity in indexUtilizationInfo.PotentialCompositeIndexes)
{
@@ -89,16 +89,16 @@ protected void WriteIndexUtilizationInfo(IndexUtilizationInfo indexUtilizationIn
void WriteSingleIndexUtilizationEntity(SingleIndexUtilizationEntity indexUtilizationEntity)
{
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricWriter.IndexExpression}: {indexUtilizationEntity.IndexDocumentExpression}", indentLevel: 2);
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricWriter.IndexImpactScore}: {indexUtilizationEntity.IndexImpactScore}", indentLevel: 2);
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricWriter.IndexUtilizationSeparator, indentLevel: 2);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricsWriter.IndexExpression}: {indexUtilizationEntity.IndexDocumentExpression}", indentLevel: 2);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricsWriter.IndexImpactScore}: {indexUtilizationEntity.IndexImpactScore}", indentLevel: 2);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricsWriter.IndexUtilizationSeparator, indentLevel: 2);
}
void WriteCompositeIndexUtilizationEntity(CompositeIndexUtilizationEntity indexUtilizationEntity)
{
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricWriter.IndexExpression}: {String.Join(", ", indexUtilizationEntity.IndexDocumentExpressions)}", indentLevel: 2);
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricWriter.IndexImpactScore}: {indexUtilizationEntity.IndexImpactScore}", indentLevel: 2);
- IndexMetricWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricWriter.IndexUtilizationSeparator, indentLevel: 2);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricsWriter.IndexExpression}: {String.Join(", ", indexUtilizationEntity.IndexDocumentExpressions)}", indentLevel: 2);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{IndexMetricsWriter.IndexImpactScore}: {indexUtilizationEntity.IndexImpactScore}", indentLevel: 2);
+ IndexMetricsWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexMetricsWriter.IndexUtilizationSeparator, indentLevel: 2);
}
}
@@ -123,7 +123,7 @@ private static void AppendHeaderToStringBuilder(StringBuilder stringBuilder, str
private static void AppendNewlineToStringBuilder(StringBuilder stringBuilder)
{
- IndexMetricWriter.AppendHeaderToStringBuilder(
+ IndexMetricsWriter.AppendHeaderToStringBuilder(
stringBuilder,
string.Empty,
indentLevel: 0);
diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs
index e34a7902ad..a9ef4569b5 100644
--- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs
@@ -8,6 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
using System.Linq;
using System.Text;
using Microsoft.Azure.Cosmos.Core;
+ using Microsoft.Azure.Cosmos.Core.Utf8;
using Newtonsoft.Json;
///
@@ -29,7 +30,7 @@ sealed class IndexUtilizationInfo
potentialCompositeIndexes: new List());
///
- /// Initializes a new instance of the Index Utilization class.
+ /// Initializes a new instance of the Index Utilization class. This is the legacy class of IndexMetricsInfo.
///
/// The utilized single indexes list
/// The potential single indexes list
@@ -60,23 +61,6 @@ public IndexUtilizationInfo(
/// The parsed index utilization info
/// A new IndexUtilizationInfo from the backend delimited string.
internal static bool TryCreateFromDelimitedBase64String(string delimitedString, out IndexUtilizationInfo result)
- {
- if (delimitedString == null)
- {
- result = IndexUtilizationInfo.Empty;
- return true;
- }
-
- return TryCreateFromDelimitedString(System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(delimitedString)), out result);
- }
-
- ///
- /// Creates a new IndexUtilizationInfo from the backend delimited string.
- ///
- /// The backend delimited string to deserialize from.
- /// The parsed index utilization info
- /// A new IndexUtilizationInfo from the backend delimited string.
- internal static bool TryCreateFromDelimitedString(string delimitedString, out IndexUtilizationInfo result)
{
if (delimitedString == null)
{
@@ -84,9 +68,15 @@ internal static bool TryCreateFromDelimitedString(string delimitedString, out In
return true;
}
+ // Even though this parsing is resilient, older version of the SDK doesn't have such lenient parsing.
+ // As such, it is right not not possible to remove some of the field in the IndexUtilizationInfo class.
+ // However, in newer version of the SDKs, the code base is going to start returning IndexMetricsInfo,
+ // so this class exists solely for legacy support.
try
{
- result = JsonConvert.DeserializeObject(delimitedString, new JsonSerializerSettings()
+ string decodedString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(delimitedString));
+
+ result = JsonConvert.DeserializeObject(decodedString, new JsonSerializerSettings()
{
// Allowing null values to be resilient to Json structure change
MissingMemberHandling = MissingMemberHandling.Ignore,
@@ -108,20 +98,10 @@ internal static bool TryCreateFromDelimitedString(string delimitedString, out In
/// Materialize the Index Utilization String into Concrete objects.
///
/// The index utilization response string as sent by the back end.
- /// The encoding of the string.
/// Cpncrete Index utilization object.
- public static IndexUtilizationInfo CreateFromString(string delimitedString, bool isBse64Encoded)
+ public static IndexUtilizationInfo CreateFromString(string delimitedString)
{
- IndexUtilizationInfo indexUtilizationInfo;
-
- if (isBse64Encoded)
- {
- TryCreateFromDelimitedBase64String(delimitedString, out indexUtilizationInfo);
- }
- else
- {
- TryCreateFromDelimitedString(delimitedString, out indexUtilizationInfo);
- }
+ TryCreateFromDelimitedBase64String(delimitedString, out IndexUtilizationInfo indexUtilizationInfo);
return indexUtilizationInfo;
}
diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/SingleIndexIndexMetrics.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/SingleIndexIndexMetrics.cs
new file mode 100644
index 0000000000..2c8826c3ea
--- /dev/null
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/SingleIndexIndexMetrics.cs
@@ -0,0 +1,47 @@
+//------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//------------------------------------------------------------
+namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
+{
+ using System;
+ using Newtonsoft.Json;
+
+ ///
+ /// Query index utilization data for single indexes (sub-structure of the Index Metrics class) in the Azure Cosmos database service.
+ ///
+ #if INTERNAL
+#pragma warning disable SA1600
+#pragma warning disable CS1591
+ public
+#else
+ internal
+#endif
+ sealed class SingleIndexIndexMetrics
+ {
+ ///
+ /// Initialized a new instance of an Index Metrics' Single Index class.
+ ///
+ /// The string representation of the single index.
+ /// The index impact score.
+ [JsonConstructor]
+ public SingleIndexIndexMetrics(
+ string indexDocumentExpression,
+ string indexImpactScore)
+ {
+ this.IndexDocumentExpression = indexDocumentExpression;
+ this.IndexImpactScore = indexImpactScore;
+ }
+
+ ///
+ /// String representation of index paths of a composite index.
+ ///
+ [JsonProperty(PropertyName = "IndexSpec")]
+ public string IndexDocumentExpression { get; }
+
+ ///
+ /// The index impact score of the single index.
+ ///
+ [JsonProperty(PropertyName = "IndexImpactScore")]
+ public string IndexImpactScore { get; }
+ }
+}
\ No newline at end of file
diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DefaultDocumentQueryExecutionContext.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DefaultDocumentQueryExecutionContext.cs
index b53c3c5c71..9895bd5f5a 100644
--- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DefaultDocumentQueryExecutionContext.cs
+++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DefaultDocumentQueryExecutionContext.cs
@@ -108,7 +108,7 @@ protected override async Task> ExecuteIntern
partitionIdentifier,
new QueryMetrics(
response.ResponseHeaders[HttpConstants.HttpHeaders.QueryMetrics],
- IndexUtilizationInfo.CreateFromString(response.ResponseHeaders[HttpConstants.HttpHeaders.IndexUtilization], true),
+ IndexUtilizationInfo.CreateFromString(response.ResponseHeaders[HttpConstants.HttpHeaders.IndexUtilization]),
new ClientSideMetrics(
this.retries,
response.RequestCharge,
diff --git a/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryResponse.cs b/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryResponse.cs
index 6c7777ebff..47c9136a8f 100644
--- a/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryResponse.cs
+++ b/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryResponse.cs
@@ -12,6 +12,7 @@ namespace Microsoft.Azure.Cosmos
using Microsoft.Azure.Cosmos.Query.Core.Metrics;
using Microsoft.Azure.Cosmos.Serializer;
using Microsoft.Azure.Cosmos.Tracing;
+ using Microsoft.Azure.Documents;
///
/// Represents the template class used by feed methods (enumeration operations) for the Azure Cosmos DB service.
@@ -183,7 +184,13 @@ private QueryResponse(
cosmosArray: cosmosElements,
serializerCore: serializerCore);
- this.IndexUtilizationText = ResponseMessage.DecodeIndexMetrics(responseMessageHeaders, true);
+ // Chose how to decode depending on which PopulateIndexMetrics request header was sent
+ // If none was sent, we currently default to V1
+ // TODO: Switch the flag to false once V2 is deployed
+ this.IndexUtilizationText = ResponseMessage.DecodeIndexMetrics(
+ responseMessageHeaders,
+ isBase64Encoded: true);
+
this.RequestMessage = requestMessage;
}
diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs
index f723107ede..2b4aba5ac0 100644
--- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs
+++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs
@@ -269,6 +269,7 @@ internal override void PopulateRequestOptions(RequestMessage request)
if (this.PopulateIndexMetrics.HasValue)
{
+ // TODO: Switch to V2
request.Headers.CosmosMessageHeaders.Add(HttpConstants.HttpHeaders.PopulateIndexMetrics, this.PopulateIndexMetrics.ToString());
}
diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/IndexMetricsParserBaselineTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/IndexMetricsParserBaselineTest.cs
index 6ae91f1375..598ee51c9d 100644
--- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/IndexMetricsParserBaselineTest.cs
+++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/IndexMetricsParserBaselineTest.cs
@@ -133,6 +133,7 @@ public void IndexUtilizationParse()
public override IndexMetricsParserTestOutput ExecuteTest(IndexMetricsParserTestInput input)
{
+ // V2
QueryRequestOptions requestOptions = new QueryRequestOptions() { PopulateIndexMetrics = true };
FeedIterator itemQuery = testContainer.GetItemQueryIterator(
diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/PopulateIndexMetricsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/PopulateIndexMetricsTest.cs
index 29f1944643..084e7738a5 100644
--- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/PopulateIndexMetricsTest.cs
+++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/PopulateIndexMetricsTest.cs
@@ -35,14 +35,6 @@ static async Task ImplementationAsync(Container container, IReadOnlyList 12");
- // Build the expected string
- Assert.IsTrue(IndexUtilizationInfo.TryCreateFromDelimitedBase64String("eyJVdGlsaXplZFNpbmdsZUluZGV4ZXMiOlt7IkZpbHRlckV4cHJlc3Npb24iOiIoUk9PVC5uYW1lID0gXCJBQkNcIikiLCJJbmRleFNwZWMiOiJcL25hbWVcLz8iLCJGaWx0ZXJQcmVjaXNlU2V0Ijp0cnVlLCJJbmRleFByZWNpc2VTZXQiOnRydWUsIkluZGV4SW1wYWN0U2NvcmUiOiJIaWdoIn0seyJGaWx0ZXJFeHByZXNzaW9uIjoiKFJPT1QuYWdlID4gMTIpIiwiSW5kZXhTcGVjIjoiXC9hZ2VcLz8iLCJGaWx0ZXJQcmVjaXNlU2V0Ijp0cnVlLCJJbmRleFByZWNpc2VTZXQiOnRydWUsIkluZGV4SW1wYWN0U2NvcmUiOiJIaWdoIn1dLCJQb3RlbnRpYWxTaW5nbGVJbmRleGVzIjpbXSwiVXRpbGl6ZWRDb21wb3NpdGVJbmRleGVzIjpbXSwiUG90ZW50aWFsQ29tcG9zaXRlSW5kZXhlcyI6W3siSW5kZXhTcGVjcyI6WyJcL25hbWUgQVNDIiwiXC9hZ2UgQVNDIl0sIkluZGV4UHJlY2lzZVNldCI6ZmFsc2UsIkluZGV4SW1wYWN0U2NvcmUiOiJIaWdoIn1dfQ==",
- out IndexUtilizationInfo parsedInfo));
- StringBuilder stringBuilder = new StringBuilder();
- IndexMetricWriter indexMetricWriter = new IndexMetricWriter(stringBuilder);
- indexMetricWriter.WriteIndexMetrics(parsedInfo);
- string expectedIndexMetricsString = stringBuilder.ToString();
-
// Test using GetItemQueryIterator
QueryRequestOptions requestOptions = new QueryRequestOptions() { PopulateIndexMetrics = true };
@@ -56,7 +48,6 @@ static async Task ImplementationAsync(Container container, IReadOnlyList 1);
Assert.IsNotNull(page.Headers.Get(HttpConstants.HttpHeaders.IndexUtilization), "Expected index utilization headers for query");
Assert.IsNotNull(page.IndexMetrics, "Expected index metrics response for query");
- Assert.AreEqual(expectedIndexMetricsString, page.IndexMetrics);
}
// Test using Stream API
@@ -73,7 +64,6 @@ static async Task ImplementationAsync(Container container, IReadOnlyList 1);
Assert.IsNotNull(response.Headers.Get(HttpConstants.HttpHeaders.IndexUtilization), "Expected index utilization headers for query");
- Assert.AreEqual(expectedIndexMetricsString, response.IndexMetrics);
}
}
}
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 d971223f09..762bbbd945 100644
--- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs
+++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs
@@ -2292,7 +2292,7 @@ private async Task ValidateQueryMetricsHeadersOverContinuations(
QueryMetrics queryMetrics = new QueryMetrics(
responseQueryMetrics,
- IndexUtilizationInfo.CreateFromString(indexUtilization, true),
+ IndexUtilizationInfo.CreateFromString(indexUtilization),
ClientSideMetrics.Empty);
this.ValidateQueryMetrics(queryMetrics);
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 9fe272a6bd..b3bce119dd 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
@@ -97,9 +97,7 @@ private static void TestParses(bool isBase64Encoded)
}
else
{
- Assert.IsTrue(IndexUtilizationInfo.TryCreateFromDelimitedString(testString,
- out IndexUtilizationInfo parsedInfo));
- Assert.IsNotNull(parsedInfo);
+ Assert.IsTrue(IndexMetricsInfo.TryCreateFromString(testString, out _));
}
}
}