feature: add SqlMonitor and SlowSqlEntry for SQL execution monitoring
- [ ] I have registered the PR changes.
Ⅰ. Describe what this PR did
This PR introduces a new SQL monitoring utility to the seata-common module:
-
SqlMonitor: a singleton class for collecting SQL execution statistics.- Tracks slow SQL (execution time > threshold), up to
maxSlowEntries - Maintains histogram of transaction execution time
- Maintains histogram of connection hold time
- Thread-safe using concurrent data structures and explicit locking
- Includes setters
setSlowThreshold()andsetMaxSlowEntries()for future dynamic configuration
- Tracks slow SQL (execution time > threshold), up to
-
SlowSqlEntry: a simple immutable model class holding slow SQL info (text, exec time, timestamp)
Ⅱ. Does this pull request fix one issue?
No. This is a new feature and the first step in the SQL monitoring implementation plan.
Ⅲ. Why don't you add test cases (unit test/integration test)?
Test cases are included:
-
SqlMonitorTest.javacovers:- Slow SQL recording and eviction behavior
- Histogram bucket logic for transaction/hold times
- Fast SQL skip logic
- Queue size trimming
Ⅳ. Describe how to verify it
- Run
SqlMonitorTestwith JUnit - Verify correctness of slow SQL detection, histogram aggregation, and bounded queue behavior
Ⅴ. Special notes for reviews
- This is PR 1/3 in the SQL monitoring feature set
- Follow-up PRs will integrate this utility with
seata-rm-datasource(recording) andseata-server(metrics exposure) - Configuration injection will be addressed later via
application.ymlor dynamic configuration center
Hi @slievrly, this PR adds SqlMonitor and SlowSqlEntry to support SQL execution monitoring (slow SQL tracking + histograms).
Would you mind reviewing it when convenient? This is the first part of the GSoC connection pool monitoring plan. Thanks!
Codecov Report
:x: Patch coverage is 90.32258% with 6 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 60.40%. Comparing base (db73418) to head (74437dc).
:warning: Report is 27 commits behind head on 2.x.
Additional details and impacted files
@@ Coverage Diff @@
## 2.x #7491 +/- ##
============================================
+ Coverage 60.34% 60.40% +0.05%
Complexity 658 658
============================================
Files 1284 1286 +2
Lines 48465 48527 +62
Branches 5694 5702 +8
============================================
+ Hits 29247 29311 +64
+ Misses 16600 16599 -1
+ Partials 2618 2617 -1
| Files with missing lines | Coverage Δ | |
|---|---|---|
| .../org/apache/seata/common/monitor/SlowSqlEntry.java | 77.77% <77.77%> (ø) |
|
| ...va/org/apache/seata/common/monitor/SqlMonitor.java | 92.45% <92.45%> (ø) |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@slievrly Hi, pls take a look when you are convenient.