Skip to content

Support proxy_url and ssl_ca_certs options for gRPC - #341

Merged
jhamon merged 1 commit into
mainfrom
daver/grpc_proxy_ssl_ca_cert
May 13, 2024
Merged

jhamon merged 1 commit into
mainfrom
daver/grpc_proxy_ssl_ca_cert

Conversation

@daverigby

@daverigby daverigby commented May 10, 2024 •

Copy link
Copy Markdown
Contributor

Problem

The PineconeGRPC client does not currently honor the proxy_url and ssl_ca_certs arguments - they are accepted but silently ignored.

This means the gRPC client cannot be used in enviroments which require a proxy to access the Pinecone service.

Solution

Address by wiring up these two config options to the corresponding options in the underlying grpc library - in addition to them still being passed to the HTTP-based control-plane connections.

Usage is very similar to the non-gRPC client - for example:

pc = PineconeGRPC(my_api_key,
                  proxy_url="http://localhost:8080",
                  ssl_ca_certs="/path/to/my/ca-cert.pem")

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Test Plan

Proxy tests expanded to also test PineconeGRPC

The PineconeGRPC client does not currently honor the proxy_url and
ssl_ca_certs arguments - they are accepted but silently ignored.

This means the gRPC client cannot be used in enviroments which require
a proxy to access the Pinecone service.

Address by wiring up these two config options to the corresponding
options in the underlying grpc library - in addition to them still
being passed to the HTTP-based control-plane connections.

Usage is very similar to the non-gRPC client - for example:

    pc = PineconeGRPC(my_api_key,
                      proxy_url="http://localhost:8080",
                      ssl_ca_certs="/path/to/my/ca-cert.pem")
@daverigby
daverigby force-pushed the daver/grpc_proxy_ssl_ca_cert branch from ad94eee to 2380c6a Compare May 10, 2024 21:05
@daverigby
daverigby marked this pull request as ready for review May 10, 2024 21:08
@daverigby

Copy link
Copy Markdown
Contributor Author

I note that the proxy tests are not currently run via CI. I re-ran them manually (for USE_GRPC=false and true) on Amazon Linux 2023.

In non-GRPC mode all tests pass (as before), in GRPC-mode all tests which are supported pass (gRPC doesn't support https:// proxies or proxy auth):

$ USE_GRPC=true PINECONE_API_KEY=f0ae7459-aa9c-46c2-8869-ff115dc15901 PINECONE_INDEX_NAME=test poetry run pytest tests/integration/proxy_config -s -v 
====================================================================================================================== test session starts ======================================================================================================================
platform linux -- Python 3.9.16, pytest-8.0.0, pluggy-1.3.0 -- /data/daver/repos/pinecone-python-client/.venv/bin/python
cachedir: .pytest_cache
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /data/daver/repos/pinecone-python-client
plugins: timeout-2.2.0, asyncio-0.15.1, mock-3.6.1, cov-2.10.1, benchmark-4.0.0
collected 6 items                                                                                                                                                                                                                                               

tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_https_proxy_with_self_signed_cert SKIPPED (gRPC doesn't support 'https://' proxy URLs)
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_http_proxy_with_self_signed_cert docker run -d --rm --name proxy1 -p 8080:8080 -v /data/daver/repos/pinecone-python-client/tests/integration/proxy_config/.mitm/proxy1:/home/mitmproxy/.mitmproxy mitmproxy/mitmproxy mitmdump
docker run -d --rm --name proxy2 -p 8081:8080 -v /data/daver/repos/pinecone-python-client/tests/integration/proxy_config/.mitm/proxy2:/home/mitmproxy/.mitmproxy mitmproxy/mitmproxy mitmdump --set proxyauth=testuser:testpassword
PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_with_ssl_verification_disabled_emits_warning SKIPPED (gRPC doesn't support disabling ssl_verify)
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_with_incorrect_cert_path PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_with_valid_path_to_incorrect_cert PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_that_requires_proxyauth SKIPPED (gRPC doesn't support proxy auth)

================================================================================================================= 3 passed, 3 skipped in 8.21s ==================================================================================================================

$ USE_GRPC=false PINECONE_API_KEY=f0ae7459-aa9c-46c2-8869-ff115dc15901 PINECONE_INDEX_NAME=test poetry run pytest tests/integration/proxy_config -s -v 
====================================================================================================================== test session starts ======================================================================================================================
platform linux -- Python 3.9.16, pytest-8.0.0, pluggy-1.3.0 -- /data/daver/repos/pinecone-python-client/.venv/bin/python
cachedir: .pytest_cache
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /data/daver/repos/pinecone-python-client
plugins: timeout-2.2.0, asyncio-0.15.1, mock-3.6.1, cov-2.10.1, benchmark-4.0.0
collected 6 items                                                                                                                                                                                                                                               

tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_https_proxy_with_self_signed_cert docker run -d --rm --name proxy1 -p 8080:8080 -v /data/daver/repos/pinecone-python-client/tests/integration/proxy_config/.mitm/proxy1:/home/mitmproxy/.mitmproxy mitmproxy/mitmproxy mitmdump
docker run -d --rm --name proxy2 -p 8081:8080 -v /data/daver/repos/pinecone-python-client/tests/integration/proxy_config/.mitm/proxy2:/home/mitmproxy/.mitmproxy mitmproxy/mitmproxy mitmdump --set proxyauth=testuser:testpassword
PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_http_proxy_with_self_signed_cert PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_with_ssl_verification_disabled_emits_warning PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_with_incorrect_cert_path PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_with_valid_path_to_incorrect_cert PASSED
tests/integration/proxy_config/test_proxy_settings.py::TestProxyConfig::test_proxy_that_requires_proxyauth PASSED

======================================================================================================================= 6 passed in 8.47s =======================================================================================================================

@jhamon

jhamon commented May 13, 2024

Copy link
Copy Markdown
Collaborator

Thanks for following up with this.

I previously put a lot of effort into trying to get tests with mitmproxy running in CI and ultimately had to bail due to time and other urgent things coming up. You can of course run a docker container in github actions, but I kept running into permissions issues when trying to mount a directory as a volume on the mitmproxy container so I could get the generated cert for testing. Details are a bit vague in my memory now, but I think docker was creating files as root that the test processing outside the container could not access. One day I'll get back to it because it's not great having these tests that don't run automtically.

@jhamon
jhamon merged commit b174eea into main May 13, 2024
@jhamon
jhamon deleted the daver/grpc_proxy_ssl_ca_cert branch May 13, 2024 18:55
@daverigby

Copy link
Copy Markdown
Contributor Author

Thanks @jhamon.

Note we probably don't actually need mitmproxy inside a container for this use-case, we could just download and install directly into the GitHub worker (it's a simple tgz containing just 3 binaries - mitmproxy plus the web and dump variants), or it looks like you can even install via pipx: https://docs.mitmproxy.org/stable/overview-installation/

mcpaddy added a commit to mcpaddy/pinecone-python-client that referenced this pull request May 22, 2024
* 'main' of github.com:pinecone-io/pinecone-python-client:
  [skip ci] Bump version to v4.1.0
  Bump tqdm from 4.66.1 to 4.66.3 (pinecone-io#344)
  Bump idna from 3.4 to 3.7 (pinecone-io#345)
  Bump jinja2 from 3.1.3 to 3.1.4 (pinecone-io#343)
  Add better error messages for mistaken `from_texts` and `from_documents` (pinecone-io#342)
  Support proxy_url and ssl_ca_certs options for gRPC (pinecone-io#341)
  Remove serverless public preview warnings (pinecone-io#340)
  [skip ci] Bump version to v4.0.0
  Improve upsert throughput by 3x (pinecone-io#334)
  Remove `merge` workflow and update `build-and-publish-docs` workflow to be manually runnable (pinecone-io#335)
  [skip ci] Bump version to v3.2.2
  [Fix] openapi_config deprecation warning incorrectly shown (pinecone-io#327)
  Add grpc unit test run, expand testing of VectorFactory (pinecone-io#326)
  [skip ci] Bump version to v3.2.1
  Allow clients to tag requests with a source_tag (pinecone-io#324)
  [skip ci] Bump version to v3.2.0
  Revise proxy configuration, add integration testing (pinecone-io#325)
  [Fix] Configuring SSL proxy via openapi_config object (pinecone-io#321)
  Update README.md (pinecone-io#323)
NishchayMahor pushed a commit to NishchayMahor/python-sdk-1 that referenced this pull request Sep 22, 2026
…r the 5s ceiling (pinecone-io#327) (pinecone-io#341)

* test(tooling): measured scoped timeout markers for the unit tests near the 5s ceiling (pinecone-io#327)

pinecone-io#306 made `timeout = 5` load-bearing for unit tests and handed back eight that
run within 1.7-2.5x of it. Its risk assessment was that they are wall-clock-bound
rather than CPU-bound, so unlike the grpc dataframe property test they should not
amplify on a slower runner. Measuring wall vs CPU per test confirms it: all eight
spend 0.1-0.5% of their runtime on CPU, and both costs are fixed constants in the
test doubles (a `threading.Event.wait(timeout=2)`, and a Retry-After of 2.0s that
the smear can stretch 1.5x).

Scoped markers sized against those measurements, at pinecone-io#306's ~7x ratio: 15s on the
three classes in test_grpc_dataframe_total_timeout.py that let the deadline fire
(2.01s each), and 20s on the sync and async Retry-After smear tests (2.96s). The
global 5s unit default is untouched.

Sweeping the whole suite for anything else above 1.5s found one test the ticket
did not know about, and it is the CPU-bound one: test_gaps_mode_end_to_end runs
1.65s at 94% CPU across two api_coverage.py subprocesses, i.e. the exact profile
that blew the 5s limit before. It gets 30s.

CI now runs pytest tests/unit with --durations, so a claimed margin can be
checked against real runner hardware without a throwaway commit.

Closes pinecone-io#327

* test(grpc): mark the two dataframe property tests the CI durations exposed (pinecone-io#327)

The --durations this PR added to CI paid for itself on its own first run. The
eight wall-clock-bound tests came in at 1.00x local->CI on all five Python
versions, exactly as pinecone-io#306 predicted. But the CPU-bound reference amplified
3.7-4.9x, reaching 6.22s on py3.10 — so pinecone-io#306's 60s marker on
test_batches_form_a_valid_partition is holding back a red on four of five
versions right now, not guarding a hypothetical.

Its two unmarked siblings in the same class share that profile and amplify ~3x
(0.70s/0.73s local -> 1.82-1.86s/1.69-2.19s CI), leaving 2.3x under the 5s
default on a cost that demonstrably clears 5s for the third member. 30s each,
sized against the CI maximum rather than the local reading.

Refs pinecone-io#327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants