ref(cli): make attach-partitions output legible for long runs - #8432
Merged
Conversation
The output did not say whether a run was a dry run, so the only signal was the wording of each line, and "Would attach partition 90-20240212" named neither the source nor the destination. An operator reading a scrollback could not tell a rehearsal from a real attach, or which tables were involved. Announce the mode and the table pair before any work, and qualify every partition line with the source and destination.
attach-partitions reported progress with click.echo, so lines like "Attached partition 90-20260608 ..." and "Attached 1 partition(s) ..." carried no timestamps. On long runs that made it impossible to tell how long an individual ATTACH took, or when a run stalled. Route the output through a module logger instead, matching the convention in the rest of snuba.cli. LOG_FORMAT is "%(asctime)s %(message)s", so every line is now timestamped: 2026-09-03 12:48:40,815 Attached partition 90-20260608 from d.src to d.dst 2026-09-03 12:48:40,815 [EXECUTE] Attached 1 partition(s) from d.src to d.dst Two behaviour changes follow from using logging: - The output moves from stdout to stderr, since logging.basicConfig installs a StreamHandler on stderr. - --log-level now gates these lines, so --log-level WARNING silences them.
pbhandari
approved these changes
Sep 3, 2026
phacops
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
attach-partitionswalks partitions one at a time and can run for a longtime, but its progress output was hard to act on. Two commits fix that.
State the mode and tables
The output never said whether a run was a dry run, so the only signal was
the wording of each line, and
Would attach partition 90-20240212namedneither the source nor the destination. Reading a scrollback, you could not
tell a rehearsal from a real attach, or which tables were involved.
The mode and table pair are now announced before any work, and every
partition line is qualified with both tables.
Add timestamps
Progress went through
click.echo, so no line carried a timestamp. On a longrun there was no way to tell how long an individual
ATTACHtook, or when arun stalled.
The output now goes through a module logger, matching the convention in the
rest of
snuba.cli.LOG_FORMATis"%(asctime)s %(message)s", so lines aretimestamped:
Behaviour changes to be aware of
Moving to
logginghas two consequences beyond formatting:logging.basicConfiginstallsa
StreamHandleron stderr. This would break any pipeline parsing thiscommand's stdout. I am not aware of one, but say the word and I will attach a
stdout handler instead.
--log-levelnow gates these lines, so--log-level WARNINGsilencesprogress output.
Also worth a look: a
--partition-idrun now logs twice per partition, becauseattach_partition_from_tablealready emits its own "Attaching partition" line.Previously the two went to different streams so the overlap was invisible. Happy
to drop the CLI line or demote the library one to
debug.Testing
tests/clickhouse/test_partition_management.pypasses (43 tests);mypyand thepre-commit
ruffhooks are clean. No test asserted on this CLI's output beforeor after.