kafka: improve topic validation, timeout checks, and logging - #5818
Conversation
📝 WalkthroughWalkthroughKafka topic visibility and timeout validation are tightened, Kafka version selection is split into detection and assignment handling, routine Kafka logs are reduced, and Kafka log-redaction and compression log checks are removed. ChangesKafka validation
Kafka version configuration
Kafka logging and integration coverage
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/test all |
|
/test all |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: asddongmen, wk989898 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/sink/kafka/options_test.go`:
- Around line 412-414: Update the three timeout assertions in the options test
to compare DialTimeout, ReadTimeout, and WriteTimeout against the independent
expected value 10*time.Second instead of defaultTimeout. Keep the test focused
and deterministic, and do not modify the production default constant.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0a5fb09f-f336-4d97-bbb6-477ecf75455b
📒 Files selected for processing (4)
downstreamadapter/sink/topicmanager/kafka_topic_manager.godownstreamadapter/sink/topicmanager/kafka_topic_manager_test.gopkg/sink/kafka/options.gopkg/sink/kafka/options_test.go
|
/hold |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/sink/kafka/sarama_config.go`:
- Around line 224-230: Update the version-warning condition in the Sarama
configuration logic around assignedVersion so it uses the detected broker
version rather than maxKafkaVersion: only compare versions when detection did
not reach its detection ceiling, and warn when assignedVersion is greater than
detectedVersion. Preserve the existing warning message and structured fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d34319e9-28b4-471a-ae82-aef15fe0bd2f
📒 Files selected for processing (8)
downstreamadapter/sink/kafka/sink.godownstreamadapter/sink/topicmanager/kafka_topic_manager.gopkg/sink/kafka/admin.gopkg/sink/kafka/sarama_async_producer.gopkg/sink/kafka/sarama_config.gopkg/sink/kafka/sarama_config_test.gotests/integration_tests/log_redaction/run.shtests/integration_tests/run_light_it_in_ci.sh
💤 Files with no reviewable changes (4)
- pkg/sink/kafka/sarama_async_producer.go
- pkg/sink/kafka/admin.go
- tests/integration_tests/log_redaction/run.sh
- downstreamadapter/sink/kafka/sink.go
🚧 Files skipped from review as they are similar to previous changes (1)
- downstreamadapter/sink/topicmanager/kafka_topic_manager.go
|
/test all |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
downstreamadapter/sink/topicmanager/kafka_topic_manager.go (1)
288-297: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winCache the topic only after visibility succeeds.
createTopicstores the partition count beforewaitUntilTopicVisiblereturns. If metadata never appears and the wait fails, a laterGetPartitionNumcall returns this cached value immediately (Lines 98-100), bypassing the new visibility check and potentially using a topic that is still unavailable. Move the cache update into the successful post-wait path, or remove it when waiting fails.Proposed fix
func (m *kafkaTopicManager) createTopic( _ context.Context, topicName string, ) (int32, error) { // ... - m.tryUpdatePartitionsAndLogging(topicName, m.cfg.PartitionNum) - return m.cfg.PartitionNum, nil } err = m.waitUntilTopicVisible(ctx, topicName) if err != nil { return 0, err } + m.tryUpdatePartitionsAndLogging(topicName, partitionNum) log.Info(🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@downstreamadapter/sink/topicmanager/kafka_topic_manager.go` around lines 288 - 297, Update the topic creation flow around createTopic and waitUntilTopicVisible so the partition-count cache is populated only after waitUntilTopicVisible succeeds. If visibility waiting fails, remove any cache entry created by createTopic before returning the error, ensuring later GetPartitionNum calls cannot bypass the visibility check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@downstreamadapter/sink/topicmanager/kafka_topic_manager.go`:
- Around line 288-297: Update the topic creation flow around createTopic and
waitUntilTopicVisible so the partition-count cache is populated only after
waitUntilTopicVisible succeeds. If visibility waiting fails, remove any cache
entry created by createTopic before returning the error, ensuring later
GetPartitionNum calls cannot bypass the visibility check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f4e623a2-08d4-40a7-96be-e69fb3485144
📒 Files selected for processing (11)
downstreamadapter/sink/kafka/sink.godownstreamadapter/sink/topicmanager/kafka_topic_manager.gopkg/sink/kafka/admin.gopkg/sink/kafka/claimcheck/claim_check.gopkg/sink/kafka/options.gopkg/sink/kafka/options_test.gopkg/sink/kafka/sarama_async_producer.gopkg/sink/kafka/sarama_config.gopkg/sink/kafka/sarama_factory.gopkg/sink/kafka/sarama_sync_producer.gotests/integration_tests/kafka_compression/run.sh
💤 Files with no reviewable changes (1)
- tests/integration_tests/kafka_compression/run.sh
🚧 Files skipped from review as they are similar to previous changes (5)
- pkg/sink/kafka/sarama_async_producer.go
- pkg/sink/kafka/sarama_config.go
- pkg/sink/kafka/admin.go
- downstreamadapter/sink/kafka/sink.go
- pkg/sink/kafka/options.go
|
/unhold |
|
/test all |
What problem does this PR solve?
Kafka sink has several correctness and diagnosability problems:
Issue Number: close #5819
What is changed and how it works?
dial-timeout,read-timeout, andwrite-timeoutvalues withCDC:ErrKafkaInvalidConfig. Omitted values keep the existing 10-second defaults.sync_diff; generic log-redaction coverage remains in the integration suite.Check List
Tests
go test --tags=intest ./pkg/sink/kafka ./downstreamadapter/sink/topicmanager -count=1scripts/check-log-style.shgit diff --checkQuestions
Will it cause performance regression or break compatibility?
No performance regression is expected. This intentionally tightens timeout validation: explicitly configured zero or negative Kafka timeouts are now rejected. Positive values and omitted values retain their existing behavior. Kafka version selection behavior is unchanged. Kafka sink log output changes intentionally.
Do you need to update user documentation, design documentation or monitoring documentation?
No.
Release note