Repository navigation
fix(spanner): honor GOOGLE_CLOUD_UNIVERSE_DOMAIN when universe domain is unset - #15142
sakthivelmanii wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Spanner client to support resolving the universe domain from the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable. It refactors universe domain resolution and validation logic in SpannerOptions and ConnectionOptions to ensure consistent precedence (explicit configuration > environment variable > default "googleapis.com") and delegation to GAX stub builders. Additionally, comprehensive integration and unit tests using forked JVM processes have been added to verify these behaviors. I have no feedback to provide as there are no review comments.
olavloite
left a comment
There was a problem hiding this comment.
A few issues to address before merging:
1. Use SpannerEnvironment instead of System.getenv(...) and forked-JVM probes
SpannerOptions already provides SpannerEnvironment (SpannerOptions.useEnvironment(...) / SpannerOptions.useDefaultEnvironment()) so environment-variable configuration can be tested in-process (like getMonitoringHost() and getOptimizerVersion()).
Instead of calling System.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") directly and using forked JVMs to test GAX's EndpointContext:
- Add
default @Nullable String getUniverseDomain() { return null; }toSpannerOptions.SpannerEnvironment, returningSystem.getenv(GOOGLE_CLOUD_UNIVERSE_DOMAIN_ENV_VAR)inSpannerEnvironmentImpl. - Read
environment.getUniverseDomain()inSpannerOptions.resolveUniverseDomain(...). - Pass
getResolvedUniverseDomain()directly tospannerStubSettingsBuilder,instanceAdminStubSettingsBuilder, anddatabaseAdminStubSettingsBuilder, and removeresolveStubUniverseDomain(...). - Replace the forked-JVM probe tests in
SpannerOptionsTestandConnectionOptionsTestwith in-process tests usingSpannerOptions.useEnvironment(...)(resetting viaSpannerOptions.useDefaultEnvironment()infinally/@After).
2. ConnectionOptions and SpannerPool still ignore GOOGLE_CLOUD_UNIVERSE_DOMAIN by default
ConnectionProperties.UNIVERSE_DOMAIN defaults to "googleapis.com" rather than null. When a connection URI omits universeDomain:
ConnectionOptions.getUniverseDomain()returns"googleapis.com".ConnectionOptions.getDefaultHost()passes"googleapis.com"toSpannerOptions.resolveUniverseDomain(...), skipping the env fallback.SpannerPoolpasses"googleapis.com"toSpannerOptions.Builder#setUniverseDomain(...), overriding the env var.
ChannelProviderUniverseDomainProbe only worked because it explicitly called .setConnectionPropertyValue(ConnectionProperties.UNIVERSE_DOMAIN, null).
To fix this:
- Change the default of
ConnectionProperties.UNIVERSE_DOMAINfrom"googleapis.com"tonull(and updateConnectionOptionsTest.testUniverseDomain(), which currently expectsspannerOptions.getUniverseDomain()to be"googleapis.com"when omitted, plus regenerate the connection properties markdown docs if needed). - Add tests using a plain connection URI without
universeDomain(and without setting the property tonull) verifying bothConnectionOptions#getChannelProvider()andSpannerPool.
3. Pass the resolved universe domain to BuiltInMetricsProvider
SpannerOptions still passes getUniverseDomain() (null or "" when unset/cleared) to builtInMetricsProvider in getBuiltInOpenTelemetry(), enablegRPCMetrics(...), and createCloudMonitoringMetricsTracerFactory(). If GOOGLE_CLOUD_UNIVERSE_DOMAIN="", SpannerCloudMonitoringExporter skips setUniverseDomain(...) and MetricServiceSettings resolves monitoring.:443. Passing getResolvedUniverseDomain() keeps monitoring consistent with the Spanner stubs.
4. Minor items
- Explicit validation: Validation of
GOOGLE_CLOUD_UNIVERSE_DOMAINwhenhostoremulatorHostis set currently only happens becauseServiceOptionscallsMoreObjects.firstNonNull(builder.host, getDefaultHost())eagerly. CallgetResolvedUniverseDomain()(orvalidateUniverseDomain(...)) explicitly inSpannerOptionsinstead of relying on that side effect. - Nullness annotations: Use
org.jspecify.annotations.Nullableinstead of addingjavax.annotation.NullableinConnectionOptionsTest(and on new methods inSpannerOptions).
|
Also, long term, this should be fixed in gax + google-cloud-core, so we need less workaround code in the Spanner client. |
… is unset ## Problem Statement - When no universe domain was set explicitly, the Spanner client coerced it to `googleapis.com` for the data, instance admin, and database admin stubs and for the default host, so `GOOGLE_CLOUD_UNIVERSE_DOMAIN` was ignored. - The `universeDomain` connection property defaulted to `googleapis.com`, so `ConnectionOptions` and pooled Spanner clients also ignored `GOOGLE_CLOUD_UNIVERSE_DOMAIN`. - Built-in metrics received the unresolved universe domain rather than the one used by the Spanner stubs. ## Solution - Add `SpannerOptions.SpannerEnvironment#getUniverseDomain()`, backed by `GOOGLE_CLOUD_UNIVERSE_DOMAIN`. - Resolve the universe domain with the precedence: explicit setting, then environment, then `googleapis.com`, and use that value for the stubs, the default host, and built-in metrics. - The `universeDomain` connection property is now unset by default, so `ConnectionOptions#getUniverseDomain()` returns `null` when it is not configured. - An unset or empty `GOOGLE_CLOUD_UNIVERSE_DOMAIN` still falls back to `googleapis.com`. - An invalid `GOOGLE_CLOUD_UNIVERSE_DOMAIN` fails with `IllegalArgumentException` at `SpannerOptions.Builder#build()` (including when a host or emulator host is set) and with `INVALID_ARGUMENT` in `ConnectionOptions#getChannelProvider()`.
e7a73af to
498e49c
Compare
|
@olavloite Addressed all comments — moved the env lookup into |
Problem Statement
googleapis.comfor the data, instance admin, and database admin stubs and for the default host, soGOOGLE_CLOUD_UNIVERSE_DOMAINwas ignored.universeDomainconnection property defaulted togoogleapis.com, soConnectionOptionsand pooled Spanner clients also ignoredGOOGLE_CLOUD_UNIVERSE_DOMAIN.Solution
SpannerOptions.SpannerEnvironment#getUniverseDomain(), backed byGOOGLE_CLOUD_UNIVERSE_DOMAIN.googleapis.com, and use that value for the stubs, the default host, and built-in metrics.universeDomainconnection property is now unset by default, soConnectionOptions#getUniverseDomain()returnsnullwhen it is not configured.GOOGLE_CLOUD_UNIVERSE_DOMAINstill falls back togoogleapis.com.GOOGLE_CLOUD_UNIVERSE_DOMAINfails withIllegalArgumentExceptionatSpannerOptions.Builder#build()(including when a host or emulator host is set) and withINVALID_ARGUMENTinConnectionOptions#getChannelProvider().