Skip to content

fix(metrics): make ClickHouse and Redpanda addons resilient to pod rescheduling - #1459

Merged
janzak-dev merged 6 commits into
mainfrom
fix/resilient-metrics-addons-deployment
Oct 28, 2026
Merged

janzak-dev merged 6 commits into
mainfrom
fix/resilient-metrics-addons-deployment

Conversation

@janzak-dev

@janzak-dev janzak-dev commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Hardens the in-cluster ClickHouse and Redpanda metrics addons and the GKE deployment workflow against pod rescheduling and node pool rollouts.

Motivation & Context

During the XMC Nightly build run (Run 40612800311), a GKE node pool update rescheduled redpanda-0 and clickhouse-0 onto new nodes. Because the lightweight dev/CI metrics addons use ephemeral storage, redpanda-0 came up without the xmc-metrics topic and clickhouse-0 came up without the xmc_metrics tables and materialized views.

In .github/workflows/deploy-gke.yml, the Execute GKE Deployment Pipeline step (xmc_app Helm release with wait: true) executed before Deploy Metrics Addons (ClickHouse & Redpanda) (setup_metrics_addons.sh). When ingestion-gateway-deployment rolled out, its startup check (ValidateTopicTopology) failed because xmc-metrics was missing on the rescheduled redpanda-0 pod, causing ingestion-gateway to enter CrashLoopBackOff. This caused the xmc_app Helm release to time out after 10 minutes and prevented setup_metrics_addons.sh from running, leaving xmc_metrics missing in ClickHouse for all subsequent Nightly Examples E2E Test Suite jobs (Run 40629962765).

Key Changes

  • Self-Healing ClickHouse Schema Initialization (deploy/addons/metrics/):
    • Updated deploy/addons/metrics/setup_metrics_addons.sh and deploy/addons/metrics/clickhouse/README.md to create ConfigMap clickhouse-init-scripts from deploy/clickhouse/schema.sql and ensure both xmc and xmc-metrics namespaces exist upfront.
    • Updated deploy/addons/metrics/manifests/metrics-addons.yaml to mount the clickhouse-init-scripts ConfigMap at /docker-entrypoint-initdb.d with CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS=1, so clickhouse-0 automatically applies schema.sql (CREATE TABLE/VIEW IF NOT EXISTS) on every pod startup or restart.
    • Added an HTTP readinessProbe (/ping on port 8123) to StatefulSet/clickhouse so Kubernetes rollouts and service endpoints wait until /entrypoint.sh finishes running /docker-entrypoint-initdb.d/init.sql on its loopback-only bootstrap server and starts the main ClickHouse server.
  • Self-Healing Redpanda Topic Provisioning (deploy/addons/metrics/manifests/metrics-addons.yaml):
    • Enabled publishNotReadyAddresses: true on the headless Service/redpanda so redpanda-0.redpanda.xmc.svc.cluster.local resolves during container startup hooks.
    • Added a lifecycle.postStart hook to StatefulSet/redpanda that polls until rpk topic describe xmc-metrics or rpk topic create xmc-metrics --partitions 128 --replicas 1 succeeds on every pod start (and before Kubernetes marks the container Ready).
    • Added manifest and setup script consistency assertions in deploy/clickhouse/schema_test.py (and exported the manifest/script files in deploy/addons/metrics/BUILD.bazel and deploy/clickhouse/BUILD.bazel).
  • GKE Deployment Workflow Ordering & Diagnostics (.github/workflows/deploy-gke.yml):
    • Added a Pre-Deploy Metrics Addons on Existing Cluster step before Execute GKE Deployment Pipeline so existing clusters reconcile Redpanda and ClickHouse before xmc_app rolls out ingestion-gateway-deployment.
    • Updated Collect Diagnostics on Failure to capture pod statuses, descriptions, and current/previous container logs across all pods in both xmc and xmc-metrics namespaces.

Assumptions

  • Verified: clickhouse/clickhouse-server:24.3-alpine /entrypoint.sh executes /docker-entrypoint-initdb.d/*.sql via clickhouse-client --multiquery on a loopback-only (127.0.0.1) bootstrap server on every container start when CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS=1 is set, and only listens on <PodIP>:8123 (/ping) once initialization finishes and the main ClickHouse server starts.
  • Verified: docker.redpanda.com/redpandadata/redpanda:v24.1.1 includes /bin/sh, rpk, seq, and sleep for the postStart topic creation hook.

Verification & Testing

  • Executed bazel test //deploy/clickhouse/... (passed).
  • Verified end-to-end on GKE at HEAD (ba25d6981) via XMC Nightly build (Run 40695549515) and Nightly Examples E2E Test Suite (Run 40697009915) — all 16 example workloads passed.
  • Verified diff size via ./tools/analyze_diff_size.py --base-ref origin/main... (86 prod lines in deploy/workflow manifests, 14 test lines, 4 doc lines — zero Go application binary changes).

Related Issues / Bugs

TAG=agy
CONV=817ce1b8-5e4c-47e5-839f-333d06bf7842

…ent to pod rescheduling

When GKE node pools roll or pods restart, the ephemeral Redpanda and
ClickHouse metrics addons lose the `xmc-metrics` topic and ClickHouse tables
(`xmc_metrics`, `xmc_metrics_queue`, and materialized views). Additionally,
during GKE upgrades (`deploy-gke.yml`), the `xmc_app` Helm release rolled out
`ingestion-gateway-deployment` before `setup_metrics_addons.sh` ran, causing
`ingestion-gateway` to fail its single-shot startup topic topology check and
blocking the Helm rollout.

Key changes:
- Mount `deploy/clickhouse/schema.sql` into ClickHouse via ConfigMap
  `clickhouse-init-scripts` at `/docker-entrypoint-initdb.d/init.sql` with
  `CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS=1` so schema initialization runs
  automatically on every container startup.
- Add a `postStart` lifecycle hook on the Redpanda container (with
  `publishNotReadyAddresses: true` on the headless service) to automatically
  ensure the `xmc-metrics` topic (`128` partitions, `1` replica) is created
  whenever `redpanda-0` starts.
- Add `ValidateTopicTopologyWithRetry` in `ingestiongateway` so startup topic
  validation retries transiently missing topics or broker readiness errors for
  up to 30s (bounded by context) before failing.
- Pre-provision metrics addons before running `dev_env.py gke-deploy` when
  upgrading an existing GKE cluster in `deploy-gke.yml`, and expand failure
  diagnostics to capture pod descriptions and logs across both `xmc` and
  `xmc-metrics` namespaces.

TAG=agy
CONV=817ce1b8-5e4c-47e5-839f-333d06bf7842

@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 retry mechanism for Kafka topic topology validation (ValidateTopicTopologyWithRetry) and enhances the self-healing capabilities of the in-cluster metrics stack by automating ClickHouse schema initialization and Redpanda topic creation. Feedback on these changes highlights two key improvements: adding defensive parameter validation to the retry function to prevent potential nil pointer panics or CPU-burning busy loops, and removing the optional: true flag from the ClickHouse initialization script volume mount to avoid container startup failures when using subPath with a missing ConfigMap.

@janzak-dev janzak-dev changed the title fix(metrics): make ClickHouse, Redpanda, and ingestion gateway resilient to pod rescheduling fix(metrics): make ClickHouse and Redpanda addons resilient to pod rescheduling Oct 28, 2026
Gate ClickHouse pod readiness on HTTP /ping (port 8123) so Kubernetes
rollouts and Service endpoints wait until /entrypoint.sh finishes
running /docker-entrypoint-initdb.d/init.sql on its loopback-only
bootstrap server and starts the main ClickHouse server.

TAG=agy
@janzak-dev janzak-dev added the priority::2-high top of mind. should not wait. label Oct 28, 2026
@janzak-dev
janzak-dev marked this pull request as ready for review October 28, 2026 13:45
@github-actions
github-actions Bot requested a review from AntonTyb October 28, 2026 13:45
@janzak-dev
janzak-dev enabled auto-merge October 28, 2026 13:48
@janzak-dev
janzak-dev added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit c0be5f8 Oct 28, 2026
36 checks passed
@janzak-dev
janzak-dev deleted the fix/resilient-metrics-addons-deployment branch October 28, 2026 14:15

This branch was previously deployed

1 inactive deployment
xmc-nightly — ba25d698 Deployed Oct 28, 2026 by janzak-dev via Run & Verify: Multi-Pod & Multi-Container Job #107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::2-high top of mind. should not wait.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants