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: POST query variants serializes 'q' parameter into HTTP body #765

Merged
merged 3 commits into from
Sep 10, 2021

Conversation

bednar
Copy link
Contributor

@bednar bednar commented Aug 27, 2021

Proposed Changes

The query parameter for post variants of query is serialized into HTTP body.

It is usefull when you hit the nginx limit for Request-URI length, eq. HTTP error: 414 Request-URI Too Large.

Following query variants also respects the requiresPost settings:

  1. QueryResult query(Query, TimeUnit)
  2. void query(Query, int, BiConsumer<Cancellable, QueryResult>, Runnable, Consumer<Throwable>)

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • compile-and-test.sh completes successfully
  • Commit messages are in semantic format
  • Sign CLA (if not already signed)

@majst01
Copy link
Collaborator

majst01 commented Aug 27, 2021

Can you update the CI Test matrix with influxdb-2 as well ?

@bednar bednar changed the title feat: streaming query serializes 'q' parameter into HTTP body for InfluxDB 2 feat: streaming query serializes 'q' parameter into HTTP body Aug 27, 2021
@bednar
Copy link
Contributor Author

bednar commented Aug 27, 2021

Can you update the CI Test matrix with influxdb-2 as well ?

Yes I will do. It will be a little bit tricky but I will do my best.

@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2021

Codecov Report

Merging #765 (0b036a8) into master (c0e60d1) will decrease coverage by 4.34%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #765      +/-   ##
============================================
- Coverage     58.45%   54.11%   -4.35%     
+ Complexity      414      383      -31     
============================================
  Files            70       70              
  Lines          2571     2574       +3     
  Branches        269      268       -1     
============================================
- Hits           1503     1393     -110     
- Misses         1002     1116     +114     
+ Partials         66       65       -1     
Impacted Files Coverage Δ
src/main/java/org/influxdb/impl/InfluxDBImpl.java 75.39% <100.00%> (-7.11%) ⬇️
.../influxdb/msgpack/MessagePackConverterFactory.java 0.00% <0.00%> (-100.00%) ⬇️
...uxdb/msgpack/MessagePackResponseBodyConverter.java 0.00% <0.00%> (-100.00%) ⬇️
...ava/org/influxdb/msgpack/QueryResultModelPath.java 0.00% <0.00%> (-90.00%) ⬇️
...ava/org/influxdb/msgpack/MessagePackTraverser.java 0.00% <0.00%> (-87.24%) ⬇️
src/main/java/org/influxdb/dto/Query.java 65.00% <0.00%> (-2.50%) ⬇️
src/main/java/org/influxdb/dto/Point.java 92.97% <0.00%> (+0.82%) ⬆️
...n/java/org/influxdb/impl/InfluxDBResultMapper.java 89.36% <0.00%> (+2.83%) ⬆️
...rc/main/java/org/influxdb/impl/InfluxDBMapper.java 88.57% <0.00%> (+88.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c0e60d1...0b036a8. Read the comment docs.

@bednar
Copy link
Contributor Author

bednar commented Aug 30, 2021

@majst01, InfluxDB 2 compatibility endpoints requires Database and retention policy mapping for queries and writes. So there is no easy way how to use existing test cases with InfluxDB 2.

I've prepared separete test case for InfluxDB 2 - InfluxDB2Test

You can start this testcase by: INFLUXDB_VERSION=2.0 ./compile-and-test.sh

@bednar bednar marked this pull request as ready for review August 30, 2021 14:15
@bednar bednar requested review from majst01 and rhajek August 30, 2021 14:15
compile-and-test.sh Outdated Show resolved Hide resolved
@bednar bednar marked this pull request as draft September 9, 2021 07:34
@bednar bednar changed the title feat: streaming query serializes 'q' parameter into HTTP body feat: query parameter for POST variants is serialized into HTTP body Sep 9, 2021
@bednar bednar force-pushed the feat/query-as-body-for-influxdb-v2 branch from 666ebb5 to 8e425fd Compare September 9, 2021 08:06
@bednar bednar changed the title feat: query parameter for POST variants is serialized into HTTP body feat: POST query variants serializes 'q' parameter into HTTP body Sep 9, 2021
@bednar
Copy link
Contributor Author

bednar commented Sep 9, 2021

@majst01, I had to change how is PR implemented:

  • All query variants respects requiresPost settings on Query
  • POST variants serializes query into HTTP body

Can you review this changes?

Thx

@bednar bednar marked this pull request as ready for review September 9, 2021 08:16
@bednar bednar requested a review from majst01 September 9, 2021 08:16
Copy link
Contributor

@rhajek rhajek left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@majst01 majst01 left a comment

Choose a reason for hiding this comment

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

So, does this mean that influxdb-java is now compatible with influxdb v2 ? If yes this must be reflected in the Readme, currently it says:

Note: This library is for use with InfluxDB 1.x. For connecting to InfluxDB 2.x instances, please use the influxdb-client-java client.

Please adjust accordingly

@bednar
Copy link
Contributor Author

bednar commented Sep 10, 2021

@majst01

So, does this mean that influxdb-java is now compatible with influxdb v2 ?

The influxdb-java is able to use InfluxDB 1.x compatibility API, but this API supports only subset of v1 features, e.g. queries:

image

I think that current text is correct, because the client doesn't supports v2 API.

@majst01
Copy link
Collaborator

majst01 commented Sep 10, 2021

@majst01

So, does this mean that influxdb-java is now compatible with influxdb v2 ?

The influxdb-java is able to use InfluxDB 1.x compatibility API, but this API supports only subset of v1 features, e.g. queries:

image

I think that current text is correct, because the client doesn't supports v2 API.

Understood, but even that must be clarified in the Readme, please add a short description with a link to the official documentation.

@bednar
Copy link
Contributor Author

bednar commented Sep 10, 2021

@majst01, note changed to Note: This library is for use with InfluxDB 1.x and 2.x compatibility API. For full supports of InfluxDB 2.x features, please use the influxdb-client-java client.

@majst01 majst01 merged commit d73aa32 into master Sep 10, 2021
@majst01 majst01 deleted the feat/query-as-body-for-influxdb-v2 branch September 10, 2021 12:34
@majst01
Copy link
Collaborator

majst01 commented Sep 10, 2021

@bednar merged, and now all builds fail ?? Could you please check why.

@majst01
Copy link
Collaborator

majst01 commented Sep 13, 2021

@bednar it still does not compile anymore, please fix this, otherwise i have to revert this

@bednar
Copy link
Contributor Author

bednar commented Sep 13, 2021

@majst01 currently I'am fixing that issue, stay tuned.

The problem is caused by definition of GitHub PRs workflow:

image

All 1.x builds are running agains 1.8...

@bednar
Copy link
Contributor Author

bednar commented Sep 15, 2021

The PR with fix is prepared: #773

@bentatham
Copy link
Contributor

With this change, I am now seeing failures in 2.22 that I didn't see before in 2.21.

missing required parameter "q"

Using InfluxDB 1.8.10.
I don't think I'm doing anything too fancy. Things like this:

BoundedParameterQuery.QueryBuilder
        .newQuery(queryString)
        .forDatabase(database)
        .bind("startTime", startTime)
        .bind("endTime", endTime)
        .create();

(which defaults to requiresPost=true)

Is this expected? What do I need to change?

@bednar
Copy link
Contributor Author

bednar commented May 23, 2022

Hi @bentatham,

can you share a little bit more about your code? How do you initialise the client? How do you run your query?

I just tried following code and everything works fine:

try (InfluxDB client = InfluxDBFactory.connect("http://localhost:8086")) {

  BoundParameterQuery query = QueryBuilder
		  .newQuery("SELECT * FROM cpu WHERE time >= $startTime AND time <= $endTime")
		  .forDatabase("my_database")
		  .bind("startTime", "2015-08-18T00:00:00Z")
		  .bind("endTime", "2015-08-18T00:30:00Z")
		  .create();

  QueryResult result = client.query(query);

  System.out.println("result = " + result);
}

Regards

@bentatham
Copy link
Contributor

@bednar Thanks for getting back to me:

We are using influxDB behind vertx, but I don't think that should really matter unless something in the query object is massively not thread-safe and is consistently hitting a volatility issue or something really obscure.

Initialization:

influxDb = InfluxDBFactory.connect(
            configuration.getUrl().toString(), 
            configuration.getUser(), 
            configuration.getPassword(), 
            new OkHttpClient().newBuilder() 
              .connectTimeout(CONNECT_TIMEOUT_SECONDS_DEFAULT, TimeUnit.SECONDS) 
              .readTimeout(READ_TIMEOUT_SECONDS_DEFAULT, TimeUnit.SECONDS)
              .writeTimeout(WRITE_TIMEOUT_SECONDS_DEFAULT, TimeUnit.SECONDS) 
enableGzip();

Batching is not enabled.

And then invoked with:

influxDb.query(query, TimeUnit.NANOSECONDS)

Maybe something is different about the query that specifies units? (My unit tests still fail with removing that, but that might be because of the units themselves, so I'll keep digging here too.)

@bednar
Copy link
Contributor Author

bednar commented May 25, 2022

@bednar Thanks for getting back to me:

We are using influxDB behind vertx, but I don't think that should really matter unless something in the query object is massively not thread-safe and is consistently hitting a volatility issue or something really obscure.

So the vertx performs as a proxy? Is there a support for query in the HTTP body?

Initialization:

influxDb = InfluxDBFactory.connect(
            configuration.getUrl().toString(), 
            configuration.getUser(), 
            configuration.getPassword(), 
            new OkHttpClient().newBuilder() 
              .connectTimeout(CONNECT_TIMEOUT_SECONDS_DEFAULT, TimeUnit.SECONDS) 
              .readTimeout(READ_TIMEOUT_SECONDS_DEFAULT, TimeUnit.SECONDS)
              .writeTimeout(WRITE_TIMEOUT_SECONDS_DEFAULT, TimeUnit.SECONDS) 
enableGzip();

Batching is not enabled.

I tried it with a direct connection to InfluxDB and everything works fine.

And then invoked with:

influxDb.query(query, TimeUnit.NANOSECONDS)

Maybe something is different about the query that specifies units? (My unit tests still fail with removing that, but that might be because of the units themselves, so I'll keep digging here too.)

It doesn't matter.

@mschwore
Copy link

mschwore commented Jul 1, 2022

I'm seeing the same behavior as @bentatham

I submitted issue !848 describing the problem. It seems to be related (at least for me) to enableGzip being set to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants