Repository: InfluxCommunity/influxdb3-python

Issue:
client not using proxy - grpc
### Specifications

* Client Version: 1.11 dev [unreleased]
* InfluxDB Version: cloud - [TODO] check also clustered
* Platform: client ubunt 22.04 + Python 3.12

Using an envoy proxy server between client and server query requests are not showing up in the proxy log.  They seem to succeed regardless. This implies that the proxy settings are being ignored.  See EAR 5702

Regarding behavior with clustered a related issue is #117


### Code sample to reproduce problem

```python
from build.lib.influxdb_client_3 import InfluxDBClient3
import time
import logging
import http.client

def main() -> None:
    print("main()")
    http.client.HTTPConnection.debuglevel = 1
    logging.basicConfig()
    logging.getLogger().setLevel(logging.DEBUG)
    requests_log = logging.getLogger("request.packages.urllib3")
    requests_log.setLevel(logging.DEBUG)
    requests_log.propagate = True
    client = InfluxDBClient3(
        # host="http://localhost:3000",
        host="https://us-east-1-1.aws.cloud2.influxdata.com",
        token="******",
        org="Bonitoo",
        database="Ephemera",
        proxy="http://localhost:10000",
        # proxy="http://localhost:80",
        debug=True
    )

    now = time.time_ns()

    lp = f'drone,location=harfa,id=A16E22 speed=18.7,alt=97.6,shutter=7 {now}'

    print("Writing Data")
    client.write(lp)
    print(f"Wrote {lp}")

    table = client.query(
        query="SELECT * FROM drone WHERE time >= now() - interval '1 hour'")

    print(table.to_pandas())


if __name__ == "__main__":
    main()
```


### Expected behavior

That the proxy settings be used for both writes and queries.  Expect to see in the proxy log a record like the following. 

```
envoy-1  | [2025-02-07T13:10:15.727Z] "CONNECT - HTTP/1.1" 200 DC 418 255 2 - "-" "grpc-httpcli/0.0" "8739665c-96f2-4f8f-9961-5618291c0d24" "192.168.88.82:50051" "192.168.88.82:50051"
```
Also that proxy settings can be set through environment variables, a configuration file and directly in the client code.  


### Actual behavior

When inspecting the proxy logs, it appears the write API is using the proxy, however the query API request using Flight > GRPC are not showing up. 

Example
```
envoy-1  | [2025-02-07 09:47:14.922][22][debug][http] [source/common/http/conn_manager_impl.cc:1135] [Tags: "ConnectionId":"11","StreamId":"17761144465323234730"] request headers complete (end_stream=false):
envoy-1  | ':authority', 'us-east-1-1.aws.cloud2.influxdata.com:443'
envoy-1  | ':method', 'CONNECT'
envoy-1  | 
envoy-1  | [2025-02-07 09:47:14.922][22][debug][connection] [./source/common/network/connection_impl.h:98] [Tags: "ConnectionId":"11"] current connecting state: false
envoy-1  | [2025-02-07 09:47:14.922][22][debug][router] [source/common/router/router.cc:525] [Tags: "ConnectionId":"11","StreamId":"17761144465323234730"] cluster 'influxdb_cluster' match for URL ''
envoy-1  | [2025-02-07 09:47:14.922][22][debug][misc] [source/common/upstream/cluster_manager_impl.cc:2295] Allocating TCP conn pool
envoy-1  | [2025-02-07 09:47:14.922][22][debug][router] [source/common/router/router.cc:750] [Tags: "ConnectionId":"11","StreamId":"17761144465323234730"] router decoding headers:
envoy-1  | ':authority', 'us-east-1-1.aws.cloud2.influxdata.com:443'
envoy-1  | ':method', 'CONNECT'
envoy-1  | ':scheme', 'http'
envoy-1  | 'x-forwarded-proto', 'http'
envoy-1  | 'x-request-id', '963c4250-2187-4be5-b7c4-182505b40b06'
envoy-1  | 'x-envoy-expected-rq-timeout-ms', '15000'
...
envoy-1  | [2025-02-07T09:47:14.922Z] "CONNECT - HTTP/1.1" 200 DC 1089 3644 1088 - "-" "-" "963c4250-2187-4be5-b7c4-182505b40b06" "us-east-1-1.aws.cloud2.influxdata.com:443" "34.196.233.7:443"
...
```
Though the query follows, it does not appear in the log.

### Additional info

_No response_

Discussion:
@karel-rehor: Note that when ENVAR `grpc_proxy` is set, the proxy server is called.  

e.g. Client call from IDE with the following ENVARS
```
PYTHONUNBUFFERED=1;grpc_proxy=http://localhost:10000
```
Then in proxy console log...
```
envoy-1  | [2025-02-07T14:13:18.933Z] "CONNECT - HTTP/1.1" 200 DC 1089 3644 1048 - "-" "-" "cff42e10-77ea-4031-8945-fe30744ad97f" "us-east-1-1.aws.cloud2.influxdata.com:443" "34.196.233.7:443"
envoy-1  | [2025-02-07T14:13:19.282Z] "CONNECT - HTTP/1.1" 200 DC 1214 7321 700 - "-" "grpc-httpcli/0.0" "7f421443-2c9a-42e0-aa4c-031334444ce2" "us-east-1-1.aws.cloud2.influxdata.com:443" "34.196.233.7:443"
```
And results are correct...
```
    alt      id location  shutter  speed                          time
0  97.6  A16E22    harfa      7.0   18.7 2025-02-07 14:13:18.930199607
1  97.6  A16E22    harfa      7.0   18.7 2025-02-07 14:00:48.277472412
```

Solution patch:
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:
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
diff --git a/influxdb_client_3/__init__.py b/influxdb_client_3/__init__.py
index 9097b31..40ab8a4 100644
--- a/influxdb_client_3/__init__.py
+++ b/influxdb_client_3/__init__.py
@@ -121,7 +121,7 @@ class InfluxDBClient3:
                                          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
@@ -166,7 +166,8 @@ class InfluxDBClient3:
         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..7d03a95 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 @@ class QueryApi(object):
         """
         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):


Test patch:
diff --git a/tests/test_query.py b/tests/test_query.py
index 0ad7e3f..1c6ab43 100644
--- a/tests/test_query.py
+++ b/tests/test_query.py
@@ -150,3 +150,17 @@ class TestQuery(unittest.TestCase):
         )
 
         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')