Skip to content

metrics: expose IA remote-read scan details#69606

Merged
ti-chi-bot[bot] merged 1 commit into
pingcap:masterfrom
Connor1996:codex/tidb-ia-remote-read-observability
Jul 10, 2026
Merged

metrics: expose IA remote-read scan details#69606
ti-chi-bot[bot] merged 1 commit into
pingcap:masterfrom
Connor1996:codex/tidb-ia-remote-read-observability

Conversation

@Connor1996

@Connor1996 Connor1996 commented Jul 2, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: ref #69624

Problem Summary:

TiDB does not currently expose IA remote-read scan detail fields in its own observability surfaces, so operators cannot inspect remote segment count, bytes, or wait time through slow logs, statement summary, or Prometheus metrics.

What changed and how does it work?

Adds TiDB observability plumbing for IA remote-read scan details:

  • slow log fields for IA remote segment count, bytes, and wait time
  • INFORMATION_SCHEMA.SLOW_QUERY and statement summary columns
  • Prometheus metrics and metric-schema entries
  • statement summary aggregation for average/max IA remote-read values

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Expose IA remote-read segment count, bytes, and wait time in slow logs, statement summary, `INFORMATION_SCHEMA.SLOW_QUERY`, and Prometheus metrics.

Summary by CodeRabbit

  • New Features

    • Added monitoring for IA remote read segments, including per-instance segment count, segment size (bytes), and wait-time (histogram).
    • Extended slow query logs with IA remote read segment fields.
    • Added IA remote read segment columns to statement summary and information_schema views, including average and maximum values.
  • Bug Fixes

    • Improved slow-log parsing and updated test fixtures to match the expanded column layout.
    • Expanded statement-summary schema validation and aggregation coverage for IA remote read segment metrics.

@ti-chi-bot

ti-chi-bot Bot commented Jul 2, 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

@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. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds IA remote read segment count, size, and wait-time observability across execution details, Prometheus metrics, slow-query logs, information schema, and statement summaries.

Changes

IA Remote Read Segment Metrics

Layer / File(s) Summary
Core statistics extraction
pkg/util/execdetails/execdetails.go, pkg/util/execdetails/execdetails_test.go
Defines IA remote read fields, extracts count, bytes, and wait time, and tests populated and nil inputs.
Prometheus metric reporting
pkg/metrics/*, pkg/server/conn.go, pkg/infoschema/metric_table_def.go
Registers, observes, and exposes IA remote read counters and wait-duration histograms.
Slow-query log integration
pkg/sessionctx/variable/slow_log.go, pkg/executor/slow_query.go, pkg/infoschema/tables.go, pkg/sessionctx/variable/tests/*, pkg/executor/slow_query_test.go
Writes and parses IA fields and updates slow-query schema and fixtures.
Statement summary v1 aggregation
pkg/util/stmtsummary/*, pkg/infoschema/tables.go
Tracks IA sums and maxima, merges evicted data, exposes average/max columns, and validates datum conversions.
Statement summary v2 aggregation
pkg/util/stmtsummary/v2/*
Adds IA fields to records and column factories, updates add/merge behavior, and tests numeric and chunk conversions.
Information-schema validation
pkg/infoschema/test/clustertablestest/tables_test.go
Verifies IA statement-summary columns across supported tables and rejects obsolete names.

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

Sequence Diagram(s)

sequenceDiagram
  participant ScanDetail
  participant QueryMetrics
  participant SlowLog
  participant StatementSummary
  participant Prometheus

  ScanDetail->>QueryMetrics: provide IA count, bytes, and wait time
  QueryMetrics->>Prometheus: observe IA metrics
  ScanDetail->>SlowLog: format IA fields
  SlowLog->>StatementSummary: parse and expose IA columns
  ScanDetail->>StatementSummary: aggregate sums and maxima
Loading

Possibly related issues

  • pingcap/tidb#69624 — Covers the IA remote-read observability implemented across slow logs, statement summaries, information schema, and Prometheus metrics.

Suggested labels: component/statistics

Suggested reviewers: windtalker, wjhuang2016, gengliqi, D3Hunter

Poem

A rabbit counts segments under moonlit skies,
Logs their bytes where the soft wind flies.
Wait times hop into histograms bright,
Summaries bloom from data at night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.84% 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 is concise and directly summarizes the main change: exposing IA remote-read scan details in metrics.
Description check ✅ Passed The description includes the required issue line, problem summary, change summary, checklist, and release note, so it is mostly complete.
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.
✨ 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 2, 2026
@Connor1996 Connor1996 force-pushed the codex/tidb-ia-remote-read-observability branch from cbda601 to 53462ff Compare July 3, 2026 00:06
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 3, 2026
@Connor1996 Connor1996 force-pushed the codex/tidb-ia-remote-read-observability branch 2 times, most recently from 9506fba to d136bb6 Compare July 3, 2026 00:49
@Connor1996 Connor1996 marked this pull request as ready for review July 3, 2026 00:49
@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 3, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 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/util/execdetails/execdetails.go`:
- Around line 213-231: The new IA remote-read fields are not available in the
current client-go version, so the added accessor in GetIARemoteReadSegmentStats
will not compile yet. Hold this change until the github.com/tikv/client-go/v2
bump lands, or guard/remove the references to
util.ScanDetail.IaRemoteReadSegmentCount, IaRemoteReadSegmentBytes, and
IaRemoteReadSegmentDuration so this package and its tests only use fields that
exist in the current dependency.

In `@pkg/util/stmtsummary/statement_summary.go`:
- Around line 202-207: The field naming is inconsistent across the statement
summary stats, where sumIAReadSegmentCount/maxIAReadSegmentCount omit “Remote”
while the related fields and upstream source use IARemoteReadSegment/
IaRemoteReadSegmentCount. Rename the struct fields in statement_summary.go and
update all matching references in reader.go and tables.go/v2 so the exported SQL
column becomes AVG_IA_REMOTE_READ_SEGMENT_COUNT (and related names stay
aligned). Use the existing sibling symbols like sumIARemoteReadSegmentSize,
maxIARemoteReadSegmentWaitTime, and GetIARemoteReadSegmentStats as the naming
reference when updating the public INFORMATION_SCHEMA.STATEMENTS_SUMMARY
columns.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9766269a-88a6-49f6-bd9b-cf863d6f288b

📥 Commits

Reviewing files that changed from the base of the PR and between b212b93 and d136bb6.

📒 Files selected for processing (21)
  • pkg/executor/slow_query.go
  • pkg/executor/slow_query_test.go
  • pkg/infoschema/metric_table_def.go
  • pkg/infoschema/tables.go
  • pkg/infoschema/test/clustertablestest/tables_test.go
  • pkg/metrics/metrics.go
  • pkg/metrics/server.go
  • pkg/server/conn.go
  • pkg/sessionctx/variable/slow_log.go
  • pkg/sessionctx/variable/tests/session_test.go
  • pkg/util/execdetails/execdetails.go
  • pkg/util/execdetails/execdetails_test.go
  • pkg/util/stmtsummary/BUILD.bazel
  • pkg/util/stmtsummary/evicted.go
  • pkg/util/stmtsummary/reader.go
  • pkg/util/stmtsummary/statement_summary.go
  • pkg/util/stmtsummary/statement_summary_test.go
  • pkg/util/stmtsummary/v2/BUILD.bazel
  • pkg/util/stmtsummary/v2/column.go
  • pkg/util/stmtsummary/v2/column_test.go
  • pkg/util/stmtsummary/v2/record.go

Comment thread pkg/util/execdetails/execdetails.go
Comment thread pkg/util/stmtsummary/statement_summary.go Outdated
@Connor1996 Connor1996 force-pushed the codex/tidb-ia-remote-read-observability branch from d136bb6 to a7faa73 Compare July 9, 2026 03:21
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 35.89744% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.8862%. Comparing base (59ca788) to head (486115f).

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69606        +/-   ##
================================================
- Coverage   76.3197%   75.8862%   -0.4335%     
================================================
  Files          2041       2082        +41     
  Lines        560107     580295     +20188     
================================================
+ Hits         427472     440364     +12892     
- Misses       131734     137809      +6075     
- Partials        901       2122      +1221     
Flag Coverage Δ
integration 45.8229% <35.8974%> (+6.1176%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 63.9961% <ø> (+1.2748%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Connor1996 Connor1996 force-pushed the codex/tidb-ia-remote-read-observability branch 2 times, most recently from adf8b7a to d463ca5 Compare July 9, 2026 23:19

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
pkg/util/stmtsummary/v2/record_test.go (1)

25-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test only exercises IaRemoteReadSegmentCount, not Size or WaitTime.

The count assertions are correct (Sum=3→6, Max=3 after merge), and the JSON key presence/absence checks are a good defensive measure. However, since only IaRemoteReadSegmentCount is set on the ScanDetail, the SumIARemoteReadSegmentSize/MaxIARemoteReadSegmentSize and SumIARemoteReadSegmentWaitTime/MaxIARemoteReadSegmentWaitTime paths in NewStmtRecord and Merge (record.go lines 329–340, 547–558) are not validated with non-trivial values. Consider also setting IaRemoteReadSegmentSize and IaRemoteReadSegmentWaitTime on the fixture to cover those branches.

Also applies to: 73-74, 91-92, 111-114

🤖 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 `@pkg/util/stmtsummary/v2/record_test.go` around lines 25 - 27, The test
fixture only covers remote read segment count, leaving size and wait-time
aggregation untested. In TestStmtRecord and the related cases, initialize
ScanDetail.IaRemoteReadSegmentSize and IaRemoteReadSegmentWaitTime with non-zero
values, then add or update Sum/Max assertions after NewStmtRecord and Merge to
verify their aggregation and JSON output paths.
pkg/util/stmtsummary/evicted_test.go (1)

379-380: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test only covers IARemoteReadSegmentCount, not Size or WaitTime.

The merge math for count is correct (sum 8+8=16, max max(3,5)=5). However, sumIARemoteReadSegmentSize, maxIARemoteReadSegmentSize, sumIARemoteReadSegmentWaitTime, and maxIARemoteReadSegmentWaitTime are left at zero in both fixtures, so the corresponding addInfo branches (evicted.go lines 309–316) are not exercised with non-trivial values. Consider populating those fields to validate the size and wait-time merge logic.

Also applies to: 479-480, 586-587

🤖 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 `@pkg/util/stmtsummary/evicted_test.go` around lines 379 - 380, Extend the
relevant fixtures in the evicted statement-summary tests, including the cases
around the existing IARemoteReadSegmentCount fields and the additional
referenced fixtures, by assigning non-zero values to sumIARemoteReadSegmentSize,
maxIARemoteReadSegmentSize, sumIARemoteReadSegmentWaitTime, and
maxIARemoteReadSegmentWaitTime. Update the expected merged results to verify the
corresponding addInfo merge branches for size and wait time, not just count.
🤖 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.

Nitpick comments:
In `@pkg/util/stmtsummary/evicted_test.go`:
- Around line 379-380: Extend the relevant fixtures in the evicted
statement-summary tests, including the cases around the existing
IARemoteReadSegmentCount fields and the additional referenced fixtures, by
assigning non-zero values to sumIARemoteReadSegmentSize,
maxIARemoteReadSegmentSize, sumIARemoteReadSegmentWaitTime, and
maxIARemoteReadSegmentWaitTime. Update the expected merged results to verify the
corresponding addInfo merge branches for size and wait time, not just count.

In `@pkg/util/stmtsummary/v2/record_test.go`:
- Around line 25-27: The test fixture only covers remote read segment count,
leaving size and wait-time aggregation untested. In TestStmtRecord and the
related cases, initialize ScanDetail.IaRemoteReadSegmentSize and
IaRemoteReadSegmentWaitTime with non-zero values, then add or update Sum/Max
assertions after NewStmtRecord and Merge to verify their aggregation and JSON
output paths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 37685cff-733d-401a-9eb5-bd5a37109414

📥 Commits

Reviewing files that changed from the base of the PR and between adf8b7a and d463ca5.

📒 Files selected for processing (23)
  • pkg/executor/slow_query.go
  • pkg/executor/slow_query_test.go
  • pkg/infoschema/metric_table_def.go
  • pkg/infoschema/tables.go
  • pkg/infoschema/test/clustertablestest/tables_test.go
  • pkg/metrics/metrics.go
  • pkg/metrics/server.go
  • pkg/server/conn.go
  • pkg/sessionctx/variable/slow_log.go
  • pkg/sessionctx/variable/tests/session_test.go
  • pkg/util/execdetails/execdetails.go
  • pkg/util/execdetails/execdetails_test.go
  • pkg/util/stmtsummary/BUILD.bazel
  • pkg/util/stmtsummary/evicted.go
  • pkg/util/stmtsummary/evicted_test.go
  • pkg/util/stmtsummary/reader.go
  • pkg/util/stmtsummary/statement_summary.go
  • pkg/util/stmtsummary/statement_summary_test.go
  • pkg/util/stmtsummary/v2/BUILD.bazel
  • pkg/util/stmtsummary/v2/column.go
  • pkg/util/stmtsummary/v2/column_test.go
  • pkg/util/stmtsummary/v2/record.go
  • pkg/util/stmtsummary/v2/record_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/util/stmtsummary/BUILD.bazel
🚧 Files skipped from review as they are similar to previous changes (17)
  • pkg/sessionctx/variable/tests/session_test.go
  • pkg/util/execdetails/execdetails_test.go
  • pkg/sessionctx/variable/slow_log.go
  • pkg/util/stmtsummary/v2/BUILD.bazel
  • pkg/metrics/server.go
  • pkg/infoschema/tables.go
  • pkg/util/stmtsummary/v2/column_test.go
  • pkg/executor/slow_query.go
  • pkg/server/conn.go
  • pkg/util/stmtsummary/v2/record.go
  • pkg/infoschema/metric_table_def.go
  • pkg/metrics/metrics.go
  • pkg/util/stmtsummary/reader.go
  • pkg/util/execdetails/execdetails.go
  • pkg/executor/slow_query_test.go
  • pkg/util/stmtsummary/statement_summary_test.go
  • pkg/util/stmtsummary/statement_summary.go

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 10, 2026
@ti-chi-bot ti-chi-bot Bot added the lgtm label Jul 10, 2026
@ti-chi-bot ti-chi-bot Bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 10, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-10 04:30:09.688502202 +0000 UTC m=+342395.724597258: ☑️ agreed by pingyu.
  • 2026-07-10 07:35:05.366062677 +0000 UTC m=+353491.402157743: ☑️ agreed by coocood.

@bb7133 bb7133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot

ti-chi-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, coocood, pingyu, XuHuaiyu

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 the approved label Jul 10, 2026
@bb7133

bb7133 commented Jul 10, 2026

Copy link
Copy Markdown
Member

Please resolve the conflict

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@Connor1996 Connor1996 force-pushed the codex/tidb-ia-remote-read-observability branch from d463ca5 to 486115f Compare July 10, 2026 21:44
@ti-chi-bot ti-chi-bot Bot merged commit b94006d into pingcap:master Jul 10, 2026
36 checks passed
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants