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

Elasticsearch low and high level REST clients #8290

Conversation

loicmathieu
Copy link
Contributor

This PR integrates the Elasticsearch low level rest client inside Quarkus.

It creates a new extension that allows to configure a connection to Elasticsearch inside application.properties and inject a RestClient.

The configuration properties has the same semantics as the one from the Hibernate search extension.

This is a draft PR, some works still needs to be done around configuration and documentation.

@gsmet gsmet self-assigned this Mar 31, 2020
@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from d160efa to 538ac17 Compare March 31, 2020 09:35
@boring-cyborg boring-cyborg bot added area/dependencies Pull requests that update a dependency file area/documentation area/infra-automation anything related to CI, bots, etc. that are used to automated our infrastructure labels Mar 31, 2020
@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from 538ac17 to da53ae6 Compare March 31, 2020 09:51
@loicmathieu loicmathieu requested a review from gsmet April 3, 2020 07:53
@loicmathieu
Copy link
Contributor Author

@gsmet the fact that a user can not easily use the high level rest client bother me a lot, I found a way to allow this without providing support for it: we can add the RestClientBuilder as a CDI bean so if someone still want to use the high level rest client he can do something like this:

@Inject RestClientBuilder restClientBuilder;
private HighLevelRestClient highLevelRestClient;

@PostConstruct
void init() {
    highLevelRestClient = new HighLevelRestClient(restClientBuilder);
}

WDYT

@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch 2 times, most recently from 28d9667 to b39d064 Compare April 3, 2020 08:47
@gsmet
Copy link
Member

gsmet commented Apr 6, 2020

Cool stuff.

I haven't reviewed in details (expect a thorough review at some point ;)) but I have a few questions:

  • wouldn't it be possible to include that in the existing extension without it being an issue for the current usage by the Hibernate Search extension? That would solve the name issue.
  • should we allow connecting to multiple clusters from the get go?

As for the high level client, I don't have a problem having a separate extension for it. We would need to check how it behaves with native image though. And maybe we could be a bit aggressive with exclusions (maybe it doesn't need Lucene typically).

I agree exposing the builder as a CDI bean looks neat and would be useful in all cases.

@loicmathieu
Copy link
Contributor Author

wouldn't it be possible to include that in the existing extension without it being an issue for the current usage by the Hibernate Search extension? That would solve the name issue.

It should be possible, as CDI beans will be removed automatically, if not used we can produce them without any issue. The main issue is that hibernate-search users will start seeing an elasticsearch-rest-client extension and will be able to configure it, and the configuration may seems redondant to them as to be able to inject a RestClient they will need to configure Elasticsearch under quarkus.elasticsearch root configuration.

But we should be able to rename the current hidden extension to elasticsearch-core as it's not a user facing extension right ?

@loicmathieu
Copy link
Contributor Author

should we allow connecting to multiple clusters from the get go?

As you want, it's a common feature request for database extension but I don't know of often it is for Elasticsearch

@loicmathieu
Copy link
Contributor Author

As for the high level client, I don't have a problem having a separate extension for it. We would need to check how it behaves with native image though. And maybe we could be a bit aggressive with exclusions (maybe it doesn't need Lucene typically).

I agree exposing the builder as a CDI bean looks neat and would be useful in all cases.

It's either way ;)

An other approach would be to propose a PR to the Elasticsearch driver to be able to create a hig level rest client from a low level one ;)

@loicmathieu
Copy link
Contributor Author

@gsmet I think again at providing connection to multiple clusters. I would prefere to merge this PR without it and opening an Epic that list what we want to support on Elasticsearch: multi-tenant, metrics, investigation of hibernate-search-standalone or Panache, ... The idea is to build our Elasticsearch support in steps.

We can then decide what will be the minimum level of support before we document it and integrate the extension inside code.quarkus.io so it becomes visible to users.

@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from b39d064 to 5fb6414 Compare April 7, 2020 11:10
@boring-cyborg boring-cyborg bot added the area/hibernate-search Hibernate Search label Apr 7, 2020
@loicmathieu
Copy link
Contributor Author

Added the high level client as a separate extension (didn't update the guide yet).

I move the health check to the common extension to be able to use it in both, maybe we can find a way to use it with hibernate-search-elasticsearch also ;)

I have an issue with a banned dependency : log4j2 is banned but the corresponding bridge from jboss-logmanager is not publushed in maven central: https://github.com/jboss-logging/log4j2-jboss-logmanager. I customize the configuration of the enforcer plugin for now but it's temporary ...

@loicmathieu
Copy link
Contributor Author

loicmathieu commented Apr 8, 2020

I refactor the code to share code between the two clients.

I implement more configuration options + the sniffer.

I integrate the high level client inside the documentation.

@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from 6f82a21 to c8d920f Compare April 9, 2020 09:43
@loicmathieu loicmathieu marked this pull request as ready for review April 9, 2020 09:44
@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from c8d920f to f50f0ca Compare April 13, 2020 10:48
@loicmathieu
Copy link
Contributor Author

I remove all the un-needed dependencies from lucene, I use Jdeps to know which one are needed, then I add back the one that are needed for native-image to works (see the comment inside the pom).

@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from f50f0ca to cc9f761 Compare May 15, 2020 10:04
@loicmathieu
Copy link
Contributor Author

@gsmet I rebased on master to fix some merge issues.

I would love this PR to be considered for 1.5 if it's still possible ?

@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from cc9f761 to b87311d Compare June 8, 2020 10:49
Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

I added some comments, mostly in the documentation. Didn't have the time to finish the review before going on PTO, sorry about that :/.

On a more general note, I would go with:

  • quarkus-elasticsearch-rest-client-common for the existing extension
  • quarkus-elasticsearch-rest-client for the low level client
  • quarkus-elasticsearch-rest-high-level-client for the high level client

That way, we would be consistent with the Elasticsearch clients.

<artifactId>elasticsearch-rest-high-level-client</artifactId>
<!-- We exclude all lucene libraries that are not needed -->
<!-- Jdeps shows that only lucene-core and lucene-queries are needed-->
<!-- Native image needs also lucene-highlighter and lucene-join -->
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could add substitutions to remove the need for them. I'm pretty sure they are not really useful.

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'll open a followup issue for this if it's OK.

Copy link
Member

Choose a reason for hiding this comment

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

Sure.

@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from 4827ff4 to c5b832b Compare June 25, 2020 10:03
@loicmathieu
Copy link
Contributor Author

@gsmet I renamed the three extensions, apply your suggestions and implements most of what you ask.
There is still 3 open points that needs your feedback.

@loicmathieu
Copy link
Contributor Author

@gsmet due to the change that mandates that an extension runtime module depending on another extension mandate that the extension's deployment module also depands on another extension deployment's module, this PR needs to be re-worked.

I think I must create another common module to share the code between the two clients.

So I propose to rename the just renammed elasticsearch-rest-client-common that is shared with Hibernate Search elasticsearch-common and create another module named elasticsearch-rest-client-common with the code shared between the two clients.

@gsmet
Copy link
Member

gsmet commented Jul 1, 2020

As for the split, let me some time to think about it and check the code. I'm a bit puzzled why we cannot have both the deployment of the low level client and the high level client running at the same time as one is based on the other.

I will have a closer look before the end of the week.

@loicmathieu
Copy link
Contributor Author

@gsmet I try to move all the common part to the common module and it works and it didn't crash hibernate-search that also use the common module so it appears to be safe.

The only caveat is that I also move the config to the common module as both client uses the same config (but I can duplicate it). I don't know if it's an issue as hibernate-search didn't use the same configuration options, and those options are not used inside the common module.

@gsmet
Copy link
Member

gsmet commented Jul 6, 2020

I don't think that's a good idea.

For me, here's what it's supposed to do:

  • the low level REST client creates a shared low level REST client from the config that is in this very module
  • the high level REST client reuses the instance above

This way you don't have to do all sorts of weird things: the low level and high level extensions fully co-exist as the latter is based on the former.

One interesting thing is that the javadoc RestHighLevelClient recommends to subclass it if you want to inject an already built low level client and I think that's what we should do.

Note that even if we subclass it, we should just expose it as a RestHighLevelClient so that users just use this class for injection.

Does it make sense?

@gsmet gsmet changed the title Elasticsearch low level rest client Elasticsearch low and high level REST clients Jul 6, 2020
@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch 5 times, most recently from cc89595 to cc63165 Compare July 7, 2020 11:22
@loicmathieu
Copy link
Contributor Author

@gsmet I restructure the code to reuse the rest client inside the high level one.
I also fix the issue with log4j2.

@@ -1,4 +1,4 @@
# quarkus-integration-test-elasticsearch project
# quarkus-integration-test-elasticsearch-rest-client project
Copy link
Member

Choose a reason for hiding this comment

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

Aren't you missing high-level here and below? Not sure as GH UI is doing weird things with those files but better check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, bad copy/paste. Fixed.

@loicmathieu loicmathieu force-pushed the feat/elasticsearch-low-level-client branch from cc63165 to d562e83 Compare July 7, 2020 13:56
@gsmet
Copy link
Member

gsmet commented Jul 8, 2020

I extracted part of the log4j2 fix here: #10560 as I want to backport it and I need it for a Platform related thingy.

@gsmet
Copy link
Member

gsmet commented Jul 21, 2020

Superseded by #10745 .

@gsmet gsmet closed this Jul 21, 2020
@gsmet gsmet added the triage/invalid This doesn't seem right label Jul 21, 2020
@loicmathieu loicmathieu deleted the feat/elasticsearch-low-level-client branch July 22, 2020 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependencies Pull requests that update a dependency file area/documentation area/hibernate-search Hibernate Search area/infra-automation anything related to CI, bots, etc. that are used to automated our infrastructure triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants