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
Use Elasticsearch cluster health for check instead of ping #290
Conversation
Ping will only allow to return healthy or unhealthy statuses. By using Elasticsearch Cluster Health API [1] we can also return degraded if the cluster is in yellow state. Note that I needed to convert the cluster status to a string instead of using Elasticsearch.Net.Health enum, as otherwise we would need to add a reference to the Elasticsearch.Net NuGet package. 1: https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html
@unaizorrilla as discussed in #287 I've started a PR. It isn't ready yet for final review, but I wanted to start showing the direction I'm taking. One thing I noticed is that the functional tests for this are ok, but not enough for this new kind of check, and then come to the realization that properly testing might involve some tweaking of version: '3'
services:
elasticsearch_red:
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
ports:
- 19200:9200
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- node.master=true
- node.data=false
- discovery.type=single-node
- discovery.zen.minimum_master_nodes=2
- xpack.security.enabled=false
elasticsearch_green:
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
ports:
- 19201:9200
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- node.master=true
- node.data=true
- discovery.type=single-node
- discovery.zen.minimum_master_nodes=1
- xpack.security.enabled=false
elasticsearch_yellow:
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
ports:
- 19202:9200
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- node.master=true
- node.data=true
- discovery.type=single-node
- xpack.security.enabled=false This is not enough, as for the yellow server I also need to run One idea that I have for testing this is that instead of using an Elasticsearch Docker image we could add a mock HTTP server to the tests that return the different payloads Elasticsearch Cluster Health API sends. That will make it easier to setup and run the tests, though it might make the tests a bit more complex on their setup. What do you think? |
By default the option is false, meaning it will use ping as it was previously doing. If the user wants advanced health check they can call this method which will instruct ElasticsearchHealthCheck to use the Cluster Health API instead. See parent commit for more information.
123990f
to
faea6ce
Compare
These new tests don't need a running Elasticsearch instance but rather create a mock HTTP server that will send back responses in the same format as Elasticsearch Cluster Health API does.
Hi @inkel Let me some days to review this PR |
@unaizorrilla I've added the tests without needing to spawn Elasticsearch demons but rather mocking an HTTP server that returns the same payload as Cluster Health API. Please check commit 9220378 and let me know what you think. Nevertheless, I think this is ready for review! |
@Xabaril hi! I've just pushed some updates with tests for the new functionality. Yes, please, take as long as you need! And thank you for publishing all these packages, we are using it at my company and they are wonderful, they just work 😸 I do have more PRs in mind, though, I hope you don't mind 😬 |
🤔 AppVeyor tests are failing due to not finding a right .NET framework:
|
This was for debugging purposes.
Let me check appveyor because is now failing and we don't change anything, the same build that works some days ago is failing now! 👎 |
Hi @inkel I think the issue is related with microsoft/vstest#2189 , I'm trying to solve it asap! |
I think there is a bug on Microsoft.Net.Test.Sdk 16.3.0 , downgrade to 16.2.0 build is working again! I try to review PR asap |
@unaizorrilla any comments on this one? |
Hi @inkel we try to review and merge it asap |
Do not unnecessarily assigned a default value that's equal to the zero value of a boolean. Co-Authored-By: Ivan Maximov <sungam3r@yandex.ru>
Thanks @sungam3r for the suggestion! |
Hi, are there any updates on this? |
Hi! Sorry for being pushy, but is there any update on this one? |
Hi @sungam3r! I'm not working with # anymore at the moment, and I've even left the company I was working at the time we needed this merged. I'd love to see the changes integrated as I think it's the right way to have a health check on Elasticsearch, but I cannot make any changes to this branch nor help maintaining it. |
Covered by #1577 . |
Oh wow, what a blast from the past seeing action in this PR. I'm glad this is now covered. |
As stated in #287, using ping will only allow returning healthy or unhealthy statuses. By using
Elasticsearch Cluster Health API we can also return degraded if the cluster is in the yellow state.
While implementing this I realized that for some use cases users won't need to check for degraded, so to keep backwards dependency I've added a new option method
ElasticsearchOptions
to enable using cluster health check:By default, it will use the original ping check.