Skip to content

kafka: decouple topic manager tests from Sarama - #5961

Open
3AceShowHand wants to merge 3 commits into
pingcap:masterfrom
3AceShowHand:topic-manager-decouple-sarama
Open

kafka: decouple topic manager tests from Sarama#5961
3AceShowHand wants to merge 3 commits into
pingcap:masterfrom
3AceShowHand:topic-manager-decouple-sarama

Conversation

@3AceShowHand

@3AceShowHand 3AceShowHand commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: close #5885

Kafka topic manager tests depend on Sarama-specific authorization errors. This couples the behavior tests to the current Kafka client implementation and makes them harder to reuse during the franz-go migration tracked by #5881.

What is changed and how it works?

  • Add the client-independent ErrKafkaAdminAuthorizationFailed error.
  • Translate Sarama topic and cluster authorization errors at the admin adapter boundary.
  • Update topic manager tests to use the AdminClient mock and TiCDC-owned errors instead of Sarama types.
  • Expand Kafka admin adapter tests for config lookup, topic metadata, topic creation, authorization errors, general errors, and cleanup behavior.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test
  • No code

Questions

Will it cause performance regression or break compatibility?

No. The change only normalizes Kafka admin authorization errors at the adapter boundary and preserves the existing topic manager fallback behavior.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

None

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Aug 12, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign 3aceshowhand for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 12, 2026
@3AceShowHand
3AceShowHand marked this pull request as draft August 12, 2026 10:24
@ti-chi-bot ti-chi-bot Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a30b6b1-3629-487c-ac0b-4d83eb1b4c4f

📥 Commits

Reviewing files that changed from the base of the PR and between 6b42707 and 0b7df28.

📒 Files selected for processing (3)
  • downstreamadapter/sink/topicmanager/kafka_topic_manager_test.go
  • pkg/sink/kafka/admin.go
  • pkg/sink/kafka/admin_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/sink/kafka/admin.go
  • pkg/sink/kafka/admin_test.go

📝 Walkthrough

Walkthrough

Kafka admin authorization failures now map to a normalized non-fatal error. Admin operations use centralized Sarama error wrapping. Tests expand coverage for admin behavior and topic-manager scenarios.

Changes

Kafka admin error handling

Layer / File(s) Summary
Authorization error contract and centralized mapping
pkg/errors/error.go, pkg/errors/error_test.go, pkg/sink/kafka/admin.go
Adds ErrKafkaAdminAuthorizationFailed and routes Sarama authorization failures through centralized wrapping across Kafka admin operations.
Kafka admin behavior coverage
pkg/sink/kafka/admin_test.go
Adds coverage for broker and topic configuration, topic metadata, authorization mapping, and topic creation outcomes.
Topic manager scenario tests
downstreamadapter/sink/topicmanager/kafka_topic_manager_test.go
Refactors tests into parallel isolated subtests for topic creation, visibility, validation, existing topics, and authorization fallback behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant KafkaAdmin as Kafka admin operation
  participant Sarama as Sarama admin API
  participant ErrorMapper as wrapSaramaAdminError
  participant ErrorPackage as Kafka error package
  KafkaAdmin->>Sarama: Execute Kafka admin operation
  Sarama-->>KafkaAdmin: Return authorization or general error
  KafkaAdmin->>ErrorMapper: Wrap error with operation and resource
  ErrorMapper->>ErrorPackage: Classify the error
  ErrorPackage-->>KafkaAdmin: Return normalized Kafka admin error
Loading

Possibly related PRs

Suggested reviewers: lidezhu, wk989898

Poem

A rabbit checks each Kafka call,
Standard errors now cover all.
Topics wait, then become clear,
Parallel mocks keep paths sincere.
Hop by hop, the tests stand tall.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: decoupling topic-manager tests from Sarama.
Description check ✅ Passed The description includes the issue, problem, implementation details, tests, compatibility, documentation, and release note sections.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@3AceShowHand
3AceShowHand marked this pull request as ready for review August 12, 2026 13:17
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 12, 2026
@3AceShowHand 3AceShowHand changed the title kafka: topic manager decouple from the sarama kafka: decouple topic manager tests from Sarama Aug 13, 2026
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed do-not-merge/needs-linked-issue and removed do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kafka: decouple admin tests from Sarama

1 participant