Repository navigation
feat(dashboard): rebuild ClickHouse data engine when configuration changes - #1039
Conversation
Centralize Kubernetes Component Custom Resource lookup and field extraction into pkg/components/crreader, reusing the canonical GVR and default namespace constants from internal/kubernetes/common/constants. Migrate cmd/ingestion_gateway and cmd/actuator to delegate Component CR fetching, disabled state checks, and string-map extraction to crreader. TAG=agy
When enable_components is true, resolve ClickHouse connection coordinates and the password Secret from the clickhouse Component CR via pkg/clickhouse/componentconfig, falling back to static CLICKHOUSE_* environment variables only when the CR is NotFound or disabled. Preserve Secret Manager CSI password file precedence (CLICKHOUSE_PASSWORD_FILE) and provision the conditional dashboard-service-components-reader Role and RoleBinding in the Helm chart. TAG=agy
…anges Add Resolver and NewDynamicProvider to internal/dashboard/dataengine so readiness probes re-evaluate the resolved ClickHouse configuration fingerprint and atomically swap the cached DataEngine when coordinates or credentials change, while keeping chart queries on the lock-free cached engine path. TAG=agy
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic ClickHouse provider that resolves configuration on initial dial and swaps the cached engine dynamically during readiness checks when configuration changes are detected. Feedback on these changes includes addressing potential query disruption by closing old engine connections asynchronously with a grace period, wrapping ping errors during rebuilds for better diagnostics, and refactoring initDataEngine to explicitly accept configuration parameters instead of relying on a package-level global variable.
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic ClickHouse provider that resolves connection configurations dynamically and swaps the cached engine on readiness checks when the configuration fingerprint changes. The review feedback highlights three key issues: a potential variable shadowing bug in main.go that could cause uninitialized configuration values to be read, lock contention in pingDynamic due to holding a mutex during blocking network I/O, and the immediate closure of superseded engines which can abort in-flight queries.
Avoid shadowing config in run, optimize dynamic ping locking, wrap ping errors, and add close grace period. Comment link: #1039 (comment) TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
…dling Fail closed on malformed spec.enabled or status.state and use type switch for nested map extraction. Comment link: #1037 (comment) TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic ClickHouse provider that resolves configuration fingerprints and dynamically swaps connection pools when changes are detected. The review feedback highlights a critical compilation error in main.go due to an outdated variable reference (cfg instead of srvCfg), and suggests adding defensive nil checks for ClickHouse connections in provider.go to prevent potential nil pointer dereferences.
Comment link: #1038 (comment) TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
…ection checks Add EnableComponents and ComponentsNamespace to server.Config populated via LoadConfig, pass cfg directly to initDataEngine, and check for nil connections in rebuild and build. Comment link: #1039 (comment) TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
|
/gemini review |
…ted IPv6 Lazily initialize K8s getter and secret reader inside connector closure to avoid permanently caching transient startup errors, strip brackets in normalizeEndpointToken, and add unit tests for bracketed IPv6 endpoints. Comment link: #1038 (comment) TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic ClickHouse provider that automatically swaps the connection pool when configuration changes are detected via fingerprinting during readiness checks. While this enables seamless configuration updates, the feedback points out a potential scalability issue: querying the Kubernetes API server directly on every readiness probe could overload the API server in large-scale deployments. It is recommended to resolve these resources locally using a cached client or shared informer.
…ow pure component config
…d allow pure component config
…ts, and readiness gate - Return ErrNotConfigured when ClickHouse Component CR is absent/disabled and static env is unconfigured - Do not make ClickHouse a mandatory /readyz dependency when unconfigured - Render dashboard-service-components-reader RBAC whenever componentsDeployment is enabled - Check status.access.envVars ENDPOINT before HOST and preserve multi-replica clusterEndpoints - Align defaultDialTimeout to 5s and omit compression to match pkg/clickhouse.GetOptions Comment links: - #1038 (comment) - #1038 (comment) - #1038 (comment) - #1038 (comment) TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
…traction - Fail closed in IsDisabled when comp.Object is an empty map - Move FakeGetter to testonly package pkg/components/crreader/crreadertest with sync.RWMutex and NotFound error semantics - Format float64 without scientific notation and ignore non-scalar values in formatScalarValue - Unexport nestedStringMap Comment links: - #1037 (comment) - #1037 (comment) - #1037 (comment) - #1037 (comment) TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
TAG=agy CONV=d4f29869-c50e-43d2-99c2-59e32521a096
Define Component CRD GVR and default namespace constants directly in pkg/components/crreader to avoid importing the legacy unresolved xmanager_cloud/kubernetes/common/constants path flagged by the google3 legacy import ratchet. TAG=agy
…nts-clickhouse-cr-resolution
…port ratchet Replace the legacy unresolved xmanager_cloud/logging/logging import in pkg/clickhouse/componentconfig with standard library log/slog and sync with refactor/components-shared-cr-reader. TAG=agy
…hboard-dataengine-rebuild-on-config-change
…ry importpath Sync feat/components-clickhouse-cr-resolution with origin/main after PR #1037 merged, and restore logging.Info in pkg/clickhouse/componentconfig using the directory-backed xmanager_cloud/internal/logging import path with importpath_aliases on //internal/logging:logging. Comment link: #1038 (comment) TAG=agy
…hboard-dataengine-rebuild-on-config-change
Resolve conflicts with origin/main after PR #1038 landed on main. TAG=agy
- Forward customGetter to buildClickHouseResolver and initialize K8s Secret reader lazily via lazySecretReader. - Fall back to pinging the active cached engine in pingDynamic when candidate config resolution or rebuild fails so healthy pods remain ready on /readyz. - Detach rebuild() dial and ping context from caller cancellation via context.WithoutCancel. Comment link: #1039 (comment) Comment link: #1039 (comment) Comment link: #1039 (comment) TAG=agy
Summary
Updates
internal/dashboard/dataengine.Providerandcmd/dashboard_serviceto detect changes in the resolved ClickHouse configuration fingerprint during readiness probes and atomically swap the cachedDataEnginewithout requiring a pod restart.Motivation & Context
Previously,
dataengine.Providercached the first successfully constructed*DataEnginefor the lifetime of the process. If theclickhouseComponentCR or its credentials Secret changed after initial startup (or if initial startup fell back to static environment configuration before theComponentCR was created),dashboard-servicewould never switch to the updated coordinates without restarting the pod.Key Changes
Optionstype alias inpkg/clickhouseandOptionsFingerprint(*clickhouse.Options) string(deterministic SHA-256 digest of addresses, database, username, and password) inpkg/clickhouse/componentconfig.ResolverandNewDynamicProvidertointernal/dashboard/dataengine:FetchChartData/Engineremain on the lock-freeatomic.Pointerfast path once an engine is cached, performing zero Kubernetes API calls on the chart query path.Pingre-evaluates the configuration fingerprint viaResolverand, when changed, dials and pings the candidate engine before atomically swapping the cached*DataEngineand closing the superseded connection.Pingreturns an error so/readyzreports unready while preserving the existing working engine for active queries.cmd/dashboard_service(initDataEngine) to usedataengine.NewDynamicProviderwithbuildClickHouseResolver.Assumptions
Verification & Testing
Automated Tests
bazel test --@io_bazel_rules_go//go/config:race //internal/dashboard/dataengine/... //cmd/dashboard_service/... //pkg/clickhouse/...(All 6 test targets pass with race detector enabled)Live Deployment & Manual Testing
..., slot...,...)deploy/ctk_v2/verify_xmc.py(All 14 pods, services, HTTPRoutes, and Gateway healthy)clickhouseComponent CR inxmcnamespace.dashboard-servicedetected the Component CR, resolved hostclickhouse.xmc.svc.cluster.local:9000and credentials fromclickhouse-secret, passed/readyzPing probe, and moved from0/1to1/1 Runningwith 0 pod restarts.spec.enabled: false.dashboard-servicedynamically detected the disabled CR and fell back to static environment configuration ("ClickHouse Component CR is absent or disabled; falling back to static environment configuration").spec.enabled: true).dashboard-servicedynamically re-resolved the Component CR, established the connection, and logged"ClickHouse configuration resolved from Component CR"without pod restart.Live Execution Output / Logs
{"timestamp":"2026-09-29T14:09:16.36919507Z","severity":"INFO","logging.googleapis.com/sourceLocation":{"function":"pkg/clickhouse/componentconfig.ResolveOptions","file":"resolver.go","line":102},"message":"ClickHouse configuration resolved from Component CR","namespace":"xmc","component":"clickhouse","addrs":["clickhouse.xmc.svc.cluster.local:9000"],"database":"default","user":"default"} {"timestamp":"2026-09-29T14:09:46.34066047Z","severity":"INFO","logging.googleapis.com/sourceLocation":{"function":"pkg/clickhouse/componentconfig.ResolveOptions","file":"resolver.go","line":78},"message":"ClickHouse Component CR is absent or disabled; falling back to static environment configuration","namespace":"xmc","component":"clickhouse"} {"timestamp":"2026-09-29T14:10:16.409429908Z","severity":"INFO","logging.googleapis.com/sourceLocation":{"function":"pkg/clickhouse/componentconfig.ResolveOptions","file":"resolver.go","line":102},"message":"ClickHouse configuration resolved from Component CR","namespace":"xmc","component":"clickhouse","addrs":["clickhouse.xmc.svc.cluster.local:9000"],"database":"default","user":"default"}Related Issues / Bugs
N/A
TAG=agy
CONV=d4f29869-c50e-43d2-99c2-59e32521a096