Skip to content

feat: gapic centralization into api core#17628

Open
hebaalazzeh wants to merge 36 commits into
mainfrom
feat/gapic-centralization-api-core
Open

feat: gapic centralization into api core#17628
hebaalazzeh wants to merge 36 commits into
mainfrom
feat/gapic-centralization-api-core

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Update and Release google-api-core

This PR introduces centralized helper functions into google.api_core.gapic_v1. The goal of this centralization is to reduce package size, improve maintainability, and boost import performance of generated GAPIC clients by moving redundant, service-agnostic boilerplate logic into google-api-core.

Key Changes

  • Centralized GAPIC Helpers: Extracted logic previously repeated across generated clients into focused, domain-specific modules within google.api_core.gapic_v1:
    • _routing.py (get_default_mtls_endpoint, get_api_endpoint, get_universe_domain)
    • _client_cert.py (use_client_cert_effective, get_client_cert_source)
    • _config_helpers.py (read_environment_variables)
    • _method_helpers.py (setup_request_id)
  • Public Method Exposure: Removed the _ prefix from these functions so they can be securely imported and utilized by external generated clients.
  • Backward Compatibility: Added internal aliases (e.g., _use_client_cert_effective = use_client_cert_effective) to prevent breaking changes for existing GAPIC clients (over 2,400+ repos) that have not yet been regenerated.
  • Comprehensive Test Coverage: Added exhaustive unit tests for all helper functions in dedicated, domain-specific test files (test_routing.py, test_client_cert.py, test_config_helpers.py, test_method_helpers.py).
  • CI Environment Hardening:
    • Handled grpc optional dependencies gracefully to ensure tests pass in install_grpc=False environments.
    • Ensured older versions of google-auth (e.g. <=2.14.1) pass in the CI test matrix by safely validating should_use_client_cert availability.

Next Steps (Phase 2)

Once this PR is merged and a new minor version of google-api-core (e.g. 2.18.0) is released, we can update the GAPIC generator to utilize these centralized helpers and stop emitting the redundant logic.

Note

Full details and baseline metrics are available in the attached Design Document.

@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 a new client_helpers module in google-api-core containing helper functions for GAPIC client initialization, and adds global lazy imports control (__lazy_modules__) to google-cloud-compute. The review feedback suggests optimizing performance by compiling the mTLS endpoint regular expression at the module level rather than inside the function. Additionally, it recommends correcting the type annotations in get_api_endpoint to use Optional[Any] for client_cert_source and Optional[str] for the return type.

Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py Outdated
@hebaalazzeh hebaalazzeh self-assigned this Jul 6, 2026
@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-centralization-api-core branch from 5e1eb20 to ad1c01f Compare July 6, 2026 21:21
@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini

@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-centralization-api-core branch from c27695d to 2353e82 Compare July 7, 2026 20:56
@hebaalazzeh hebaalazzeh marked this pull request as ready for review July 7, 2026 21:01
@hebaalazzeh hebaalazzeh requested a review from a team as a code owner July 7, 2026 21:01
@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-centralization-api-core branch 3 times, most recently from 1d7b5c2 to 3f02e35 Compare July 9, 2026 20:02
@hebaalazzeh hebaalazzeh requested review from tswast and removed request for a team and tswast July 10, 2026 01:37
@hebaalazzeh hebaalazzeh requested a review from a team July 10, 2026 09:09
Comment thread packages/google-api-core/google/api_core/gapic_v1/__init__.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/_config_helpers.py Outdated
Comment thread packages/google-api-core/tests/unit/gapic/test_method_helpers.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/_client_cert.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/_client_cert.py
@ohmayr

ohmayr commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Could we open a draft PR for gapic-generator with the template updates, temporarily pointing its test google-api-core dependency to this git branch?

Running the gapic-generator-python CI (showcase and unit tests) on that draft PR will give us end-to-end verification that this branch integrates cleanly with generated code before we merge.

@parthea parthea marked this pull request as draft July 13, 2026 18:45
@parthea

parthea commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Converting to draft as it appears there are unrelated changes to bigframes. If that's not the case, move it back to ready for review

@hebaalazzeh hebaalazzeh marked this pull request as ready for review July 13, 2026 19:42
@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-centralization-api-core branch from cb95824 to a1341f0 Compare July 13, 2026 21:18
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.

3 participants