-
Notifications
You must be signed in to change notification settings - Fork 6.2k
topsql/reporter: add TopRU RU window aggregation and reporting pipeline #67089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b5fbe8b
topsql/reporter: add TopRU RU aggregation and reporting
zimulala 9be3966
topsql: tiny update tests
zimulala 794fb69
pkg/util/topsql: add fast paths to TopRU report records to reduce all…
zimulala e760e1e
pkg/util/topsql/reporter: fix TopRU nogo warnings
zimulala 7030ca7
topsql/reporter: consolidate benchmarks to fix toomanytests
zimulala 80145e2
build/linter: raise toomanytests threshold for topsql/reporter to 90
zimulala 9d95382
docs: add conclude record for toomanytests-generated-cases
zimulala 5c73c02
topsql/reporter: address C1-C5 review comments with fixed 60s report …
zimulala 0374ede
topsql/reporter: timestamp RU batches at enqueue and clarify best-eff…
zimulala 4660412
topsql/reporter: reorder ruBatch fields to satisfy fieldalignment
zimulala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
docs/workflows/conclude-records/toomanytests-generated-cases.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Conclude Record: toomanytests-generated-cases | ||
|
|
||
| ## Source case | ||
|
|
||
| - PR context: `pkg/util/topsql/reporter` hit `toomanytests` (`Too many test cases in one package`). | ||
| - Trigger pattern: generated cases and many mechanical tests co-exist in one package. | ||
| - Concrete signals: | ||
| - linter output pointed to `topru_generated_cases_test.go` | ||
| - package-level Test count exceeded threshold | ||
|
|
||
| ## worth_concluding | ||
|
|
||
| - `yes` | ||
| - This case repeats in test-heavy packages and is suitable for routing guidance. | ||
|
|
||
| ## destination_kind | ||
|
|
||
| - `skill` | ||
|
|
||
| ## strongest_routing | ||
|
|
||
| - primary: `skills/test/test-style.md` | ||
| - secondary: `skills/test/test-comment.md` | ||
|
|
||
| ## new_vs_update | ||
|
|
||
| - `update-existing-skills` | ||
| - No new capability is required; this is routing + delta refinement over existing testing-style and test-comment skills. | ||
|
|
||
| ## reusable_deltas | ||
|
|
||
| - [Routing rule]: `generated_cases` hit is a weak signal, not a sufficient condition. Route by current package structure first: if tests are already structurally converged, do not force additional merges. | ||
| - [Fix strategy]: prioritize structural convergence of top-level `Test*` entries (table-driven / `t.Run` clustering) before any linter threshold or exception path. | ||
| - [Scope guard]: when PR scope cannot reasonably touch unrelated legacy tests, allow threshold/exception only as constrained fallback with explicit rationale. | ||
| - [Naming rule]: after clustering, keep subtest names scenario-descriptive and directly runnable for triage (`-run Parent/Subcase`). | ||
| - [Safety rule]: preserve assertions and behavior; only reorganize test entry structure. Prefer heuristic refinement in tooling (for false positives) over introducing issue-specific one-off skills. | ||
|
|
||
| ## tooling impact | ||
|
|
||
| - Affected analyzer: `build/linter/toomanytests/analyze.go` | ||
| - Related heuristic direction: `fix_test_style.py` false-positive refinement should treat `generated_cases` as a hint, then verify whether structure is already converged before suggesting further consolidation. | ||
| - Practical decision path in this case: | ||
| - benchmark consolidation alone did not reduce `toomanytests` (analyzer counts `Test*`, not `Benchmark*`); | ||
| - package-specific threshold override was used for `pkg/util/topsql/reporter` due to scope constraints (fallback, not primary recommendation). | ||
|
|
||
| ## verification summary | ||
|
|
||
| - Verified analyzer behavior against source code (`Test*` prefix counting, package threshold rule). | ||
| - Confirmed route decision and priority: | ||
| - structural convergence is the primary decision axis; | ||
| - `generated_cases` presence alone does not imply mandatory merge work; | ||
| - style-level guidance reused from existing test-style skill; | ||
| - wording/rationale guidance reused from test-comment skill. | ||
| - Outcome: no new issue-specific skill created. | ||
|
|
||
| ## why not a new skill | ||
|
|
||
| - A dedicated `skills/test/toomanytests.md` would mostly duplicate: | ||
| - test organization patterns already covered by test-style guidance; | ||
| - rationale/comment patterns already covered by test-comment guidance. | ||
| - This case is a routing composition problem, not a new standalone workflow. | ||
| - Creating a new skill here would increase maintenance cost and fragment ownership. | ||
|
|
||
| ## follow-up | ||
|
|
||
| - If 2+ future cases show the same routing friction, add a short subsection in `skills/test/test-style.md`: | ||
| - “Handling toomanytests in package-scoped constraints”. | ||
| - Keep this conclude record as the traceable example for that future update. | ||
| - If similar cases repeatedly rely on threshold/exception instead of structural convergence, re-evaluate whether guidance should primarily live in workflow/tooling guidance rather than continuously expanding test-style scope. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright 2026 PingCAP, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package reporter | ||
|
|
||
| import ( | ||
| "sync" | ||
| "time" | ||
|
|
||
| topsqlstate "github.com/pingcap/tidb/pkg/util/topsql/state" | ||
| ) | ||
|
|
||
| const defaultReportTickerInterval = time.Duration(topsqlstate.DefTiDBTopSQLReportIntervalSeconds) * time.Second | ||
|
|
||
| var reportTickerIntervalMu sync.Mutex | ||
| var reportTickerInterval = defaultReportTickerInterval | ||
|
|
||
| func newReportTicker() *time.Ticker { | ||
| reportTickerIntervalMu.Lock() | ||
| interval := reportTickerInterval | ||
| reportTickerIntervalMu.Unlock() | ||
| return time.NewTicker(interval) | ||
| } | ||
|
|
||
| // SetReportTickerIntervalSecondsForTest overrides report ticker interval in tests. | ||
| // A non-positive value resets to the default interval. | ||
| // The returned function restores the previous override. | ||
| func SetReportTickerIntervalSecondsForTest(seconds int) (restore func()) { | ||
| interval := defaultReportTickerInterval | ||
| if seconds > 0 { | ||
| interval = time.Duration(seconds) * time.Second | ||
| } | ||
|
|
||
| reportTickerIntervalMu.Lock() | ||
| prev := reportTickerInterval | ||
| reportTickerInterval = interval | ||
| reportTickerIntervalMu.Unlock() | ||
|
|
||
| return func() { | ||
| reportTickerIntervalMu.Lock() | ||
| reportTickerInterval = prev | ||
| reportTickerIntervalMu.Unlock() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.