Adopt constructor options pattern for MixerServer and SpannerDataSource#1939
Adopt constructor options pattern for MixerServer and SpannerDataSource#1939clincoln8 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the mixer server and Spanner data source constructors to use the 'Required Parameters + Options Struct' pattern, improving API stability and test setup flexibility. It introduces an EmbeddingsServiceClient to encapsulate HTTP communication with the embeddings server, replacing direct package-level function calls. Additionally, it refactors the V2 resolve routing logic, introducing the X-V2Resolve-Indicator-Spanner header to allow request-time toggling between Spanner and legacy backends, and updates corresponding tests and architectural documentation. As there are no review comments provided, no feedback is offered on reviewer remarks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
ee74b92 to
edd6e0b
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the constructors for SpannerDataSource and MixerServer to use the 'Required Parameters + Options Struct' pattern, which improves API stability and simplifies test configurations. It also introduces an EmbeddingsServiceClient to encapsulate embeddings resolution logic. The review feedback highlights three key areas for improvement: preventing potential information exposure by avoiding returning raw error messages from the embeddings server to clients, using url.JoinPath instead of path.Join to preserve trailing slashes for the server configuration endpoint, and configuring a sensible timeout on the default HTTP client to prevent resource exhaustion.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Refactor core server constructors (NewMixerServer, NewSpannerDataSource) and embeddings resolution to adopt the Constructor Options Pattern (required parameters + options struct).
Adding optional dependencies to these core components previously broke their constructor signatures, forcing updates to dozens of files (mostly test setup boilerplate) that didn't use the new feature.
This refactor stabilizes these APIs. Essential dependencies (e.g., SpannerClient) remain direct parameters, while optional ones (e.g., caches, maps clients) are grouped into an Options struct. This allows us to add future optional dependencies without breaking existing calls, and simplifies tests by allowing them to pass nil options.
Key Aspects of the Approach
SpannerDataSourceOptions,EmbeddingsServiceClientOptions, andMixerServerOptionsto group optional dependencies for the respective constructors.SpannerClientis required forNewSpannerDataSource, whileRecogPlaceStoreandMapsClientare optional.EmbeddingsServiceClientstruct, converting package-level functions (ResolveUsingEmbeddings,SelectEmbeddingsIndex) into client methods.docs/architecture.mdto document the constructor options pattern guidelines and the circular dependency resolution pattern (setter injection) with concrete examples.