Repository navigation
refactor(health): migrate health_service to backend-agnostic lazy database initialization - #1493
Merged
Merged
Conversation
…abase initialization Refactor `cmd/health_service` from Spanner-only lazy client initialization and schema version checks to backend-agnostic lazy database initialization built on `internal/storage/dbconfig`, `internal/storage/factory`, `internal/common/health`, and `pkg/components/store/dbstore`. Expose `SchemaVersion()` on `*factory.Storage`, detach long-lived client and pool lifetimes from short-lived lazy initialization contexts via `context.WithoutCancel(ctx)`, add legacy `health_ess_spanner_database_name` and `health_xid_spanner_database_name` env fallbacks in `dbconfig.Load()`, and report backend-specific ESS/XID component names and schema versions in `HealthChecker`. TAG=agy CONV=58868279-57fe-42e4-abeb-60f90d279ec2
There was a problem hiding this comment.
Code Review
This pull request refactors the health service to support multiple database backends (Spanner and Postgres) by transitioning from Spanner-specific configurations and clients to a generalized database configuration and factory storage system. It updates the health checker, lazy client wrappers, configuration loading, and associated tests to support both backends. Additionally, it ensures that database connection pools are initialized with a context detached from caller cancellation so they are not prematurely torn down. I have no feedback to provide as there are no review comments.
… alias dbFactory Return "unknown" from `essDBComponentName()` and `xidDBComponentName()` when the configured backend is neither Spanner nor Postgres, and import `internal/storage/factory` as `dbFactory` in `cmd/health_service`. TAG=agy CONV=58868279-57fe-42e4-abeb-60f90d279ec2
andrzejfudro
marked this pull request as ready for review
October 29, 2026 17:12
andrzejfudro
requested review from
janzak-dev
and removed request for
AntonTyb
October 30, 2026 06:51
andrzejfudro
enabled auto-merge
October 30, 2026 06:51
janzak-dev
previously approved these changes
Oct 30, 2026
andrzejfudro
disabled auto-merge
October 30, 2026 09:39
Rename lazy_spanner_client{,_test}.go to lazy_db_client{,_test}.go, the
server field lazySpanner to lazyDB, and the mockLazySpanner test double
to mockLazyDB now that the wrapper is backend-agnostic.
TAG=agy
CONV=58868279-57fe-42e4-abeb-60f90d279ec2
janzak-dev
approved these changes
Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactor
cmd/health_servicefrom Spanner-specific lazy client initialization to backend-agnostic lazy database initialization backed bydbconfig,factory,health.SchemaVersionClient, anddbstore.Key Changes
internal/storage/dbconfig: Addhealth_ess_spanner_database_nameandhealth_xid_spanner_database_namelegacy fallbacks inloadSpanner().internal/storage/factory&internal/storage/postgres: ExposeSchemaVersion() (health.SchemaVersionClient, int64)on*factory.Storageand passcontext.WithoutCancel(ctx)when constructing Spanner clients andpgxpoolpools so lazily initialized handles outlive the triggering RPC context whilepool.Ping(ctx)still honors the request deadline.cmd/health_service: Loaddbconfig.ConfiginLoadConfig(), replaceHealthServiceLazySpannerWrapperwithHealthServiceLazyDBWrapperinlazy_db_client.go(openingfactory.ESSandfactory.XIDon demand with retry on failure), report"Spanner ESS"/"Spanner XID"or"Postgres ESS"/"Postgres XID"based on configured backend ("unknown"otherwise), and run custom component checks wheneverEnableComponentsis enabled.Assumptions
health_ess_spanner_database_name/health_xid_spanner_database_nameenv fallbacks stay until the per-service DB env vars are removed post-release; the health-service Helm configmap is updated separately.mainfails fast only on invalidDB_BACKENDor numeric settings, and missing DB targets surface as unhealthy components at check time.factory.NewStoragecallers; this is safe because every caller closes storage explicitly viaClose(), and queries/transactions keep using their per-call contexts.Verification
bazel test //internal/storage/dbconfig/... //internal/storage/factory/... //internal/storage/postgres/... //cmd/health_service/...(Passed)./.githooks/pre-commit(Passed)TAG=agy
CONV=58868279-57fe-42e4-abeb-60f90d279ec2