Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Fixes ResponseMessage not parsing the IndexMetrics as text in latest sdk #4397

Merged
merged 6 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal ResponseMessage(
this.CosmosException = cosmosException;
this.Headers = headers ?? new Headers();

this.IndexUtilizationText = ResponseMessage.DecodeIndexMetrics(this.Headers, isBase64Encoded: true);
this.IndexUtilizationText = ResponseMessage.DecodeIndexMetrics(this.Headers, isBase64Encoded: false);
leminh98 marked this conversation as resolved.
Show resolved Hide resolved
leminh98 marked this conversation as resolved.
Show resolved Hide resolved

if (requestMessage != null && requestMessage.Trace != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ public override IndexMetricsParserTestOutput ExecuteTest(IndexMetricsParserTestI

// Make sure ODE and non-ODE is consistent
Assert.AreEqual(indexMetricsNonODE, indexMetricsODE);

// ----------------------------
// Test stream API
// ----------------------------
// Execute without ODE
string indexMetricsNonODEStreaming = RunStreamAPITest(input.Query, enableOptimisticDirectExecution: false);

// Execute with ODE
string indexMetricsODEStreaming = RunStreamAPITest(input.Query, enableOptimisticDirectExecution: true);

// Make sure ODE and non-ODE is consistent
Assert.AreEqual(indexMetricsNonODEStreaming, indexMetricsODEStreaming);

return new IndexMetricsParserTestOutput(indexMetricsNonODE);
}
Expand All @@ -403,7 +415,42 @@ private static string RunTest(string query, bool enableOptimisticDirectExecution
{
FeedResponse<CosmosElement> page = itemQuery.ReadNextAsync().Result;
Assert.IsTrue(page.Headers.AllKeys().Length > 1);
if (roundTripCount > 0)
{
if (page.IndexMetrics != null)
{
Assert.Fail("Expected only Index Metrics on first round trip. Current round trip %n", roundTripCount);
}
}
else
{
Assert.IsNotNull(page.Headers.Get(HttpConstants.HttpHeaders.IndexUtilization), "Expected index utilization headers for query");
Assert.IsNotNull(page.IndexMetrics, "Expected index metrics response for query");

indexMetrics = page.IndexMetrics;
}

roundTripCount++;
}

return indexMetrics;
}

private static string RunStreamAPITest(string query, bool enableOptimisticDirectExecution)
{
QueryRequestOptions requestOptions = new QueryRequestOptions() { PopulateIndexMetrics = true, EnableOptimisticDirectExecution = enableOptimisticDirectExecution };

using FeedIterator itemQuery = testContainer.GetItemQueryStreamIterator(
queryText: query,
requestOptions: requestOptions);

// Index Metrics is returned fully on the first page so no need to worry about result set
int roundTripCount = 0;
string indexMetrics = null;
while (itemQuery.HasMoreResults)
{
ResponseMessage page = itemQuery.ReadNextAsync().Result;
Assert.IsTrue(page.Headers.AllKeys().Length > 1);
if (roundTripCount > 0)
{
if (page.IndexMetrics != null)
Expand Down