Skip to content

fix: 118 - query not using proxy #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions influxdb_client_3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
6 changes: 5 additions & 1 deletion influxdb_client_3/query/query_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,17 @@ 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')
Loading