Repository navigation
fix(health): keep the API in the pool when Elasticsearch is down (#2667) - #2699
Merged
Merged
Conversation
## Changes 1. health.py: an ES failure no longer turns /health into a 500. This matches how Redis was already handled. ES is still reported as "es": "error" in the body and the exception is still logged. Only PostgreSQL (500) and maintenance mode (404) still take a server out of the pool. 2. errors.py: UnexpectedErrorMiddleware now catches elasticsearch.exceptions.ConnectionError (this also covers connection timeouts). It answers 503 "search unavailable / please retry later" and logs one error line instead of a full traceback. Other errors still answer 500. 3. test_health.py: new test_es_down points the client at an unreachable ES. It checks that /health answers 200 with es == 'error', and that a filtered /outings listing answers 503. Closes #2667
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2667
What I reproduced (ES stopped on the local dev stack)
GET /health"es":"error"and"es_indexed_docs":nullGET /outings/{id}?cook=fr(what the outing page calls)GET /outings?act=…,/search?q=…Opening a document never needed ES: those reads come from PostgreSQL. The real problem was
/health. HAProxy probes it, and it answered 500 whenever ES failed. Every API container uses the same ES cluster, so they all fail the probe together and HAProxy removes the whole pool. After that, every page breaks, including/outings/1964309. TheKeyErrorin the issue was one such ES failure (already fixed by #2666), but any ES outage had the same effect.Changes
web/health.py: an ES failure no longer turns/healthinto a 500. This matches how Redis was already handled. ES is still reported as"es": "error"in the body and the exception is still logged. Only PostgreSQL (500) and maintenance mode (404) still take a server out of the pool.web/errors.py:UnexpectedErrorMiddlewarenow catcheselasticsearch.exceptions.ConnectionError(this also covers connection timeouts). It answers 503search unavailable / please retry laterand logs one error line instead of a full traceback. Other errors still answer 500.tests/views/test_health.py: newtest_es_downpoints the client at an unreachable ES. It checks that/healthanswers 200 withes == 'error', and that a filtered/outingslisting answers 503.The 5 health tests pass, and ruff check and format are clean. I didn't run the full test suite.
Notes
/healthno longer turns red when ES is down. Alerting should readesin the JSON body instead of the HTTP status.