Skip to content

chore(spanner): Add support for experimental endpoint#5527

Open
mayurkale22 wants to merge 2 commits intoGoogleCloudPlatform:mainfrom
mayurkale22:mayurkale22-patch-1
Open

chore(spanner): Add support for experimental endpoint#5527
mayurkale22 wants to merge 2 commits intoGoogleCloudPlatform:mainfrom
mayurkale22:mayurkale22-patch-1

Conversation

@mayurkale22
Copy link
Copy Markdown

@mayurkale22 mayurkale22 commented Apr 20, 2026

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Contributing Guidelines from CONTRIBUTING.MD
  • Tests pass: go test -v ./.. (see Testing)
  • Code formatted: gofmt (see Formatting)
  • Vetting pass: go vet (see Formatting)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@mayurkale22 mayurkale22 requested review from a team as code owners April 20, 2026 08:36
@product-auto-label product-auto-label Bot added api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples. labels Apr 20, 2026
Copy link
Copy Markdown
Contributor

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

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 an experimental host in Spanner snippets by checking the EXPERIMENTAL_HOST environment variable and applying the necessary client options to both the database admin and data clients. Feedback suggests using a more idiomatic Go slice declaration, renaming the environment variable to be more specific (e.g., SPANNER_EXPERIMENTAL_HOST), and replacing log.Fatal calls with error returns to ensure deferred cleanup functions are executed correctly.

cfg := spanner.ClientConfig{
DatabaseRole: databaseRole,
}
opts := []option.ClientOption{}
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.

medium

In Go, it is more idiomatic to use var for an empty slice that will be appended to, rather than an empty slice literal. This avoids an unnecessary allocation and is generally preferred when the slice's initial capacity is not known.

Suggested change
opts := []option.ClientOption{}
var opts []option.ClientOption
References
  1. In Go, it is more idiomatic to use var for an empty slice that will be appended to, rather than an empty slice literal. (link)

opts := []option.ClientOption{}

adminClient, err := database.NewDatabaseAdminClient(ctx)
endpoint := os.Getenv("EXPERIMENTAL_HOST")
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.

medium

The environment variable name EXPERIMENTAL_HOST is quite generic. Consider using a more specific name like SPANNER_EXPERIMENTAL_HOST to avoid potential collisions with other tools or services that might use a similar naming convention.

cfg.IsExperimentalHost = true
}

adminClient, err := database.NewDatabaseAdminClient(ctx, opts...)
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.

medium

The run function returns an error, but errors during client creation are handled with log.Fatal, which terminates the process immediately. This prevents deferred functions (like adminClient.Close()) from running and is inconsistent with how other errors in this function are handled. Consider returning the error instead of using log.Fatal.

defer adminClient.Close()

dataClient, err := spanner.NewClientWithConfig(ctx, db, cfg)
dataClient, err := spanner.NewClientWithConfig(ctx, db, cfg, opts...)
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.

medium

Similar to the adminClient creation, using log.Fatal here prevents the previously created adminClient from being closed via its deferred Close() call if spanner.NewClientWithConfig fails. It is better to return the error to the caller.

Copy link
Copy Markdown
Contributor

@amcolin amcolin left a comment

Choose a reason for hiding this comment

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

This is a great addition! Once the feedback from Gemini has been addressed, I think this will be in a good spot to merge. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants