Skip to content

metrics: add keyspace ID label to changefeed metrics - #5662

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
asddongmen:0716-metrics-keyspace-id
Jul 17, 2026
Merged

ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
asddongmen:0716-metrics-keyspace-id

Conversation

@asddongmen

@asddongmen asddongmen commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: close #5661

Changefeed-level owner and sink metrics expose keyspace names but not the numeric keyspace ID, which makes correlation with PD/TiDB keyspace metadata difficult.

What is changed and how it works?

  • Add a decimal keyspace_id label to ticdc_owner_checkpoint_ts_lag, ticdc_owner_status, and ticdc_sink_batch_row_count_sum.
  • Read the owner label from ChangeFeedInfo.KeyspaceID.
  • Propagate the existing DispatcherManager.keyspaceID through sink constructors into metrics.Statistics; standalone consumers and redo applier use the default keyspace ID.
  • Delete metric series with the complete label set during changefeed or sink cleanup.
  • Keep ChangeFeedID, ChangeFeedDisplayName, protobuf messages, and persisted metadata unchanged.

The sink metric is a histogram, so its _bucket, _sum, and _count series all receive the label.

Check List

Tests

  • Unit test
  • Build test: make cdc

Questions

Will it cause performance regression or break compatibility?

No material performance regression is expected. The added label changes Prometheus series identity after upgrade, so dashboards and alerts that aggregate or match exact label sets may need adjustment.

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

No repository documentation is changed. The metric compatibility impact is described above.

Release note

Add the `keyspace_id` label to changefeed owner status, checkpoint lag, and sink batch row count metrics.

Summary by CodeRabbit

  • Enhancements
    • Added keyspace-aware labeling to changefeed, checkpoint, and sink execution metrics.
    • Improved metric cleanup when changefeeds stop, including status and checkpoint metrics.
    • Propagated keyspace context across supported sink types for more accurate metric attribution.
  • Tests
    • Expanded coverage to verify keyspace labels and complete metric cleanup.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jul 16, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jul 16, 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

Run ID: 11503855-2a97-4b5d-b04c-0d542a473d21

📥 Commits

Reviewing files that changed from the base of the PR and between dd07f60 and cb906dd.

📒 Files selected for processing (30)
  • cmd/kafka-consumer/writer.go
  • cmd/pulsar-consumer/writer.go
  • cmd/storage-consumer/consumer.go
  • coordinator/changefeed/changefeed_db.go
  • coordinator/changefeed/changefeed_db_test.go
  • coordinator/controller.go
  • coordinator/controller_test.go
  • downstreamadapter/dispatchermanager/dispatcher_manager.go
  • downstreamadapter/sink/blackhole/sink.go
  • downstreamadapter/sink/blackhole/sink_test.go
  • downstreamadapter/sink/cloudstorage/sink.go
  • downstreamadapter/sink/cloudstorage/sink_test.go
  • downstreamadapter/sink/cloudstorage/writer_test.go
  • downstreamadapter/sink/kafka/sink.go
  • downstreamadapter/sink/kafka/sink_test.go
  • downstreamadapter/sink/mysql/sink.go
  • downstreamadapter/sink/mysql/sink_test.go
  • downstreamadapter/sink/pulsar/sink.go
  • downstreamadapter/sink/pulsar/sink_test.go
  • downstreamadapter/sink/sink.go
  • downstreamadapter/sink/sink_test.go
  • pkg/applier/redo.go
  • pkg/applier/redo_test.go
  • pkg/metrics/changefeed.go
  • pkg/metrics/changefeed_test.go
  • pkg/metrics/sink.go
  • pkg/metrics/statistics.go
  • pkg/metrics/statistics_test.go
  • pkg/sink/mysql/mysql_writer_ddl_ts_test.go
  • pkg/sink/mysql/mysql_writer_test.go

📝 Walkthrough

Walkthrough

The change propagates numeric keyspace IDs through sink constructors and statistics, adds keyspace_id labels to owner and sink metrics, and updates metric collection, cleanup, and tests.

Changes

Keyspace-aware metrics

Layer / File(s) Summary
Metric label contracts and statistics
pkg/metrics/..., pkg/metrics/statistics_test.go
Changefeed gauges and sink batch histograms include formatted keyspace_id labels; statistics registration and cleanup use the keyspace ID.
Sink construction propagation
downstreamadapter/sink/..., downstreamadapter/dispatchermanager/..., cmd/*-consumer/..., pkg/applier/..., pkg/sink/mysql/*_test.go
Sink factories, constructors, runtime call sites, and tests pass keyspace IDs through to sink statistics.
Owner metric collection and cleanup
coordinator/controller.go, coordinator/changefeed/changefeed_db.go, coordinator/*_test.go
Owner status and checkpoint metrics use keyspace-aware labels, including shutdown deletion paths.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested labels: lgtm, approved

Suggested reviewers: hongyunyan, lidezhu, flowbehappy

Poem

I’m a rabbit with labels in tow,
Keyspace numbers now neatly flow.
Through sinks they hop,
Old gauges now stop,
And clean metrics bloom as they go.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% 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
Title check ✅ Passed The title clearly summarizes the main change: adding keyspace ID labels to changefeed metrics.
Description check ✅ Passed The PR description includes the issue number, change summary, tests, compatibility notes, and release note.
Linked Issues check ✅ Passed The changes match #5661 by adding keyspace_id to the listed metrics and propagating the correct keyspace IDs.
Out of Scope Changes check ✅ Passed The extra sink, metrics, and test updates are all supporting changes required to propagate and clean up the new label.
✨ Finishing Touches
🧪 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.

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 16, 2026

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

Copy link
Copy Markdown

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 adds the keyspace_id label to three TiCDC metrics: ticdc_owner_status, ticdc_owner_checkpoint_ts_lag, and ticdc_sink_batch_row_count. To propagate the keyspace ID to the sink metrics, the keyspaceID parameter is now explicitly passed down the sink constructor chain to metrics.NewStatistics. The review feedback recommends exporting the unexported formatKeyspaceID helper function as FormatKeyspaceID from the metrics package and reusing it across the coordinator and statistics modules, which eliminates duplicate string formatting logic and allows removing several unnecessary strconv imports.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/metrics/changefeed.go Resolved
Comment thread pkg/metrics/statistics.go Resolved
Comment thread coordinator/changefeed/changefeed_db.go Resolved
Comment thread coordinator/changefeed/changefeed_db.go Resolved
Comment thread coordinator/controller.go Resolved
Comment thread coordinator/controller.go Resolved
Comment thread coordinator/controller.go Resolved
Signed-off-by: dongmen <414110582@qq.com>
@asddongmen
asddongmen force-pushed the 0716-metrics-keyspace-id branch from e3ed6cf to e54f90b Compare July 16, 2026 07:28
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 16, 2026
Signed-off-by: dongmen <414110582@qq.com>
@asddongmen
asddongmen marked this pull request as ready for review July 16, 2026 12:18
@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 Jul 16, 2026
@asddongmen

Copy link
Copy Markdown
Collaborator Author

/test all

@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jul 16, 2026
@asddongmen

Copy link
Copy Markdown
Collaborator Author

/retest

@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hongyunyan, lidezhu

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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 17, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-16 12:39:28.151174016 +0000 UTC m=+890154.187269073: ☑️ agreed by lidezhu.
  • 2026-07-17 02:23:14.333626153 +0000 UTC m=+939580.369721209: ☑️ agreed by hongyunyan.

@ti-chi-bot
ti-chi-bot Bot merged commit 5d55dc6 into pingcap:master Jul 17, 2026
12 checks passed
@asddongmen

Copy link
Copy Markdown
Collaborator Author

/cherry-pick release-nextgen-202603

@ti-chi-bot

Copy link
Copy Markdown
Member

@asddongmen: new pull request created to branch release-nextgen-202603: #5666.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-nextgen-202603

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 ti-community-infra/tichi repository.

asddongmen added a commit to ti-chi-bot/ticdc that referenced this pull request Jul 17, 2026
asddongmen added a commit to ti-chi-bot/ticdc that referenced this pull request Jul 17, 2026
asddongmen added a commit that referenced this pull request Jul 18, 2026
* metrics: add keyspace ID label to changefeed metrics (#5662)

close #5661

* coordinator: simplify keyspace ID lookup

---------

Co-authored-by: dongmen <20351731+asddongmen@users.noreply.github.com>
Co-authored-by: dongmen <414110582@qq.com>
@3AceShowHand

Copy link
Copy Markdown
Collaborator

/cherry-pick release-8.5

@ti-chi-bot

Copy link
Copy Markdown
Member

@3AceShowHand: new pull request created to branch release-8.5: #6526.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-8.5

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 ti-community-infra/tichi repository.

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

Labels

approved lgtm 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add keyspace_id label to changefeed metrics

5 participants