incubator-seata icon indicating copy to clipboard operation
incubator-seata copied to clipboard

feature: add SQL monitoring and connection pool abstraction with implementation and tests

Open Oscarcheng0312 opened this issue 5 months ago • 0 comments

  • [ ] I have registered the PR changes.

Ⅰ. Describe what this PR did

This PR introduces a complete SQL monitoring system and a connection pool abstraction with a concrete implementation, forming the foundation of the connection-pool in Seata.

  1. SQL‑event collector (package org.apache.seata.common.monitor)
    • SqlExecutionEntry: immutable model of a single SQL execution event (sql, executionTimeMillis, holdTimeMillis, timestamp).
    • SqlMonitor: singleton collector that
      • records all SQL events (up to maxAllRecords)
      • records slow SQL events (execMs > slowThreshold) up to maxSlowEntries
      • exposes getAllRecords(), getSlowSqlList(), clearOldRecords(), resetForTest().
  2. ConnectionPool (package org.apache.seata.common.pool)
    • ConnectionPoolConfig & ConnectionPoolMetrics: plain‐old‐Java objects representing connection‐pool metrics and config.
    • PoolManager: interface defining methods getConfig(), getMetrics(), updateConfig().
    • PoolManagerRegistry: simple lookup/factory returning a PoolManager instance by DataSource type.
  3. Concrete Connection Pool Implementation
    • Adds actual implementation of PoolManager for supported pool types (e.g., Druid/Hikari) using reflection.
  4. Unit Tests
    • SqlMonitorTest: Covers core monitor behaviors (recording, slow query detection, eviction, clear/reset)
    • Connection Pool Tests: Verifies the correctness of PoolManager implementations, metric reporting, and configuration updating.

Ⅱ. Does this pull request fix one issue?

No — this is a new feature for the common module and rm-datasource module, including features about SQL monitor for Druid, connection‐pool metrics config, and the implementation of the connection-pool.

Ⅲ. Why don't you add test cases (unit test/integration test)?

Unit tests are included for all core behaviors of SqlMonitor. Connection pool implementation (config, metrics, update)

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Oscarcheng0312 avatar Jul 25 '25 15:07 Oscarcheng0312