Elastic 5 Alpha: Why do Sniffer and HostsSniffer have their own RestClient

When creating a sniffer for the new rest client you need to provider two instances of the RestClient. Should these be different instances with a different configuration? In the next line of code I create a sniffer using two restClient instances.

Sniffer.builder( restClient1 , HostsSniffer.builder( restClient2 ) ).build();

The responsibility of the HostsSniffer is to find the hosts. If I am right, the HostsSniffer uses the provided restClient2 to connect to the cluster and finds the hosts. Than the Sniffer uses the hosts as provided by the HostsSniffer to store them into the restClient1 as given to the Sniffer.

So the question is, should restClient1 be the same as restClient2? If so, why do I need to provide it twice? If not, what is the difference?

Hi Jettro,
sorry for the delay.
You got it right, you have to provide the RestClient twice. The reason for this is that the HostsSniffer is the component that gets the hosts, while the Sniffer is the one that sets the hosts (calls RestClient#setHosts). In the ordinary usecase the REST client instance is the same in both cases. It could happen though that HostsSniffer is a custom one and takes hosts from somewhere else (not even an es cluster potentially) hence why the separation. I will see if I can add a simpler way to create the needed objects for the ordinary usecase though.

Thanks for raising this

Cheers
Luca

Hi Jettro,
I pushed this: https://github.com/elastic/elasticsearch/pull/19599 .

It simplifies the Sniffer creation for the general usecase:

Sniffer sniffer = Sniffer.builder(restClient).build();

then the HostsSniffer gets automatically created against that same client. It is still possible to provide a HostsSniffer in case the default configuration has to be changed or the impl needs to be different:

Sniffer sniffer = Sniffer.builder(restClient).setHostsSniffer(new ElasticsearchHostsSniffer(restClient, 5000, "https")).build();

Cheers
Luca

Nice, I like it.