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

Add preflight check on Elasticsearch before connecting #1026

Conversation

andsel
Copy link
Contributor

@andsel andsel commented Jul 14, 2021

Update client behavior to match functionality of 7.14+


Tasks

  • change error message from LogStash::ConfigurationError: Not a valid Elasticsearch to could not connect to a compatible version of Elasticsearch

@andsel andsel changed the title Feature/add elasticsearch check before connecting Add preflight check on Elasticsearch before connecting Jul 14, 2021
@andsel andsel marked this pull request as draft July 15, 2021 07:25
@andsel andsel force-pushed the feature/add_elasticsearch_check_before_connecting branch from 2c6d745 to ff08c78 Compare July 15, 2021 15:28
@andsel
Copy link
Contributor Author

andsel commented Aug 17, 2021

The red CI on case:

INTEGRATION=true 
ELASTIC_STACK_VERSION=8.x 
SNAPSHOT=true

Is due to security "on" by default in 8.0.0. It doesn't depend on this PR, but could be solved disabling the security.
Add to .ci/Dockerfile.elasticsearch the line:

RUN echo "xpack.security.enabled: false" >> $es_yml

@andsel andsel marked this pull request as ready for review September 3, 2021 15:13
@andsel andsel requested a review from yaauie September 3, 2021 15:42
@andsel andsel force-pushed the feature/add_elasticsearch_check_before_connecting branch from 6ca5c67 to 46d6835 Compare September 7, 2021 16:15
@roaksoax roaksoax requested a review from jsvd September 21, 2021 14:42
Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

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

I believe we can simplify the healthcheck process by reducing the number of calls to ES, and always performing the product check, which shouldn't have a performance impact.

lib/logstash/outputs/elasticsearch/http_client/pool.rb Outdated Show resolved Hide resolved
# Try to keep locking granularity low such that we don't affect IO...
@state_mutex.synchronize { @url_info.select {|url,meta| meta[:state] != :alive } }.each do |url,meta|
begin
health_check_request(url)

# when called from resurrectionist skip the product check done during register phase
if register_phase
Copy link
Member

Choose a reason for hiding this comment

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

This makes me wonder if we could just make the elasticsearch? check everytime instead of HEAD'ing the /?

Right after we do HEAD then we request '/' in es_version = get_es_version(url).

With this change we'll be doing 4 requests to ES:

  1. HEAD request
  2. GET '/' for elasticsearch? on register_phase
  3. GET '/' to get elasticsearch version
  4. GET '/_license'

We can just do instead:

  1. GET '/' for healthcheck (and always confirm it's ES)
  2. GET '/_license'

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 agree with you, I think that point 2 and 3 could be merged or at least do one one HTTP GET call to /.
About the HTTP HEAD, that call could use a customized path from configuration (healthcheck_path) that some users could have customized. If we drop the HEAD call is like ignoring that setting and we should remove it.
I'm ok with removing the HEAD call, because actually seems to be used just to ping the server for reachability and then it immediately send a GET.
We could split this work in 2 steps:

  • first collapse the GET call for point 2 and 3
  • create a follow-up PR to drop the HEAD call and deprecate the healthcheck_path param

Copy link
Member

Choose a reason for hiding this comment

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

create a follow-up PR to drop the HEAD call and deprecate the healthcheck_path param

It's fine if there's only an issue instead to track the goal of reducing the number of network calls for a healthcheck.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened #1043 to track this feature

lib/logstash/outputs/elasticsearch/http_client/pool.rb Outdated Show resolved Hide resolved
Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

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

other than a few cosmetic refactors the change LGTM but we need a better error message, just like in the ES input and filter.

@andsel andsel force-pushed the feature/add_elasticsearch_check_before_connecting branch from d46c39b to e590e04 Compare September 29, 2021 15:45
@andsel andsel force-pushed the feature/add_elasticsearch_check_before_connecting branch from ee6fb44 to 83d644d Compare October 1, 2021 07:22
@andsel andsel requested a review from jsvd October 4, 2021 09:05
Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

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

LGTM only minor nitpick

lib/logstash/outputs/elasticsearch/http_client/pool.rb Outdated Show resolved Hide resolved
# Try to keep locking granularity low such that we don't affect IO...
@state_mutex.synchronize { @url_info.select {|url,meta| meta[:state] != :alive } }.each do |url,meta|
begin
health_check_request(url)

# when called from resurrectionist skip the product check done during register phase
if register_phase
Copy link
Member

Choose a reason for hiding this comment

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

create a follow-up PR to drop the HEAD call and deprecate the healthcheck_path param

It's fine if there's only an issue instead to track the goal of reducing the number of network calls for a healthcheck.

Co-authored-by: João Duarte <[email protected]>
@andsel andsel merged commit 3a170cf into logstash-plugins:master Oct 12, 2021
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.

3 participants