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

FeedResponse<T>.Headers empty for ordered, cross-partition queries #2356

Closed
ccurrens opened this issue Mar 31, 2021 · 1 comment · Fixed by #2357
Closed

FeedResponse<T>.Headers empty for ordered, cross-partition queries #2356

ccurrens opened this issue Mar 31, 2021 · 1 comment · Fixed by #2357
Assignees
Labels
Hotfix A hotfix is required for the issue QUERY

Comments

@ccurrens
Copy link
Contributor

Response headers are missing in FeedReponse<T> when the query executed contains an OrderBy statement and is cross-partition.

To Reproduce
Here's a simplified case:

public class Family
{
    [JsonProperty(PropertyName = "id")]
    public string Id { get; set; }

    public string LastName { get; set; }

    [JsonProperty(PropertyName = "_pk")]
    public string PartitionKey => LastName;
}

private Task RunQuery(IQueryable<Family> query)
{
    var iterator = query.ToFeedIterator();
    while (iterator.HasMoreResults)
    {
        var response = await iterator.ReadNextAsync();
        Console.WriteLine(response.Headers.Get("x-ms-documentdb-query-metrics") ?? "MISSING");
    }
}

// Writes "MISSING" to the console
RunQuery(container.GetItemLinqQueryable<Family>().OrderBy(f => f.Id));

// Writes query metrics to the console
RunQuery(container.GetItemLinqQueryable<Family>());

Expected behavior
Headers from the response should be available in the FeedResponse

Actual behavior
There are no headers available in the FeedResponse

Environment summary
SDK Version: 3.17.1 (Also in 3.16, and possibly earlier)
OS Version (e.g. Windows, Linux, MacOSX): All

Additional context
The headers are available by adding a RequestHandler to the client. This is a complicated workaround when the client is used by multiple threads and you are trying to relate requests to one another.

Since the headers are available when running an ordered query in-partition, it seems to be an issue with additionalHeaders not flowing through to the QueryPage result (also here)

Ultimately, though, I think this is indicative of a missing feature in the SDK, where it would be really nice to have the QueryMetrics class (or similar) publicly exposed on responses. Apparently, something similar was available in an earlier SDK version. Our particular use case is structured logging, where we enrich our logs with additional properties, including the index utilization ratio, request counts, and retrieved/output document counts.

@j82w
Copy link
Contributor

j82w commented Apr 26, 2021

@ccurrens please upgrade to the latest 3.18.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hotfix A hotfix is required for the issue QUERY
Projects
None yet
3 participants