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

feat: specify http completion for async queries #632

Merged
merged 4 commits into from
May 14, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 4.15.0 [unreleased]

### Bug Fixes
1. [#632](https://github.com/influxdata/influxdb-client-csharp/pull/632): Use HttpCompletionOption.ResponseHeadersRead for streaming

### Dependencies
Update dependencies:

Expand Down
9 changes: 7 additions & 2 deletions Client/InfluxDB.Client.Api/Client/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Text.RegularExpressions;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -115,9 +116,13 @@ internal RestRequest PrepareRequest(
string path, Method method, List<KeyValuePair<string, string>> queryParams, object postBody,
Dictionary<string, string> headerParams, Dictionary<string, string> formParams,
Dictionary<string, FileParameter> fileParams, Dictionary<string, string> pathParams,
string contentType)
string contentType,
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bednar I am still hitting the buffer limit in 4.16.0 for large queries was the default suppose to be HttpCompletionOption.ResponseHeadersRead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default value that should be overridden in our files. It seems like HttpCompletionOption.ResponseHeadersRead should also be set in the QueryApi file. As a workaround, can you try setting HttpClient.MaxResponseContentBufferSize in HttpClient? How to use a custom HttpClient is mentioned here: #528.

For more information, see:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a prerelease version of the client with a fix from #649. Can you test the version 4.17.0-dev.headers.read.1? You can find it here: https://www.nuget.org/packages/InfluxDB.Client/4.17.0-dev.headers.read.1.

Copy link

@MD-NG MD-NG Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi thank you for the response. I tested the changes for #649 and it fixed the issue.

{
var request = new RestRequest(path, method);
var request = new RestRequest(path, method)
{
CompletionOption = httpCompletionOption
};

// add path parameter, if any
foreach (var param in pathParams)
Expand Down
7 changes: 5 additions & 2 deletions Client/InfluxDB.Client.Api/Service/QueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Threading;
using RestSharp;
using InfluxDB.Client.Api.Client;
Expand Down Expand Up @@ -1544,9 +1545,11 @@ public RestResponse PostQueryWithIRestResponse(string zapTraceSpan = null, strin
/// <param name="org">Specifies the name of the organization executing the query. Takes either the ID or Name. If both &#x60;orgID&#x60; and &#x60;org&#x60; are specified, &#x60;org&#x60; takes precedence. (optional)</param>
/// <param name="orgID">Specifies the ID of the organization executing the query. If both &#x60;orgID&#x60; and &#x60;org&#x60; are specified, &#x60;org&#x60; takes precedence. (optional)</param>
/// <param name="query">Flux query or specification to execute (optional)</param>
/// <param name="httpCompletionOption">Specify http completion to enable fully stream queries for async.</param>
/// <returns>ApiResponse of string</returns>
public RestRequest PostQueryWithRestRequest(string zapTraceSpan = null, string acceptEncoding = null,
string contentType = null, string org = null, string orgID = null, Query query = null)
string contentType = null, string org = null, string orgID = null, Query query = null,
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
{
var localVarPath = "/api/v2/query";
var localVarPathParams = new Dictionary<string, string>();
Expand Down Expand Up @@ -1621,7 +1624,7 @@ public RestRequest PostQueryWithRestRequest(string zapTraceSpan = null, string a
return Configuration.ApiClient.PrepareRequest(localVarPath,
Method.Post, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams,
localVarFileParams,
localVarPathParams, localVarHttpContentType);
localVarPathParams, localVarHttpContentType, httpCompletionOption);
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions Client/QueryApiSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public interface IQueryApiSync

/// <summary>
/// The synchronous version of QueryApi.
///
/// The client uses <see cref="System.Net.Http.HttpClient"/> to send the request and parse responses to InfluxDB 2.0.
/// The `HttpClient` is supposed to use maximus size of the body to int.MaxValue.
/// If you want to query large data, use <see cref="QueryApi.QueryAsync"/> method.
/// </summary>
public class QueryApiSync : AbstractQueryClient, IQueryApiSync
{
Expand Down Expand Up @@ -139,7 +143,8 @@ public List<T> QuerySync<T>(Query query, string org = null, CancellationToken ca
RestRequest QueryFn(Func<HttpResponseMessage, RestRequest, RestResponse> advancedResponseWriter)
{
return _service
.PostQueryWithRestRequest(null, "application/json", null, optionsOrg, null, query)
.PostQueryWithRestRequest(null, "application/json", null, optionsOrg, null, query,
HttpCompletionOption.ResponseHeadersRead)
.AddAdvancedResponseHandler(advancedResponseWriter);
}

Expand Down Expand Up @@ -191,7 +196,8 @@ public List<FluxTable> QuerySync(Query query, string org = null, CancellationTok
RestRequest QueryFn(Func<HttpResponseMessage, RestRequest, RestResponse> advancedResponseWriter)
{
return _service
.PostQueryWithRestRequest(null, "application/json", null, optionsOrg, null, query)
.PostQueryWithRestRequest(null, "application/json", null, optionsOrg, null, query,
HttpCompletionOption.ResponseHeadersRead)
.AddAdvancedResponseHandler(advancedResponseWriter);
}

Expand Down