Skip to content

feat(dashboard): rebuild ClickHouse data engine when configuration changes - #1039

Merged
VLukiantsev merged 26 commits into
mainfrom
feat/dashboard-dataengine-rebuild-on-config-change
Oct 7, 2026
Merged

VLukiantsev merged 26 commits into
mainfrom
feat/dashboard-dataengine-rebuild-on-config-change

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Updates internal/dashboard/dataengine.Provider and cmd/dashboard_service to detect changes in the resolved ClickHouse configuration fingerprint during readiness probes and atomically swap the cached DataEngine without requiring a pod restart.

Motivation & Context

Previously, dataengine.Provider cached the first successfully constructed *DataEngine for the lifetime of the process. If the clickhouse Component CR or its credentials Secret changed after initial startup (or if initial startup fell back to static environment configuration before the Component CR was created), dashboard-service would never switch to the updated coordinates without restarting the pod.

Key Changes

  • Add Options type alias in pkg/clickhouse and OptionsFingerprint(*clickhouse.Options) string (deterministic SHA-256 digest of addresses, database, username, and password) in pkg/clickhouse/componentconfig.
  • Add Resolver and NewDynamicProvider to internal/dashboard/dataengine:
    • FetchChartData / Engine remain on the lock-free atomic.Pointer fast path once an engine is cached, performing zero Kubernetes API calls on the chart query path.
    • Readiness Ping re-evaluates the configuration fingerprint via Resolver and, when changed, dials and pings the candidate engine before atomically swapping the cached *DataEngine and closing the superseded connection.
    • If re-resolution or candidate dialing fails, Ping returns an error so /readyz reports unready while preserving the existing working engine for active queries.
  • Wire cmd/dashboard_service (initDataEngine) to use dataengine.NewDynamicProvider with buildClickHouseResolver.

Assumptions

  • None — requirements were fully specified.

Verification & Testing

Automated Tests

  • Unit & Integration 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)
  • Pre-commit Checks: buildifier, gofmt, golangci-lint, addlicense (All passed)

Live Deployment & Manual Testing

  • Deployment Target: GKE Dev Cluster (..., slot ..., ...)
  • Cluster Health: Verified via deploy/ctk_v2/verify_xmc.py (All 14 pods, services, HTTPRoutes, and Gateway healthy)
  • Manual Test Scenarios Executed:
    1. Component CR Resolution & Readiness Gate:
      • Action: Deployed ClickHouse Service/pod and applied clickhouse Component CR in xmc namespace.
      • Result: dashboard-service detected the Component CR, resolved host clickhouse.xmc.svc.cluster.local:9000 and credentials from clickhouse-secret, passed /readyz Ping probe, and moved from 0/1 to 1/1 Running with 0 pod restarts.
    2. Dynamic Fallback on Component Disable:
      • Action: Patched Component CR to spec.enabled: false.
      • Result: On next readiness probe (within 10s), dashboard-service dynamically detected the disabled CR and fell back to static environment configuration ("ClickHouse Component CR is absent or disabled; falling back to static environment configuration").
    3. Dynamic Rebuild on Component Recovery:
      • Action: Re-enabled Component CR (spec.enabled: true).
      • Result: On next readiness probe, dashboard-service dynamically 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

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
@VLukiantsev
VLukiantsev added this pull request to stack #1040 September 29, 2026 12:35
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

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

Copy link
Copy Markdown

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 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.

Comment thread cmd/dashboard_service/main.go Resolved

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

Copy link
Copy Markdown

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 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.

Comment thread cmd/dashboard_service/main.go Resolved
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
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

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

Copy link
Copy Markdown

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 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 thread cmd/dashboard_service/main.go Resolved
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
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/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

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

Copy link
Copy Markdown

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 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.

Comment thread cmd/dashboard_service/main.go Resolved
…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
…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
…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
@VLukiantsev
VLukiantsev requested a review from janzak-dev October 6, 2026 13:24
Base automatically changed from feat/components-clickhouse-cr-resolution to main October 6, 2026 13:24
@VLukiantsev
VLukiantsev marked this pull request as ready for review October 6, 2026 13:24
Resolve conflicts with origin/main after PR #1038 landed on main.

TAG=agy
Comment thread cmd/dashboard_service/main.go Resolved
- 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
@VLukiantsev
VLukiantsev requested a review from janzak-dev October 6, 2026 15:14
@VLukiantsev
VLukiantsev added this pull request to the merge queue Oct 7, 2026
Merged via the queue into main with commit 1f0c5f6 Oct 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants