Skip to content

server: add logging for profiling requests#69897

Merged
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
gengliqi:add-pprof-log
Jul 20, 2026
Merged

server: add logging for profiling requests#69897
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
gengliqi:add-pprof-log

Conversation

@gengliqi

@gengliqi gengliqi commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #69896

Problem Summary:
See #69896

What changed and how does it work?

Check List

Tests

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

[2026/07/17 10:46:34.892 +08:00] [INFO] [http_status.go:230] ["profiling request received"] [method=GET] [path=/debug/pprof/mutex] [remote-addr=127.0.0.1:53315] [debug=1]
[2026/07/17 10:46:34.892 +08:00] [INFO] [http_status.go:230] ["profiling request received"] [method=GET] [path=/debug/pprof/profile] [remote-addr=127.0.0.1:53314] [seconds=30]
[2026/07/17 10:46:34.892 +08:00] [INFO] [http_status.go:230] ["profiling request received"] [method=GET] [path=/debug/pprof/heap] [remote-addr=127.0.0.1:53311]
[2026/07/17 10:46:34.892 +08:00] [INFO] [http_status.go:230] ["profiling request received"] [method=GET] [path=/debug/pprof/goroutine] [remote-addr=127.0.0.1:53312] [debug=1]

[2026/07/20 11:53:09.809 +08:00] [INFO] [http_status.go:230] ["profiling request received"] [method=GET] [path=/debug/zip] [remote-addr=127.0.0.1:63746] [seconds=1]

[2026/07/20 11:48:56.409 +08:00] [INFO] [tables.go:254] ["profiling request received"] [table=performance_schema.tidb_profile_goroutines] [conn=2631925766] [user=root@127.0.0.1] [client-ip=127.0.0.1]
[2026/07/20 11:50:03.338 +08:00] [INFO] [tables.go:254] ["profiling request received"] [table=performance_schema.tidb_profile_cpu] [conn=2631925766] [user=root@127.0.0.1] [client-ip=127.0.0.1]
  • 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.

None

Summary by CodeRabbit

  • New Features
    • Added structured profiling request logging for /debug/pprof/ routes, capturing method, path, remote address, and (when present) query parameters like seconds, debug, and gc.
    • Extended the same profiling request logging to /debug/zip.
    • Added structured “profiling request received” logging for TiDB performance schema profiling tables.
  • Tests
    • Updated debug, zip, and profiling-table tests to assert the expected profiling request log entries (including key fields and counts) alongside existing HTTP/table behavior.

u
Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 17, 2026
@coderabbitai

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

Profiling requests through pprof, debug zip, and TiDB profile tables now emit structured logs. Tests capture and verify these logs, Bazel dependencies are updated, test documentation is refreshed, and bindinfo test sharding increases from 25 to 26.

Changes

Profiling request logging

Layer / File(s) Summary
HTTP profiling logging and route wiring
pkg/server/http_status.go
Adds request metadata logging and applies it to pprof endpoints and debug zip.
HTTP logging validation
pkg/server/handler/tests/http_handler_serial_test.go, pkg/server/handler/tests/http_handler_test.go, pkg/server/handler/tests/BUILD.bazel, .agents/skills/tidb-test-guidelines/references/server-case-map.md
Captures logs and validates route-specific fields, counts, and test wiring.
Profile table logging and validation
pkg/infoschema/perfschema/tables.go, pkg/infoschema/perfschema/BUILD.bazel, pkg/util/profile/profile_test.go, pkg/util/profile/BUILD.bazel, .agents/skills/tidb-test-guidelines/references/util-case-map.md
Logs TiDB profile table requests and verifies one structured entry per queried profile table.

Bindinfo test sharding

Layer / File(s) Summary
Increase bindinfo test shards
pkg/bindinfo/tests/BUILD.bazel
Raises the bindinfo test target’s shard count from 25 to 26.

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

Suggested labels: approved

Suggested reviewers: yangkeao

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant HTTPProfiler
  participant ZapLogger
  participant ProfileTable
  Client->>HTTPProfiler: Request pprof or debug zip
  HTTPProfiler->>ZapLogger: Record profiling request metadata
  HTTPProfiler-->>Client: Return profiling response
  Client->>ProfileTable: Query tidb_profile table
  ProfileTable->>ZapLogger: Record table and connection metadata
  ProfileTable-->>Client: Return profile rows
Loading

Poem

A rabbit logs each profiling hop,
With fields recorded, none will drop.
Pprof and tables join the song,
Tests check the trail all day long.
“Hop, hop!” says Bun, “the logs are strong!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The template is mostly present, but the 'What changed and how does it work?' section is empty. Add a brief implementation summary for the logging changes and any side effects or documentation notes if needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding profiling-request logging for server endpoints.
Linked Issues check ✅ Passed The PR implements logging for /debug/pprof/, /debug/zip, and performance_schema.tidb_profile_ as requested in #69896.
Out of Scope Changes check ✅ Passed No clearly unrelated code changes stand out; the BUILD, test, and doc updates support the profiling-logging work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@gengliqi
gengliqi requested review from YangKeao, bb7133 and Copilot July 17, 2026 03:01

@YangKeao YangKeao 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 added the approved label Jul 17, 2026
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 17, 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.

🧹 Nitpick comments (2)
pkg/server/handler/tests/http_handler_serial_test.go (1)

487-488: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Reduce the profile duration to speed up the test.

The test route /debug/pprof/profile?seconds=5 (defined earlier in debugRoutes) makes the test suite wait for 5 seconds. To save test execution time without losing coverage, consider reducing this duration to 1 second. You will need to update both the route definition and this assertion.

⚡ Proposed fixes to reduce test wait time

Update the assertion:

-	require.Len(t, pprofLogs.FilterField(zap.String("path", "/debug/pprof/profile")).
-		FilterField(zap.String("seconds", "5")).All(), 1)
+	require.Len(t, pprofLogs.FilterField(zap.String("path", "/debug/pprof/profile")).
+		FilterField(zap.String("seconds", "1")).All(), 1)

And update the corresponding route definition earlier in debugRoutes:

-		"/debug/pprof/profile?seconds=5",
+		"/debug/pprof/profile?seconds=1",
🤖 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/server/handler/tests/http_handler_serial_test.go` around lines 487 - 488,
Reduce the pprof profile duration from 5 seconds to 1 second in the debugRoutes
definition, and update the corresponding assertion in the profile test to expect
seconds="1"; keep the existing route coverage and log filtering intact.
pkg/server/http_status.go (1)

364-369: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Log the /debug/zip endpoint which also collects profiles.

Since the /debug/zip endpoint (defined around line 464) internally triggers CPU, heap, and goroutine profile collections which consume significant resources, consider wrapping it with withPProfRequestLog as well to ensure these collections are properly logged.

🛠️ Proposed fix for the `/debug/zip` handler

Update the /debug/zip handler registration:

-	router.HandleFunc("/debug/zip", func(w http.ResponseWriter, r *http.Request) {
+	router.HandleFunc("/debug/zip", withPProfRequestLog(func(w http.ResponseWriter, r *http.Request) {

(Note: If /debug/zip is ever uncommented in the debugRoutes slice within http_handler_serial_test.go, the strings.HasPrefix(route, "/debug/pprof/") check calculating expectedPProfLogs will also need to account for it.)

🤖 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/server/http_status.go` around lines 364 - 369, Wrap the /debug/zip
handler registration with withPProfRequestLog, matching the existing profiling
endpoint registrations, so its profile collection activity is logged. Update the
related serial test’s expected PProf log calculation only if /debug/zip is
enabled there.
🤖 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/server/handler/tests/http_handler_serial_test.go`:
- Around line 487-488: Reduce the pprof profile duration from 5 seconds to 1
second in the debugRoutes definition, and update the corresponding assertion in
the profile test to expect seconds="1"; keep the existing route coverage and log
filtering intact.

In `@pkg/server/http_status.go`:
- Around line 364-369: Wrap the /debug/zip handler registration with
withPProfRequestLog, matching the existing profiling endpoint registrations, so
its profile collection activity is logged. Update the related serial test’s
expected PProf log calculation only if /debug/zip is enabled there.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3d1a6636-de1a-4ac9-b929-ea26f653452d

📥 Commits

Reviewing files that changed from the base of the PR and between 57b5f22 and a7dd559.

📒 Files selected for processing (4)
  • .agents/skills/tidb-test-guidelines/references/server-case-map.md
  • pkg/server/handler/tests/BUILD.bazel
  • pkg/server/handler/tests/http_handler_serial_test.go
  • pkg/server/http_status.go

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 15.38462% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.4948%. Comparing base (d573e28) to head (8b84717).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69897        +/-   ##
================================================
- Coverage   76.3206%   75.4948%   -0.8259%     
================================================
  Files          2041       2086        +45     
  Lines        559973     583840     +23867     
================================================
+ Hits         427375     440769     +13394     
- Misses       131697     140790      +9093     
- Partials        901       2281      +1380     
Flag Coverage Δ
integration 45.6228% <15.3846%> (+5.9175%) ⬆️

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

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

Copilot AI 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.

Pull request overview

Adds structured request logging for /debug/pprof/* endpoints on the status HTTP server, improving observability for when/where profiles are collected (per issue #69896).

Changes:

  • Introduce a withPProfRequestLog wrapper to emit structured fields (method/path/remote-addr + selected query params) for pprof requests.
  • Wrap all /debug/pprof/* handlers (explicit routes and the PathPrefix fallback) to ensure consistent logging coverage.
  • Extend existing debug-route tests to assert the expected pprof log entries are emitted, and update Bazel deps/docs accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/server/http_status.go Adds the pprof request logging wrapper and applies it to all pprof routes on the status server router.
pkg/server/handler/tests/http_handler_serial_test.go Updates TestDebugRoutes to capture and assert structured pprof request logs via zaptest/observer.
pkg/server/handler/tests/BUILD.bazel Adds the zaptest/observer Bazel dependency for the updated test.
.agents/skills/tidb-test-guidelines/references/server-case-map.md Updates the server test map to reflect debug route logging coverage in http_handler_serial_test.go.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gengliqi

Copy link
Copy Markdown
Contributor Author

/hold

@ti-chi-bot ti-chi-bot Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 17, 2026
Signed-off-by: gengliqi <gengliqiii@gmail.com>
@gengliqi gengliqi changed the title server: add logging for pprof requests server: add logging for profiling requests Jul 17, 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.

🧹 Nitpick comments (1)
pkg/server/handler/tests/http_handler_test.go (1)

1256-1262: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use defer to ensure the response body is closed.

If require.Equal or httputil.DumpResponse fails and aborts the test, resp.Body.Close() at the end will not be executed, leaking the response body resource. Using defer immediately after ensuring there is no error prevents this.

♻️ Proposed refactor
 	resp, err := ts.FetchStatus("/debug/zip?seconds=1")
 	require.NoError(t, err)
+	defer resp.Body.Close()
 	require.Equal(t, http.StatusOK, resp.StatusCode)
 	b, err := httputil.DumpResponse(resp, true)
 	require.NoError(t, err)
 	require.Greater(t, len(b), 0)
-	require.NoError(t, resp.Body.Close())
🤖 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/server/handler/tests/http_handler_test.go` around lines 1256 - 1262,
Update the response handling in the test after ts.FetchStatus to defer closing
resp.Body immediately after confirming the fetch succeeded, before assertions or
httputil.DumpResponse; remove the explicit close at the end while preserving the
existing status and response-content assertions.
🤖 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/server/handler/tests/http_handler_test.go`:
- Around line 1256-1262: Update the response handling in the test after
ts.FetchStatus to defer closing resp.Body immediately after confirming the fetch
succeeded, before assertions or httputil.DumpResponse; remove the explicit close
at the end while preserving the existing status and response-content assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 08fd399f-6734-4bc5-a10c-aa083a3bc8a5

📥 Commits

Reviewing files that changed from the base of the PR and between a7dd559 and e2aa0d2.

📒 Files selected for processing (4)
  • .agents/skills/tidb-test-guidelines/references/server-case-map.md
  • pkg/server/handler/tests/http_handler_serial_test.go
  • pkg/server/handler/tests/http_handler_test.go
  • pkg/server/http_status.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • .agents/skills/tidb-test-guidelines/references/server-case-map.md
  • pkg/server/http_status.go
  • pkg/server/handler/tests/http_handler_serial_test.go

Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot Bot added sig/planner SIG: Planner and removed approved labels Jul 17, 2026
@gengliqi gengliqi changed the title server: add logging for profiling requests server: add logging for http profiling requests Jul 17, 2026
@gengliqi

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 20, 2026
@gengliqi gengliqi changed the title server: add logging for http profiling requests server: add logging for profiling requests Jul 20, 2026

@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 added the lgtm label Jul 20, 2026
@ti-chi-bot ti-chi-bot Bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 20, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-17 03:01:41.153930029 +0000 UTC m=+941887.190025085: ☑️ agreed by YangKeao.
  • 2026-07-20 03:57:42.278687027 +0000 UTC m=+1204448.314782093: ☑️ agreed by bb7133.

gengliqi added 2 commits July 20, 2026 13:16
Signed-off-by: gengliqi <gengliqiii@gmail.com>
u
Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot Bot added the approved label Jul 20, 2026
@gengliqi

Copy link
Copy Markdown
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 20, 2026
Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot Bot removed the approved label Jul 20, 2026

@time-and-fate time-and-fate 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.

buildinfo part LGTM

@ti-chi-bot

ti-chi-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, time-and-fate, YangKeao

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 20, 2026
@ti-chi-bot
ti-chi-bot Bot merged commit 3332762 into pingcap:master Jul 20, 2026
36 checks passed
@gengliqi

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-8.5

@gengliqi

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-8.5-20260323-v8.5.5

@ti-chi-bot

Copy link
Copy Markdown
Member

@gengliqi: new pull request created to branch release-8.5: #69945.
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.

@ti-chi-bot

Copy link
Copy Markdown
Member

@gengliqi: new pull request created to branch release-8.5-20260323-v8.5.5: #69946.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-8.5-20260323-v8.5.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-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner 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 logging for profiling requests

6 participants