Skip to content

Commit

Permalink
feat/sqlx_metric
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden.ma authored and aiden.ma committed Jan 19, 2025
1 parent b650c8c commit b9b19e3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/stores/sqlx/sqlmanager.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package sqlx

import (
"crypto/sha256"
"database/sql"
"encoding/hex"
"io"
"time"

"github.com/go-sql-driver/mysql"

"github.com/zeromicro/go-zero/core/syncx"
)

Expand All @@ -23,6 +27,21 @@ func getCachedSqlConn(driverName, server string) (*sql.DB, error) {
return nil, err
}

if driverName == mysqlDriverName {
if cfg, err := mysql.ParseDSN(server); err != nil {
// do nothing here
} else {
checksum := sha256.Sum256([]byte(server))
connCollector.registerClient(&statGetter{
dbName: cfg.DBName,
hash: hex.EncodeToString(checksum[:]),
poolStats: func() sql.DBStats {
return conn.Stats()
},

Check warning on line 40 in core/stores/sqlx/sqlmanager.go

View check run for this annotation

Codecov / codecov/patch

core/stores/sqlx/sqlmanager.go#L30-L40

Added lines #L30 - L40 were not covered by tests
})
}
}

return conn, nil
})
if err != nil {
Expand Down

0 comments on commit b9b19e3

Please sign in to comment.