Skip to content

Commit

Permalink
chore: only upload metrics on mysql (#4591)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Jan 22, 2025
1 parent 1023800 commit 520d2a2
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions core/stores/sqlx/sqlmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ func getCachedSqlConn(driverName, server string) (*sql.DB, error) {
return nil, err
}

if cfg, e := mysql.ParseDSN(server); e != nil {
// if cannot parse, don't collect the metrics
logx.Error(e)
} else {
checksum := sha256.Sum256([]byte(server))
connCollector.registerClient(&statGetter{
host: cfg.Addr,
dbName: cfg.DBName,
hash: hex.EncodeToString(checksum[:]),
poolStats: func() sql.DBStats {
return conn.Stats()
},
})
if driverName != mysqlDriverName {
if cfg, e := mysql.ParseDSN(server); e != nil {
// if cannot parse, don't collect the metrics
logx.Error(e)
} else {
checksum := sha256.Sum256([]byte(server))
connCollector.registerClient(&statGetter{
host: cfg.Addr,
dbName: cfg.DBName,
hash: hex.EncodeToString(checksum[:]),
poolStats: func() sql.DBStats {
return conn.Stats()
},
})
}
}

return conn, nil
Expand Down

0 comments on commit 520d2a2

Please sign in to comment.