Skip to content

fix(worker): Centralize ClickHouse configuration (fixes #286) - #422

Open
stroland02 wants to merge 1 commit into
superloglabs:mainfrom
stroland02:fix-issue-286
Open

fix(worker): Centralize ClickHouse configuration (fixes #286)#422
stroland02 wants to merge 1 commit into
superloglabs:mainfrom
stroland02:fix-issue-286

Conversation

@stroland02

@stroland02 stroland02 commented Jul 27, 2026

Copy link
Copy Markdown

This PR centralizes the ClickHouse connection configuration into a single module, \infra/clickhouse/config.ts. Previously, the autorecovery agent read a different database (falling back to \olly) while the primary worker and backfill scripts read from \superlog. By routing all ClickHouse connections through the same environment resolution logic, this guarantees that all modules correctly resolve the same target database, fixing Issue #286.


Summary by cubic

Centralized ClickHouse connection config in apps/worker/src/infra/clickhouse/config.ts and updated all worker components to use it. This aligns autorecovery, worker, and backfill scripts to the same DB resolution and fixes #286.

  • Bug Fixes

    • Autorecovery no longer falls back to olly; all modules now read the same DB via shared envs (CLICKHOUSE_URL, CLICKHOUSE_USER, CLICKHOUSE_PASSWORD, CLICKHOUSE_DB).
  • Migration

    • If you used CLICKHOUSE_DATABASE, switch to CLICKHOUSE_DB (default remains superlog).

Written for commit 5a8524e. Summary will update on new commits.

Review in cubic

@superlog-app superlog-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observability review

  • 1 blocking

export const CLICKHOUSE_URL = process.env.CLICKHOUSE_URL ?? "http://localhost:8123";
export const CLICKHOUSE_USER = process.env.CLICKHOUSE_USER ?? "default";
export const CLICKHOUSE_PASSWORD = process.env.CLICKHOUSE_PASSWORD ?? "";
export const CLICKHOUSE_DB = process.env.CLICKHOUSE_DB ?? "superlog";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logs · blocking — Log an error when CLICKHOUSE_DB falls back to the default in a non-local environment

Add an error-level log (using the repo's existing logger) when any of the four ClickHouse env vars is absent and the process is not running locally, so operators are immediately alerted to misconfiguration rather than discovering it through opaque query failures. Without this, a deployment that omits CLICKHOUSE_DB silently targets superlog in production with no operator-visible signal.

Suggested change
export const CLICKHOUSE_DB = process.env.CLICKHOUSE_DB ?? "superlog";
export const CLICKHOUSE_URL = process.env.CLICKHOUSE_URL ?? "http://localhost:8123";
export const CLICKHOUSE_USER = process.env.CLICKHOUSE_USER ?? "default";
export const CLICKHOUSE_PASSWORD = process.env.CLICKHOUSE_PASSWORD ?? "";
export const CLICKHOUSE_DB = process.env.CLICKHOUSE_DB ?? "superlog";
import { logger } from "../../logger.js";
const _isLocal = CLICKHOUSE_URL.includes("localhost") || CLICKHOUSE_URL.includes("127.0.0.1");
if (!_isLocal) {
if (!process.env.CLICKHOUSE_URL) logger.error({ field: "CLICKHOUSE_URL" }, "ClickHouse config: required env var missing, using default");
if (!process.env.CLICKHOUSE_USER) logger.error({ field: "CLICKHOUSE_USER" }, "ClickHouse config: required env var missing, using default");
if (!process.env.CLICKHOUSE_DB) logger.error({ field: "CLICKHOUSE_DB" }, "ClickHouse config: required env var missing, using default");
}

Useful? React with 👍 / 👎.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

Re-trigger cubic

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.

Autorecovery reads a different ClickHouse database than the worker

1 participant