Skip to content

Commit 8028386

Browse files
authored
Merge pull request #119 from InfluxCommunity/fix/118-grpc-proxy
fix: 118 - query not using proxy
2 parents 5739de0 + 43ccac5 commit 8028386

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
name: Checks that the description will render correctly on PyPI.
101101
command: |
102102
pip install --upgrade pip
103-
pip install twine --user
103+
pip install 'twine>=5.1,<6.1' --user
104104
python setup.py sdist bdist_wheel
105105
twine check dist/*
106106
check-docstyle:

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 1.11.0 [unreleased]
44

5+
### Bug Fixes
6+
7+
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.
8+
59
## 0.10.0 [2024-11-27]
610

711
### Bug Fixes

influxdb_client_3/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __init__(
121121
possible.
122122
:key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128)
123123
:key str proxy_headers: A dictionary containing headers that will be sent to the proxy. Could be used for proxy
124-
authentication.
124+
authentication. (Applies to Write API only)
125125
:key int connection_pool_maxsize: Number of connections to save that can be reused by urllib3.
126126
Defaults to "multiprocessing.cpu_count() * 5".
127127
:key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests
@@ -166,7 +166,8 @@ def __init__(
166166
else:
167167
connection_string = f"grpc+tcp://{hostname}:{port}"
168168
self._query_api = _QueryApi(connection_string=connection_string, token=token,
169-
flight_client_options=flight_client_options)
169+
flight_client_options=flight_client_options,
170+
proxy=kwargs.get("proxy", None))
170171

171172
def write(self, record=None, database=None, **kwargs):
172173
"""

influxdb_client_3/query/query_api.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class QueryApi(object):
2525
def __init__(self,
2626
connection_string,
2727
token,
28-
flight_client_options) -> None:
28+
flight_client_options,
29+
proxy=None) -> None:
2930
"""
3031
Initialize defaults.
3132
@@ -35,9 +36,12 @@ def __init__(self,
3536
"""
3637
self._token = token
3738
self._flight_client_options = flight_client_options or {}
39+
self._proxy = proxy
3840
self._flight_client_options["generic_options"] = [
3941
("grpc.secondary_user_agent", USER_AGENT)
4042
]
43+
if self._proxy:
44+
self._flight_client_options["generic_options"].append(("grpc.http_proxy", self._proxy))
4145
self._flight_client = FlightClient(connection_string, **self._flight_client_options)
4246

4347
def query(self, query: str, language: str, mode: str, database: str, **kwargs):

tests/test_query.py

+14
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,17 @@ def test_query_with_parameters(self):
150150
)
151151

152152
mock_do_get.assert_called_once_with(expected_ticket, ANY)
153+
154+
def test_query_proxy_base_client(self):
155+
test_proxy = "http://testproxy:5432"
156+
client = InfluxDBClient3(
157+
host="http://localhost:8443",
158+
token="my-token",
159+
org="my-org",
160+
database="my-database",
161+
proxy=test_proxy
162+
)
163+
164+
assert client._query_api._proxy == test_proxy
165+
assert ('grpc.http_proxy', test_proxy) in\
166+
client._query_api._flight_client_options.get('generic_options')

0 commit comments

Comments
 (0)