api/views/health.py constructs a new Elasticsearch client on every call:
es_settings = settings.ELASTICSEARCH_DSL["default"]
es = Elasticsearch(hosts=es_settings["hosts"], http_auth=es_settings["http_auth"])
if es.ping():
Visible in the logs as a new TCP connection each time:
{"event": "Starting new HTTP connection (1): elasticsearch:9200"}
{"event": "http://elasticsearch:9200 \"HEAD / HTTP/1.1\" 200 0"}
Why it is worth fixing
/health/ is called by the Docker healthcheck, the deploy gate in scripts/ci-deploy.sh, and any external monitoring — so this is a fresh connection several times a minute, forever, to send one HEAD /.
Measured cost is small (the ping itself is ~0.14s, and the endpoint answers in ~0.04s on-box), so this is efficiency and log noise rather than a performance problem.
It also emits a DeprecationWarning on every call:
The 'http_auth' parameter is deprecated. Use 'basic_auth' or 'bearer_auth' parameters instead
Suggested
- Reuse a module-level client, or the one
django-elasticsearch-dsl already configures, instead of building one per request.
- Move
http_auth to basic_auth while there.
Worth keeping the check itself: it is what makes /health/ return 503 when Elasticsearch is down, which the deploy gate depends on. Only the per-request construction should change.
Low priority. Related: the health check's database probe was fixed in #140 to open a fresh connection deliberately — that one is intentional and should stay.
api/views/health.pyconstructs a new Elasticsearch client on every call:Visible in the logs as a new TCP connection each time:
Why it is worth fixing
/health/is called by the Docker healthcheck, the deploy gate inscripts/ci-deploy.sh, and any external monitoring — so this is a fresh connection several times a minute, forever, to send oneHEAD /.Measured cost is small (the ping itself is ~0.14s, and the endpoint answers in ~0.04s on-box), so this is efficiency and log noise rather than a performance problem.
It also emits a
DeprecationWarningon every call:Suggested
django-elasticsearch-dslalready configures, instead of building one per request.http_authtobasic_authwhile there.Worth keeping the check itself: it is what makes
/health/return 503 when Elasticsearch is down, which the deploy gate depends on. Only the per-request construction should change.Low priority. Related: the health check's database probe was fixed in #140 to open a fresh connection deliberately — that one is intentional and should stay.