Repository navigation
Fix flaky Kafka integration tests: retry get_admin_client on NoBrokersAvailable - #107337
Conversation
…sAvailable The KafkaAdminClient created in helpers/kafka/common.py::get_admin_client was built with no retry. When the broker has not finished its metadata bootstrap yet, its constructor raises kafka.errors.NoBrokersAvailable, which fails the test. This most often happens in the autouse kafka_setup_teardown fixture, so a single transient hiccup fails every test in the file. Retry the same way get_kafka_producer already does (15 attempts, 1s apart), catching only NoBrokersAvailable so genuine failures still surface after the retries are exhausted. The retries argument defaults to 15, so all existing callers are unaffected. Observed via CIDB across 7 Kafka integration test files / 10 unrelated PRs in the last 30 days (e.g. test_kafka_zone_awareness, test_mv_target_missing, test_batch_fast, test_batch_slow_2), 0 master failures (PR-randomization-only signature). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-2:20260612-134900 |
|
cc @antaljanosbenjamin — could you review this test-infra fix? |
|
Workflow [PR], commit [32d38ab] Summary: ✅ AI ReviewSummaryThis PR adds a bounded retry around Final VerdictStatus: ✅ Approve |
CI summaryCI fully finished on HEAD 32d38ab. All test jobs green. No PR-caused failures.
This is a test-helper-only change (Python; bounded retry around |
get_admin_client retries a broker that is not up yet, but its except named only kafka.errors.NoBrokersAvailable. Constructing a KafkaAdminClient runs several readiness probes, and kafka-python chooses the exception class by whether the probe names a node: a cluster-wide probe raises NoBrokersAvailable, while the controller probe (admin/client.py:219 -> _refresh_controller_id -> :279, node id given) raises NodeNotReadyError. KafkaClient.check_version documents the split in its own docstring (client_async.py:887-891); the leaf swallows NodeNotReadyError and keeps looping only when node_id is None (:918-922), and the raise is conn.py:990-992, reached when the socket to the controller does not come up inside api_version_auto_timeout_ms, which defaults to 2000 ms. So the loop covered half the class it was written for. I added that loop in ClickHouse#107337 and narrowed it to one class there deliberately; that was wrong about the class. Surfaced as test_partition_affinity.py::test_partition_affinity_settings_validation erroring out of the autouse fixture in Integration tests (amd_asan_ubsan, db disk, old analyzer, 4/6): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115294&sha=47d8d03a62c562bfc1e9a4adb9c2091d2f4a02fd&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%204%2F6%29 CIDB over 365 days at this call, split at the instant ClickHouse#107337 merged: before it, 10 NoBrokersAvailable and 1 NodeNotReadyError; after it, 0 NoBrokersAvailable and 2 NodeNotReadyError, against 23.3M Kafka integration test rows after versus 22.8M before. The retry works, and the uncaught sibling class is all that is left. This also corrects the "0 master failures" claim in ClickHouse#107337's own message: one master row exists, 2026-06-02, on test_batch_slow_7.py. Seventeen places constructed a KafkaAdminClient directly and had no retry at all. Four of them, test_kafka_bad_messages/test.py:68,229,290 and test_1.py:29, are in modules with no autouse fixture, so there that construction is the module's first admin client. All seventeen now call the helper, following ClickHouse#108635, which converged this suite's delete_topics calls onto the retrying helper the same way. Exactly one KafkaAdminClient construction is left under tests/integration, inside get_admin_client. Deliberately not a bare except Exception: IncompatibleBrokerVersion and UnrecognizedBrokerVersion are both retriable=False and must keep failing fast instead of stalling for 15 seconds with a useless message. Validated by injecting each exception at the constructor seam, with the fix reverted as a negative control: NodeNotReadyError propagates on the first attempt without the fix and is retried with it, NoBrokersAvailable is retried in both, and both non-retriable classes propagate in both. Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
helpers/kafka/common.py::get_admin_clientbuiltKafkaAdminClientwith no retry. When the broker has not finished its metadata bootstrap yet, the constructor raiseskafka.errors.NoBrokersAvailableand fails the test. It is called from the autousekafka_setup_teardownfixture in several suites, so one transient hiccup fails every test in the file.Fix: retry the same way
get_kafka_produceralready does (15 attempts, 1s apart), catching onlyNoBrokersAvailableso genuine failures still surface once retries are exhausted.retriesdefaults to 15, so all 62 existing callers are unaffected.Observed via CIDB across 7 Kafka integration test files / 10 unrelated PRs in the last 30 days (e.g.
test_kafka_zone_awareness,test_mv_target_missing,test_batch_fast,test_batch_slow_2), 0 master failures (PR-randomization-only signature).Version info
26.6.1.723