petercheon commented on code in PR #66065:
URL: https://github.com/apache/airflow/pull/66065#discussion_r3223383271
##########
providers/elasticsearch/src/airflow/providers/elasticsearch/hooks/elasticsearch.py:
##########
@@ -135,9 +136,9 @@ def __init__(
netloc = f"{host}:{port}"
self.url = parse.urlunparse((scheme, netloc, "/", None, None, None))
if user and password:
- self.es = Elasticsearch(self.url, basic_auth=(user, password),
**kwargs)
+ self.es = apply_compat_with(Elasticsearch(self.url,
basic_auth=(user, password), **kwargs))
Review Comment:
> I checked the Elasticsearch hook file. The ESConnection constructor
creates a single Elasticsearch instance assigned to self.es. Therefore
apply_compat_with(Elasticsearch(...)) wraps that single client in place and
does not create two clients. If you found another site that builds two clients
please point me to the file and line and I will patch it. Otherwise this looks
fine to me.
Thanks @Subham-KRLX. Audited every `Elasticsearch(` construction site in
the provider — there are four (one site uses an if/else branch internally, so
it counts as a single logical construction per call):
| Class | File:line | Form |
|---|---|---|
| `ESConnection.__init__` |
`providers/elasticsearch/src/airflow/providers/elasticsearch/hooks/elasticsearch.py:139,141`
| `apply_compat_with(Elasticsearch(...))` (auth / no-auth branches, mutually
exclusive) |
| `ElasticsearchPythonHook._get_elastic_connection` |
`providers/elasticsearch/src/airflow/providers/elasticsearch/hooks/elasticsearch.py:251`
| `apply_compat_with(Elasticsearch(...))` |
| `ElasticsearchTaskHandler.__init__` |
`providers/elasticsearch/src/airflow/providers/elasticsearch/log/es_task_handler.py:273`
| `apply_compat_with(elasticsearch.Elasticsearch(...))` |
| `ElasticsearchRemoteLogIO.__init__` |
`providers/elasticsearch/src/airflow/providers/elasticsearch/log/es_task_handler.py:655`
| `apply_compat_with(elasticsearch.Elasticsearch(...))` |
Every site constructs the client exactly once and hands it to
`apply_compat_with`, which mutates `client.transport.perform_request` in place
and returns the same instance. There are no other construction sites in the
provider. Thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]