Skip to content

feat: add explicit --collectdatabase option - #15

Merged
lesandie merged 2 commits into
masterfrom
feat/collect-database-option
Oct 21, 2026
Merged

lesandie merged 2 commits into
masterfrom
feat/collect-database-option

Conversation

@lesandie

Copy link
Copy Markdown
Member

Summary

A production collect Job created its auxiliary table in the wrong ClickHouse database, because database qualification lived only inside COLLECTTABLEPREFIX as an embedded db.prefix_ string — easy to omit by accident. This was HANDOFF.md item #1 from that incident triage.

  • Add --collectdatabase/S3GC_COLLECTDATABASE to qualify the auxiliary/run-log tables' database explicitly (s3gc.py:245-259, prefix-resolution block at s3gc.py:677-706). A conflicting pair (differs from a database embedded in COLLECTTABLEPREFIX) fails fast with both values named. Given both with agreement, or COLLECTTABLEPREFIX alone, behavior is unchanged — no breaking change for existing deployments.
  • Fix check_samples_match_partitioning() (s3gc.py:1219+): it always checked system.tables WHERE database = currentDatabase(), so the --samples mismatch warning silently never fired once the auxiliary table lived in a different database. This was a second, independent bug the same incident exposed.
  • Remove a redundant, unused re-split of COLLECTTABLEPREFIX in do_collect() found while consolidating this logic.
  • Renderer: COLLECTDATABASE is optional, wired to S3GC_COLLECTDATABASE only when set (render.py, job.yaml.tmpl).
  • example.env and both READMEs now recommend COLLECTDATABASE as the primary way to qualify a prefix; the embedded db.prefix_ form stays documented and supported.

Spec-first TDD per CLAUDE.md: acceptance criteria are in the commit message, each covered by a test written to fail before the implementation (git log -1 for the full spec).

Test plan

  • pytest -v -m "not dev_cluster" — 120 passed (112 existing + 8 new)
  • render.py renders example.env cleanly with S3GC_COLLECTDATABASE present
  • kubeconform -strict validates the rendered manifest

🤖 Generated with Claude Code

A production collect Job created its auxiliary table in the wrong ClickHouse
database: database qualification lived only inside COLLECTTABLEPREFIX as an
embedded "db.prefix_" string, and it is easy to omit that dot by accident.
A second, independent bug in the same code path meant a mismatch warning
never fired when the table lived outside the user's current database.

Acceptance criteria:
- A new --collectdatabase/S3GC_COLLECTDATABASE option qualifies the
  auxiliary/run-log tables' database without embedding it in
  COLLECTTABLEPREFIX.
- Given both, a conflicting pair fails before any ClickHouse or S3 call,
  naming both values, instead of silently picking one.
- Given both with the same database, or COLLECTTABLEPREFIX alone, behavior
  is unchanged from before this change.
- check_samples_match_partitioning() checks the actual configured database,
  not always currentDatabase(), so the --samples mismatch warning fires
  regardless of which database the auxiliary table lives in.
- The Kubernetes renderer accepts an optional COLLECTDATABASE value and
  wires S3GC_COLLECTDATABASE into the Job only when set.
- example.env and both READMEs recommend COLLECTDATABASE as the primary way
  to qualify a prefix; the embedded db.prefix_ form remains documented and
  supported for existing deployments.

Also removes a redundant, unused re-split of COLLECTTABLEPREFIX in
do_collect() found while consolidating this logic.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T09:57:29.217854Z aa78fd1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa78fd1d12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread s3gc.py Outdated
rows = ch_client.query(
"SELECT partition_key FROM system.tables "
f"WHERE database = currentDatabase() AND name = '{tname.strip('`').split('.')[-1]}'"
f"WHERE {database_filter} AND name = '{tname.strip('`').split('.')[-1]}'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Extract the qualified table name without the backtick

When --collectdatabase or an embedded database qualifies the table, tname has the form `aux_db`.`s3gc_run_s3`, so tname.strip('').split('.')[-1]evaluates to ``s3gc_run_s3 `` with a leading backtick. The system.tables query therefore finds no row and silently skips the `--samples` mismatch warning, meaning the fix described by this commit still does not work for the newly recommended configuration; derive the unquoted table component separately before building this predicate.

Useful? React with 👍 / 👎.

@lesandie lesandie self-assigned this Oct 21, 2026
check_samples_match_partitioning() derived the table name by stripping
backticks from a qualified tname before splitting on the dot, so
`aux_db`.`s3gc_run_s3` became "`s3gc_run_s3" with a stray backtick. The
system.tables lookup then found no row and the --samples mismatch warning
was skipped silently -- in exactly the COLLECTDATABASE configuration this
branch recommends. Reported by Codex review on PR #15.

Acceptance criteria:
- With a database-qualified auxiliary table, the system.tables lookup
  matches on the unquoted table name, and a --samples mismatch warns.
- An unqualified auxiliary table keeps working unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lesandie
lesandie merged commit d7774b0 into master Oct 21, 2026
2 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.

1 participant