Skip to content

fix(session): support REST transport for Dataproc control plane - #241

Open
dborowitz wants to merge 1 commit into
mainfrom
dborowitz-rest-transport
Open

dborowitz wants to merge 1 commit into
mainfrom
dborowitz-rest-transport

Conversation

@dborowitz

Copy link
Copy Markdown
Contributor

Summary

Adds MANAGED_SPARK_CONNECT_DATAPROC_TRANSPORT (grpc default, or rest) so Dataproc control-plane calls (SessionControllerClient and SessionTemplateControllerClient) can use HTTP/REST instead of gRPC.

Rationale

In restricted egress environments that allowlist per domain (for example dataproc.googleapis.com and *.dataproc.googleusercontent.com) without supporting partial-label wildcards for regional subdomains (*-dataproc.googleapis.com), Dataproc gRPC calls to the global dataproc.googleapis.com endpoint are rejected (Region '...' specified in request does not match endpoint region 'global'), whereas REST requests to dataproc.googleapis.com route by URI path (/v1/projects/*/locations/<region>/*) to the regional backend. Setting MANAGED_SPARK_CONNECT_DATAPROC_TRANSPORT=rest alongside GOOGLE_CLOUD_DATAPROC_API_ENDPOINT=dataproc.googleapis.com allows the client to run in those environments.

Changes

  • Transport configuration & client wiring (session.py):
    • Added MANAGED_SPARK_CONNECT_DATAPROC_TRANSPORT (grpc or rest, case-insensitive; invalid values raise ValueError).
    • Wired transport="rest" into _create_session_controller_client() (and its _CLIENT_CACHE key, omitting the kwarg for default grpc) and Builder.session_template_controller_client.
    • Treated empty GOOGLE_CLOUD_DATAPROC_API_ENDPOINT="" as unset so it falls back to {region}-dataproc.googleapis.com.
  • REST error-handling compatibility (session.py):
    • Handled google.api_core.exceptions.from_http_response() parent HTTP classes (BadRequest, Forbidden, NotFound, Conflict) in __create and terminate_s8s_session (checking JSON error.status for FAILED_PRECONDITION / ABORTED so unrelated 400/409 errors still propagate).
    • Updated _extract_api_error_details() to parse JSON dict error details (fieldViolations) in addition to protobuf objects, stripped REST's <METHOD> <URL>: message prefix in _format_create_session_error(), and detected non-JSON HTML 404s from nonexistent regional endpoints.
  • Tests, CI & docs:
    • Added unit tests for transport resolution, client caching, and REST-shaped error formatting/termination (tests/unit/test_dataproc.py, tests/unit/test_session.py, tests/unit/test_integration_conftest.py).
    • Updated integration test fixtures/assertions to support REST + global endpoint (tests/integration/conftest.py, tests/integration/test_session.py).
    • Added a control_plane pytest marker (pyproject.toml) and a dedicated ubuntu-latest, rest CI lane (.github/workflows/integration-tests.yaml) running -m control_plane with MANAGED_SPARK_CONNECT_DATAPROC_TRANSPORT=rest and GOOGLE_CLOUD_DATAPROC_API_ENDPOINT=dataproc.googleapis.com.
    • Documented MANAGED_SPARK_CONNECT_DATAPROC_TRANSPORT in README.md.

Verification

  • pyink --check google/ tests/ setup.py: passed
  • Unit tests (pytest -n 8 tests/unit): 817 passed, 17 skipped
  • Live integration tests (google.com:hadoop-cloud-dev / us-east4, MANAGED_SPARK_CONNECT_DATAPROC_TRANSPORT=rest, GOOGLE_CLOUD_DATAPROC_API_ENDPOINT=dataproc.googleapis.com):
    • Full suite: 17 passed, 1 skipped (9m09s)
    • -m control_plane: 6 passed, 12 deselected (1m54s)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for REST transport in Dataproc control-plane calls, controlled via the new MANAGED_SPARK_CONNECT_DATAPROC_TRANSPORT environment variable. It updates client initialization, enhances error handling to parse REST JSON error payloads, and updates the test suite to cover these changes. Feedback is provided regarding a potential issue in HTTP header parsing where a case-sensitive dictionary lookup for 'content-type' might fail if the header is capitalized as 'Content-Type'.

@dborowitz
dborowitz requested review from medb and tim-u November 20, 2026 22:16
@dborowitz
dborowitz force-pushed the dborowitz-rest-transport branch from f4afb37 to 9d2d102 Compare November 20, 2026 22:23

@tim-u tim-u left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI now exports GOOGLE_CLOUD_DATAPROC_API_ENDPOINT="" on every lane. Any code outside this diff that still uses os.getenv("GOOGLE_CLOUD_DATAPROC_API_ENDPOINT", default) would therefore get "". Have all uses moved to _dataproc_api_endpoint, and do all *ControllerClient( constructions pass the transport? grep -rn "GOOGLE_CLOUD_DATAPROC_API_ENDPOINT|ControllerClient(" google/ would confirm

Comment thread tests/unit/test_integration_conftest.py Resolved
@dborowitz
dborowitz force-pushed the dborowitz-rest-transport branch from 9d2d102 to 6e2028b Compare November 21, 2026 02:56
@dborowitz

Copy link
Copy Markdown
Contributor Author

[Dave's coding agent] Verified GOOGLE_CLOUD_DATAPROC_API_ENDPOINT and *ControllerClient( across the repo:

  • In google/, the only GOOGLE_CLOUD_DATAPROC_API_ENDPOINT read is _dataproc_api_endpoint() in session.py (which now strips whitespace too), and the only two Dataproc client constructions are _create_session_controller_client() and SessionTemplateControllerClient(**kwargs) — both pass transport when configured.
  • In tests/integration/conftest.py, all four *ControllerClient( constructions forward _dataproc_transport_kwargs() and use _dataproc_api_endpoint().

All other review comments have been addressed in 6e2028b97ce2 (gRPC NotFound / FailedPrecondition parity + regression tests, custom-endpoint HTML 404 stripping, combined terminate_s8s_session handler, whitespace stripping in _dataproc_api_endpoint, and mock.patch.dict in test_integration_conftest.py).

@dborowitz
dborowitz force-pushed the dborowitz-rest-transport branch from 6e2028b to 50f48ba Compare November 21, 2026 03:50
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