Skip to content

config: table-router pr1 add changefeed level configuration#4654

Merged
ti-chi-bot[bot] merged 3 commits into
masterfrom
table-route-pr1-config-api
Mar 31, 2026
Merged

config: table-router pr1 add changefeed level configuration#4654
ti-chi-bot[bot] merged 3 commits into
masterfrom
table-route-pr1-config-api

Conversation

@3AceShowHand
Copy link
Copy Markdown
Collaborator

@3AceShowHand 3AceShowHand commented Mar 31, 2026

What problem does this PR solve?

Issue Number: close #4655

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

`None`

Summary by CodeRabbit

  • New Features
    • Added per-rule target schema/table routing fields (API and config) and validation of table-routing expressions.
  • Bug Fixes
    • Preserve dispatch rule entries when stripping MQ-only sink fields; only MQ-specific fields are cleared.
  • Tests
    • Added tests covering table routing validation and routing-expression validation.
  • Chores
    • Introduced a standardized error for invalid table routing rules.

@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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 31, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

Adds per-rule table routing fields (TargetSchema, TargetTable) across API, tests, and internal config; implements routing-expression validation and preserves non-MQ dispatch rules while clearing MQ-only fields; introduces a new error for invalid routing rules and test coverage for the validation.

Changes

Cohort / File(s) Summary
API & Test Models
api/v2/model.go, tests/integration_tests/api_v2/model.go
Added TargetSchema and TargetTable JSON fields to DispatchRule and updated API↔internal conversions to carry these fields.
Internal Sink Config & Validation
pkg/config/sink.go
Added TargetSchema/TargetTable to internal DispatchRule; added validateTableRoute() and validateRoutingExpression() (regex-based, allow literal text plus {schema}/{table}); call validation in validateAndAdjust before early MySQL-compatible return.
Changefeed MQ-field handling
pkg/config/changefeed.go
rmMQOnlyFields now retains the DispatchRules slice and clears only MQ-specific fields on each rule instead of nil-ing the whole slice.
Errors
pkg/errors/error.go
Added exported error ErrInvalidTableRoutingRule with RFC code CDC:ErrInvalidTableRoutingRule.
Tests
pkg/config/sink_test.go
Added TestValidateTableRoute, TestValidateRoutingExpression, and rejection tests for invalid routing expressions; imports RFC error package for assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Model as "API model"
    participant Converter as "API↔Internal Converter"
    participant SinkConfig as "SinkConfig"
    participant Validator as "validateRoutingExpression"
    participant Errors

    Client->>API_Model: submit DispatchRule with TargetSchema/TargetTable
    API_Model->>Converter: ToInternalReplicaConfig()
    Converter->>SinkConfig: populate internal DispatchRule (includes targets)
    SinkConfig->>Validator: validateTableRoute() → validateRoutingExpression()
    alt expression invalid
        Validator->>Errors: return ErrInvalidTableRoutingRule
        Errors-->>Client: validation error
    else expression valid
        SinkConfig-->>Client: accept config
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

lgtm, approved, ok-to-test, size/XXL

Poem

🐰 I hopped through configs, neat and small,
Added targets to routes for one and all.
Patterns checked with a careful eye,
Schemas and tables now can fly ✨
— a rabbit's cheer for routing tall

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete. The 'What is changed and how it works?' section is empty, Questions section lacks answers, and test details are not provided despite multiple test types listed. Complete the 'What is changed and how it works?' section with implementation details, answer the compatibility and documentation questions, and specify which tests were added.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code changes fully implement the objective from issue #4655 to make table route configurable at the changefeed level by adding TargetSchema and TargetTable fields with validation.
Out of Scope Changes check ✅ Passed All changes are directly related to the table route configuration objective. Modifications to API models, config validation, error handling, and tests are all necessary for the feature.
Title check ✅ Passed The title is directly related to the main change: adding table-router configuration at the changefeed level, which is the primary objective across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch table-route-pr1-config-api

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


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 and usage tips.

@3AceShowHand 3AceShowHand requested a review from wk989898 March 31, 2026 09:16
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. 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. labels Mar 31, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces table routing capabilities by adding TargetSchema and TargetTable fields to the DispatchRule configuration. These fields allow users to specify downstream schema and table names using literal text or placeholders like {schema} and {table}. The changes include updates to the API models, configuration structures, and validation logic to support these new routing rules across different sink types. Feedback suggests optimizing the validation path for MySQL-compatible sinks to avoid unnecessary MQ-specific checks and refining the routing expression regex to ensure only valid identifier characters are used.

Comment thread pkg/config/sink.go
Comment thread pkg/config/sink.go
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/config/sink_test.go (1)

298-355: Add one validateAndAdjust() case for MySQL-compatible sinks.

These cases only call validateTableRoute() directly, so they will not catch a future reorder that moves Line 830 back below the MySQL/TiDB early return. Please add one validateAndAdjust() test with a tidb:// or mysql:// URI and an invalid target-schema / target-table.

🧪 Example coverage
+func TestValidateAndAdjustRejectsInvalidTableRouteForTiDB(t *testing.T) {
+	t.Parallel()
+
+	sinkURI, err := url.Parse("tidb://127.0.0.1:4000")
+	require.NoError(t, err)
+
+	cfg := &SinkConfig{
+		DispatchRules: []*DispatchRule{
+			{
+				Matcher:      []string{"db1.*"},
+				TargetSchema: "{bad}",
+			},
+		},
+	}
+
+	err = cfg.validateAndAdjust(sinkURI)
+	require.ErrorContains(t, err, "target-schema")
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/config/sink_test.go` around lines 298 - 355, Add a new table-route test
that invokes SinkConfig.validateAndAdjust() (not just validateTableRoute()) for
a MySQL-compatible sink (use a URI like "mysql://..." or "tidb://...") and
include a DispatchRule with an invalid TargetSchema or TargetTable (e.g.,
"{bad}" or invalid placeholder) so the test expects an error containing
"target-schema" or "target-table"; this ensures the early-return path for
MySQL/TiDB sinks is exercised and will catch regressions where the validation
order changes. Reference SinkConfig, validateAndAdjust, DispatchRule, and
TargetSchema/TargetTable when locating where to add the case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/config/changefeed.go`:
- Around line 500-508: The loop in RmUnusedFields() that iterates over
info.Config.Sink.DispatchRules blindly dereferences each element and can panic
if a persisted null entry was unmarshaled; modify the loop that touches
info.Config.Sink.DispatchRules so it first checks for nil (e.g., if rule == nil
{ continue }) before clearing fields like DispatcherRule, PartitionRule,
IndexName, Columns, and TopicRule, ensuring nil entries are skipped rather than
dereferenced.

---

Nitpick comments:
In `@pkg/config/sink_test.go`:
- Around line 298-355: Add a new table-route test that invokes
SinkConfig.validateAndAdjust() (not just validateTableRoute()) for a
MySQL-compatible sink (use a URI like "mysql://..." or "tidb://...") and include
a DispatchRule with an invalid TargetSchema or TargetTable (e.g., "{bad}" or
invalid placeholder) so the test expects an error containing "target-schema" or
"target-table"; this ensures the early-return path for MySQL/TiDB sinks is
exercised and will catch regressions where the validation order changes.
Reference SinkConfig, validateAndAdjust, DispatchRule, and
TargetSchema/TargetTable when locating where to add the case.
🪄 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

Run ID: 98b286d2-c3b9-422d-9076-fb31ae17a91f

📥 Commits

Reviewing files that changed from the base of the PR and between 8a067c4 and 43ac52a.

📒 Files selected for processing (6)
  • api/v2/model.go
  • pkg/config/changefeed.go
  • pkg/config/sink.go
  • pkg/config/sink_test.go
  • pkg/errors/error.go
  • tests/integration_tests/api_v2/model.go

Comment thread pkg/config/changefeed.go
@3AceShowHand
Copy link
Copy Markdown
Collaborator Author

/test all

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/config/sink.go`:
- Around line 886-899: The validateTableRoute method should guard against nil
entries in s.DispatchRules to avoid panics: in SinkConfig.validateTableRoute
iterate over s.DispatchRules and if a rule is nil return a clear validation
error (e.g., "dispatch rule is null") instead of dereferencing it; then continue
validating rule.TargetSchema and rule.TargetTable as before—this same nil-check
will also protect subsequent dispatcher/partition normalization loops that
assume non-nil DispatchRule objects.
🪄 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

Run ID: 65364691-1047-48b7-8379-bccfb59a46f7

📥 Commits

Reviewing files that changed from the base of the PR and between 43ac52a and e552c92.

📒 Files selected for processing (2)
  • pkg/config/changefeed.go
  • pkg/config/sink.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/config/changefeed.go

Comment thread pkg/config/sink.go
@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Mar 31, 2026
@ti-chi-bot ti-chi-bot Bot added the lgtm label Mar 31, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 31, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flowbehappy, wk989898

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

The pull request process is described 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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Mar 31, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 31, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-03-31 10:25:26.098474885 +0000 UTC m=+260731.303834942: ☑️ agreed by flowbehappy.
  • 2026-03-31 10:26:09.070706127 +0000 UTC m=+260774.276066574: ☑️ agreed by wk989898.

@3AceShowHand
Copy link
Copy Markdown
Collaborator Author

/retest

@3AceShowHand
Copy link
Copy Markdown
Collaborator Author

/test all

@3AceShowHand 3AceShowHand changed the title config: add configuration for the table route functionality table route: pr1-add changefeed level configuration Mar 31, 2026
@3AceShowHand 3AceShowHand changed the title table route: pr1-add changefeed level configuration config: table-router pr1 add changefeed level configuration Mar 31, 2026
@tenfyzhong
Copy link
Copy Markdown
Collaborator

/test pull-cdc-mysql-integration-light-next-gen

@3AceShowHand
Copy link
Copy Markdown
Collaborator Author

/retest

@tenfyzhong
Copy link
Copy Markdown
Collaborator

/override pull-cdc-mysql-integration-light-next-gen

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 31, 2026

@tenfyzhong: Overrode contexts on behalf of tenfyzhong: pull-cdc-mysql-integration-light-next-gen

Details

In response to this:

/override pull-cdc-mysql-integration-light-next-gen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot merged commit 91fd985 into master Mar 31, 2026
21 checks passed
@ti-chi-bot ti-chi-bot Bot deleted the table-route-pr1-config-api branch March 31, 2026 16:00
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 31, 2026

@3AceShowHand: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test 74307e2 link unknown /test pull-unit-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add configuration to support the table route functionality

4 participants