Skip to content

Support Spanner Emulator Host for SpannerChangeStreamsToPubSub Templates#3545

Open
hunsche wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
hunsche:feature/spanner-emulator-support
Open

Support Spanner Emulator Host for SpannerChangeStreamsToPubSub Templates#3545
hunsche wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
hunsche:feature/spanner-emulator-support

Conversation

@hunsche
Copy link

@hunsche hunsche commented Mar 23, 2026

This CL updates SpannerConfig initialization in the SpannerChangeStreamsToPubSub template to explicitly respect the SPANNER_EMULATOR_HOST environment variable, restoring standard Google Cloud client behavior.

The SPANNER_EMULATOR_HOST variable is the official standard across all Google Cloud client libraries (Go, Java, Python, Node) for discovering the emulator. By default, the underlying Spanner client automatically reads and uses this variable to establish plaintext connections natively.

However, Apache Beam's SpannerIO inadvertently overrides this default fallback behavior. To fix this, this CL checks for the presence of SPANNER_EMULATOR_HOST. If present, it maps it directly to .withEmulatorHost() before falling back to the template's runtime options.

This aligns the Beam pipeline's local development experience perfectly with the conventions of the broader Google Cloud ecosystem, eliminating the need for workarounds.

TEST=Verified via local build

This CL updates SpannerConfig initialization in the
SpannerChangeStreamsToPubSub template to explicitly respect the
SPANNER_EMULATOR_HOST environment variable, restoring standard Google
Cloud client behavior.

The SPANNER_EMULATOR_HOST variable is the official standard across all
Google Cloud client libraries (Go, Java, Python, Node) for discovering the
emulator. By default, the underlying Spanner client automatically reads and
uses this variable to establish plaintext connections natively.

However, Apache Beam's SpannerIO inadvertently overrides this default
fallback behavior. To fix this, this CL checks for the presence of
SPANNER_EMULATOR_HOST. If present, it maps it directly to
.withEmulatorHost() before falling back to the template's runtime options.

This aligns the Beam pipeline's local development experience perfectly with
the conventions of the broader Google Cloud ecosystem, eliminating the need
for workarounds.

TEST=Verified via local build
@hunsche hunsche requested a review from a team as a code owner March 23, 2026 18:49
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the SpannerChangeStreamsToPubSub template by integrating native support for the SPANNER_EMULATOR_HOST environment variable. This change ensures that the Spanner client within the Beam pipeline correctly identifies and connects to a local Spanner emulator, mirroring the behavior of other Google Cloud client libraries. The update streamlines local development workflows by eliminating the need for custom workarounds when using the Spanner emulator.

Highlights

  • Spanner Emulator Host Support: Added explicit support for the SPANNER_EMULATOR_HOST environment variable in the SpannerChangeStreamsToPubSub template.
  • Configuration Priority: Prioritized the SPANNER_EMULATOR_HOST environment variable over the spannerHost runtime option for Spanner client configuration.
  • Aligned Development Experience: Ensured the Beam pipeline's local development experience aligns with standard Google Cloud client library conventions for Spanner emulator discovery.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.21%. Comparing base (1b8904c) to head (96a2da9).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
...ort/v2/templates/SpannerChangeStreamsToPubSub.java 0.00% 6 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3545      +/-   ##
============================================
- Coverage     52.25%   52.21%   -0.04%     
+ Complexity     6055     5641     -414     
============================================
  Files          1040     1040              
  Lines         62956    62990      +34     
  Branches       6893     6902       +9     
============================================
- Hits          32895    32888       -7     
- Misses        27843    27877      +34     
- Partials       2218     2225       +7     
Components Coverage Δ
spanner-templates 72.23% <ø> (-0.03%) ⬇️
spanner-import-export 69.05% <ø> (-0.04%) ⬇️
spanner-live-forward-migration 80.47% <ø> (-0.02%) ⬇️
spanner-live-reverse-replication 77.87% <ø> (-0.06%) ⬇️
spanner-bulk-migration 89.18% <ø> (-0.01%) ⬇️
gcs-spanner-dv 85.32% <ø> (-0.03%) ⬇️
Files with missing lines Coverage Δ
...ort/v2/templates/SpannerChangeStreamsToPubSub.java 0.00% <0.00%> (ø)

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hunsche hunsche force-pushed the feature/spanner-emulator-support branch from 45c8170 to 43d53e7 Compare March 24, 2026 18:00
Abacn
Abacn previously approved these changes Mar 24, 2026
@hunsche hunsche force-pushed the feature/spanner-emulator-support branch from 43d53e7 to 96a2da9 Compare March 25, 2026 16:33
@hunsche hunsche requested a review from Abacn March 25, 2026 16:33
@Abacn Abacn added the improvement Making existing code better label Mar 26, 2026
@Abacn Abacn changed the title Add native SPANNER_EMULATOR_HOST support to SpannerChangeStreamsToPubSub Support pannerEmulatorHost for SpannerChangeStreamsToPubSub Templates Mar 26, 2026
@Abacn Abacn changed the title Support pannerEmulatorHost for SpannerChangeStreamsToPubSub Templates Support Spanner Emulator Host for SpannerChangeStreamsToPubSub Templates Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Making existing code better size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants