diff --git a/esrally/client/asynchronous.py b/esrally/client/asynchronous.py index fdb5c0314..9cd655eb0 100644 --- a/esrally/client/asynchronous.py +++ b/esrally/client/asynchronous.py @@ -267,6 +267,7 @@ def _create_aiohttp_session(self): cookie_jar=aiohttp.DummyCookieJar(), request_class=self._request_class, response_class=self._response_class, + trust_env=True, connector=connector, trace_configs=self.trace_configs, ) diff --git a/esrally/client/synchronous.py b/esrally/client/synchronous.py index 29d6babfc..d0dc63fea 100644 --- a/esrally/client/synchronous.py +++ b/esrally/client/synchronous.py @@ -15,6 +15,8 @@ # specific language governing permissions and limitations # under the License. +import logging +import os import warnings from collections.abc import Iterable, Mapping from typing import Any, Optional @@ -25,6 +27,7 @@ HeadApiResponse, ListApiResponse, ObjectApiResponse, + RequestsHttpNode, TextApiResponse, ) from elastic_transport.client_utils import DEFAULT @@ -123,9 +126,17 @@ def check_product(cls, headers, response): class RallySyncElasticsearch(Elasticsearch): def __init__(self, *args, **kwargs): + self.logging = logging.getLogger(__name__) distribution_version = kwargs.pop("distribution_version", None) distribution_flavor = kwargs.pop("distribution_flavor", None) - super().__init__(*args, **kwargs) + proxy_env_vars = ["http_proxy", "https_proxy", "HTTP_PROXY", "HTTPS_PROXY", "all_proxy", "ALL_PROXY"] + if any(x in os.environ for x in proxy_env_vars): + # If we have proxy env vars, we need to use the requests transport + # to ensure that we use the correct proxy settings. + self.logging.warning("Proxy settings detected. Using requests transport.") + super().__init__(*args, node_class=RequestsHttpNode, **kwargs) + else: + super().__init__(*args, **kwargs) self._verified_elasticsearch = None self.distribution_version = distribution_version self.distribution_flavor = distribution_flavor