Skip to content

Fix flaky test_keeper_dynamic_log_level - #113571

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-flaky-test-keeper-dynamic-log-level
Aug 10, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-flaky-test-keeper-dynamic-log-level

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Related: #113224

test_keeper_dynamic_log_level/test.py::test_adjust_log_level writes a logger.xml with <level>trace</level>, sleeps for three seconds, runs one query, and asserts that the log holds at least one <Trace> message:

File: test_keeper_dynamic_log_level/test.py:76 - in test_adjust_log_level
    assert (
E   assert 0 >= 1
E    +  where 0 = int('0\n')
E    +    where '0\n' = exec_in_container(['bash', '-c', "grep '<Trace>' /var/log/clickhouse-server/clickhouse-server.log | wc -l"], privileged=True, user='root')

ConfigReloader::run waits for config_reload_interval_ms (2 seconds by default) and only then re-reads the whole configuration, so the gap between writing the file and the new level taking effect is that interval plus the duration of a full config reload, not the interval alone. Under MSan on a loaded runner that exceeds three seconds: the query runs while the level is still warning, nothing is logged at Trace, and the assertion fails.

The test now waits for the level to be applied instead of sleeping for a fixed time. The query is issued on every attempt, because the query is what produces the Trace messages the test looks for.

This is not specific to any pull request. The same failure, with the same message and on the same Integration tests (amd_msan, 3/8) shard, happened on master at 9d0b1a25ba7aa4579c95a65baca002d1dd7a1e47 about six hours earlier. It is rare - one failure in 11425 runs of this test on master over the last 90 days - and I did not find an open issue for it.

The test passed on retry within the same run, so the failure carries the retry_ok label, but that label is only downgraded to a success for the coverage job, so on every other shard it still turns the job red.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113224&sha=297082adba654b8bafac191c6c61b5023bcc76ef&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%203%2F8%29

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Version info

  • Merged into: 26.8.1.1103 (included in 26.8 and later)

The test wrote a `logger.xml` with `<level>trace</level>`, slept for three
seconds, ran one query, and asserted that the log holds at least one `<Trace>`
message.

`ConfigReloader::run` waits for `config_reload_interval_ms` (2 seconds by
default) and only then re-reads the whole configuration, so the gap between
writing the file and the new level taking effect is that interval plus the
duration of a full config reload, not the interval alone. Under MSan on a
loaded runner that exceeds three seconds: the query then runs while the level
is still `warning`, nothing is logged at `Trace`, and the assertion fails with
`assert 0 >= 1`.

Wait for the level to be applied instead of sleeping for a fixed time. The
query is issued on every attempt, because the query is what produces the
`Trace` messages the test looks for.

The same failure happened on `master` at `9d0b1a25ba7aa4579c95a65baca002d1dd7a1e47`,
so it is not specific to any pull request.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113224&sha=297082adba654b8bafac191c6c61b5023bcc76ef&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%203%2F8%29
#113224

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2d05e56]

Summary: ✅


AI Review

Summary

This PR now differs from master only in the implementation details of test_keeper_dynamic_log_level: it replaces the open-coded polling loop with wait_condition, factors the trace-count helpers, and removes the per-attempt sync. After reviewing the current diff, the prior discussion, and the wait_condition contract, I did not find a remaining correctness or reliability issue in the revised test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 5, 2026
alexey-milovidov and others added 2 commits August 6, 2026 17:01
The server and the `grep` run in the same container and kernel, so log
writes are visible through the page cache immediately; a host-wide
filesystem flush per retry only adds I/O pressure on loaded runners.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2d05e566b with master f70042f01 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.92 MiB 687.89 MiB -3.03 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks! Can't believe we used to have such a bad test. Every sleep is a red flag, and if not accompanied with a check in a loop, it can't be right.

@alexey-milovidov alexey-milovidov self-assigned this Aug 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Aug 9, 2026
…er-dynamic-log-level

Conflict in `tests/integration/test_keeper_dynamic_log_level/test.py`:
master landed an equivalent fix for the same flakiness in
#113938 (commit
`0b51ec04cb06`), which replaces the fixed `time.sleep(3)` with a
hand-rolled 60-attempt polling loop.

Resolved in favour of this branch's version, which keeps the same
polling semantics but is the cleaner form: it reuses the existing
`wait_condition` helper instead of an open-coded loop, extracts
`count_trace_messages` and `query_and_count_trace_messages`, and drops
the host-wide `sync` call (flagged as a Major by the AI review - the
poll and the `grep` run in the same container, so the page cache already
makes the written log lines visible).

So after this merge the branch no longer changes the test's behaviour
relative to master; it only simplifies it.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and resolved the conflict in tests/integration/test_keeper_dynamic_log_level/test.py.

Note for whoever merges this: an equivalent fix for the same flakiness landed on master in the meantime via #113938 (commit 0b51ec04cb06), which replaced the fixed time.sleep(3) with an open-coded 60-attempt polling loop. I resolved in favour of this branch's version, so the remaining delta against master is purely a simplification with identical behaviour:

  • reuse the existing wait_condition helper instead of the hand-rolled loop;
  • extract count_trace_messages and query_and_count_trace_messages;
  • drop the host-wide sync call (the poll and the grep run in the same container, so the page cache already makes the written log lines visible).

If you would rather keep master's form, this PR can simply be closed - the flakiness itself is already fixed there.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 10, 2026
Merged via the queue into master with commit ef9be38 Aug 10, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-flaky-test-keeper-dynamic-log-level branch August 10, 2026 13:23
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 10, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 13, 2026
Picks up ef9be38 (ClickHouse#113571, 'Fix flaky
test_keeper_dynamic_log_level'), which was the sole remaining red on this
branch's CI and is unrelated to this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants