From e111367433f89f66e28bc0cd3ebbc47d1e2021d7 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Thu, 13 Feb 2025 14:56:46 +0100 Subject: [PATCH 1/6] fix: 118 query not using proxy (WIP) --- influxdb_client_3/__init__.py | 3 ++- influxdb_client_3/query/query_api.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/influxdb_client_3/__init__.py b/influxdb_client_3/__init__.py index 9097b31..87119e8 100644 --- a/influxdb_client_3/__init__.py +++ b/influxdb_client_3/__init__.py @@ -166,7 +166,8 @@ def __init__( else: connection_string = f"grpc+tcp://{hostname}:{port}" self._query_api = _QueryApi(connection_string=connection_string, token=token, - flight_client_options=flight_client_options) + flight_client_options=flight_client_options, + proxy=kwargs.get("proxy",None)) def write(self, record=None, database=None, **kwargs): """ diff --git a/influxdb_client_3/query/query_api.py b/influxdb_client_3/query/query_api.py index 3b36d20..ad200ed 100644 --- a/influxdb_client_3/query/query_api.py +++ b/influxdb_client_3/query/query_api.py @@ -25,7 +25,8 @@ class QueryApi(object): def __init__(self, connection_string, token, - flight_client_options) -> None: + flight_client_options, + proxy = None) -> None: """ Initialize defaults. @@ -35,9 +36,12 @@ def __init__(self, """ self._token = token self._flight_client_options = flight_client_options or {} + self._proxy = proxy self._flight_client_options["generic_options"] = [ ("grpc.secondary_user_agent", USER_AGENT) ] + if self._proxy: + self._flight_client_options["generic_options"].append(("grpc.http_proxy", self._proxy)) self._flight_client = FlightClient(connection_string, **self._flight_client_options) def query(self, query: str, language: str, mode: str, database: str, **kwargs): From c2f04bd4594dcae8c875c92b9bca4269256973b5 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Thu, 13 Feb 2025 17:30:02 +0100 Subject: [PATCH 2/6] test: add simple unit test for new proxy code (WIP) --- influxdb_client_3/__init__.py | 2 +- tests/test_query.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/influxdb_client_3/__init__.py b/influxdb_client_3/__init__.py index 87119e8..831a406 100644 --- a/influxdb_client_3/__init__.py +++ b/influxdb_client_3/__init__.py @@ -121,7 +121,7 @@ def __init__( possible. :key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128) :key str proxy_headers: A dictionary containing headers that will be sent to the proxy. Could be used for proxy - authentication. + authentication. (Applies to Write API only) :key int connection_pool_maxsize: Number of connections to save that can be reused by urllib3. Defaults to "multiprocessing.cpu_count() * 5". :key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests diff --git a/tests/test_query.py b/tests/test_query.py index 0ad7e3f..213a32b 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -150,3 +150,19 @@ def test_query_with_parameters(self): ) mock_do_get.assert_called_once_with(expected_ticket, ANY) + + def test_query_proxy_base_client(self): + test_proxy = "http://testproxy:5432" + client = InfluxDBClient3( + host="http://localhost:8443", + token="my-token", + org="my-org", + database="my-database", + proxy=test_proxy + ) + + assert client._query_api._proxy == test_proxy + assert ('grpc.http_proxy', test_proxy) in\ + client._query_api._flight_client_options.get('generic_options') + + From a3816a578b25fa032fcd1de49fc6bba56f29b2e6 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Fri, 14 Feb 2025 13:21:11 +0100 Subject: [PATCH 3/6] chore: fix lint issues --- influxdb_client_3/__init__.py | 2 +- influxdb_client_3/query/query_api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/influxdb_client_3/__init__.py b/influxdb_client_3/__init__.py index 831a406..40ab8a4 100644 --- a/influxdb_client_3/__init__.py +++ b/influxdb_client_3/__init__.py @@ -167,7 +167,7 @@ def __init__( connection_string = f"grpc+tcp://{hostname}:{port}" self._query_api = _QueryApi(connection_string=connection_string, token=token, flight_client_options=flight_client_options, - proxy=kwargs.get("proxy",None)) + proxy=kwargs.get("proxy", None)) def write(self, record=None, database=None, **kwargs): """ diff --git a/influxdb_client_3/query/query_api.py b/influxdb_client_3/query/query_api.py index ad200ed..7d03a95 100644 --- a/influxdb_client_3/query/query_api.py +++ b/influxdb_client_3/query/query_api.py @@ -26,7 +26,7 @@ def __init__(self, connection_string, token, flight_client_options, - proxy = None) -> None: + proxy=None) -> None: """ Initialize defaults. From 6817f666a7c0e3197818793fccdb5938cc4e9c36 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Fri, 14 Feb 2025 13:40:20 +0100 Subject: [PATCH 4/6] chore: lint tests as well --- tests/test_query.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_query.py b/tests/test_query.py index 213a32b..1c6ab43 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -164,5 +164,3 @@ def test_query_proxy_base_client(self): assert client._query_api._proxy == test_proxy assert ('grpc.http_proxy', test_proxy) in\ client._query_api._flight_client_options.get('generic_options') - - From e42277f0817ed4b95da36af56141e4596d1971d0 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Tue, 18 Feb 2025 11:02:33 +0100 Subject: [PATCH 5/6] chore: troubleshoot twine changes --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 023f024..866544b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -100,7 +100,7 @@ jobs: name: Checks that the description will render correctly on PyPI. command: | pip install --upgrade pip - pip install twine --user + pip install 'twine>=5.1,<6.1' --user python setup.py sdist bdist_wheel twine check dist/* check-docstyle: From 43ccac52d72df741e365fdd2e16d6f7669dcc487 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Wed, 19 Feb 2025 14:55:09 +0100 Subject: [PATCH 6/6] docs: updating CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0edcb3..c45753f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 1.11.0 [unreleased] +### Bug Fixes + +1. [#119](https://github.com/InfluxCommunity/influxdb3-python/pull/119): Fix use of `proxy` argument in client and query_api to use in channel solution for GRPC proxy. + ## 0.10.0 [2024-11-27] ### Bug Fixes