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

Added possibility to reuse client as a core part of Reactive client #493

Merged
merged 6 commits into from
Sep 6, 2018

Conversation

bednar
Copy link
Contributor

@bednar bednar commented Aug 22, 2018

This PR solve #392 by adding possibility to reuse influxdb-java client as a core part of influxdb-java-reactive - Reactive Java client for InfluxDB.

Summary of changes

The InfluxDBImpl constructor has parameter for customise Retrofit.Builder. That builder is use in influxdb-java-reactive client for create reactive version of InfluxDBService.

* The InfluxDBImpl constructor has parameter for customise Retrofit.Builder. That builder is use in influxdb-java-reactive client for create reactive version of InfluxDBService.
* The InfluxDBResultMapper is able to handle results which a different time precision
* The InfluxDBResultMapper is able to map Integer to Instant
@codecov-io
Copy link

codecov-io commented Aug 22, 2018

Codecov Report

Merging #493 into master will increase coverage by 0.15%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #493      +/-   ##
============================================
+ Coverage     87.53%   87.69%   +0.15%     
- Complexity      365      368       +3     
============================================
  Files            25       25              
  Lines          1500     1503       +3     
  Branches        167      167              
============================================
+ Hits           1313     1318       +5     
  Misses          120      120              
+ Partials         67       65       -2
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/influxdb/impl/InfluxDBImpl.java 89.89% <100%> (+0.08%) 79 <1> (+1) ⬆️
src/main/java/org/influxdb/InfluxDBException.java 94.54% <0%> (+3.63%) 14% <0%> (+2%) ⬆️

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 24c5542...e6c9ad2. Read the comment docs.

@majst01
Copy link
Collaborator

majst01 commented Aug 24, 2018

Hi @bednar

You are solving 3 Issues with one PR, from my understanding only your first point is related to rxjava.

We only want to have PR´s which are focused on one single Issue.

If i am wrong can you please elaborate more details.

@bednar
Copy link
Contributor Author

bednar commented Aug 24, 2018

Hi @majst01,

Yes, you are right.

During implementation the reactive client I found two issues with InfluxDBResultMapper:

  • InfluxDBResultMapper is not able to handle results which a different time precision then milliseconds
  • InfluxDBResultMapper is not able to map Integer to Instant

I will split the current PR to three pull requests:

  1. The InfluxDBResultMapper is able to map Integer to Instant
  2. The InfluxDBResultMapper is able to handle results which a different time precision
  3. Added possibility to reuse client as a core part of Reactive client

It will be ok for you?

Copy link
Contributor

@fmachado fmachado left a comment

Choose a reason for hiding this comment

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

These were my comments that I incorrectly gave on the wrong PR from bonitoo and now moved to here.

@@ -146,7 +169,7 @@ public InfluxDBImpl(final String url, final String username, final String passwo
break;
}

this.retrofit = new Retrofit.Builder().baseUrl(url).client(
this.retrofit = retrofitBuilder.baseUrl(url).client(
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a heads up: you may have here ConcurrentModificationException as you are adding a converterFactory to a shared and non thread-safe retrofitBuilder. Worst case scenatio if you don't trigger a CME, you will end up having multiple converterFactory added to the internal list in retrofitBuilder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. It could cause same errors as in #445, so I will use same approach to avoid potential problems:

Retrofit.Builder clonedRetrofitBuilder = retrofitBuilder.baseUrl(url).build().newBuilder();
this.retrofit = clonedRetrofitBuilder.client(clonedOkHttpBuilder.build())
            .addConverterFactory(converterFactory).build();

@@ -152,7 +202,7 @@ void throwExceptionIfResultWithError(final QueryResult queryResult) {
});
}

void cacheMeasurementClass(final Class<?>... classVarAgrs) {
public void cacheMeasurementClass(final Class<?>... classVarAgrs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert the access modifier from this method on this class and from all methods from other classes to the minimum required. There is no need to make this method public.

return ((Measurement) clazz.getAnnotation(Measurement.class)).name();
}

public <T> ConcurrentMap<String, Field> getColNameAndFieldMap(final Class<T> clazz) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to have this method: you are not mocking it and now you are exposing an internal structure publicly to the external code, allowing it to be changed. Please, revert this change.

@@ -263,9 +324,11 @@ String getMeasurementName(final Class<?> clazz) {
if (value instanceof String) {
instant = Instant.from(ISO8601_FORMATTER.parse(String.valueOf(value)));
} else if (value instanceof Long) {
instant = Instant.ofEpochMilli((Long) value);
instant = Instant.ofEpochMilli(toMillis((Long) value, precision));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please do a tinny improvement here by casting to primitives instead of Object wrappers? If you do, then please change the method signature from toMillis(final Long value, ... to toMillis(final long value, ... (just to avoid unboxing).

@bednar
Copy link
Contributor Author

bednar commented Aug 28, 2018

@fmachado I made the required changes. Can you check it?

@majst01
Copy link
Collaborator

majst01 commented Aug 28, 2018

Hi @bednar

This PR still modifies around precision handling, and instantiation of a new influxdb service. I doubt these are all related to the usage in a reactive environment.

As long as we have mixed modifications in this PR we will not accept that.

@bednar
Copy link
Contributor Author

bednar commented Aug 28, 2018

Hi @majst01, thanks for response.

Today, I will create separate PR for handling precision and leave this PR only for instantiation of a new InfluxDB service.

@ivankudibal ivankudibal added this to the 2.13 milestone Aug 28, 2018
@bednar
Copy link
Contributor Author

bednar commented Aug 28, 2018

Hi @majst01, @fmachado

I created pull request (#501) for the InfluxDBResultMapper precision issue and also changed description of current PR to reflect changes.

Thanks for your reviews

@@ -126,7 +126,7 @@ public boolean isRetryWorth() {
}
}

private static InfluxDBException buildExceptionFromErrorMessage(final String errorMessage) {
public static InfluxDBException buildExceptionFromErrorMessage(final String errorMessage) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why public, if you want to test this like below, write the test in the matching package.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a changelog.md entry with pointers where the usage of influxdb-java in a reactive environment is shown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I want to reuse this method in influxdb-java-reactive to parse errors from HTTP header X-Influx-Error. If its is a problem I can use something like this:

String errorBody = String.format("{\"error\":\"%s\"}", errorHeader);

Can I let this method public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CHANGELOG.md was updated.

@bednar
Copy link
Contributor Author

bednar commented Aug 29, 2018

Hi @majst01,

I changed method InfluxDBException#buildExceptionFromErrorMessage to private.

Thanks for your review

@majst01 majst01 merged commit 490fb25 into influxdata:master Sep 6, 2018
@bednar bednar deleted the reactive-pull-request branch October 1, 2018 06:44
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

5 participants