mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? Adding sql connection pool metrics from stdlib `Stats` ## Why? Expose more metrics for config fine tuning ## How did you test it? - [x] built - [x] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) --------- Co-authored-by: Roey Berman <[email protected]> Co-authored-by: Roey Berman <[email protected]>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package mysql
|
|
|
|
import (
|
|
"github.com/jmoiron/sqlx"
|
|
"go.temporal.io/server/common/clock"
|
|
"go.temporal.io/server/common/config"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/metrics"
|
|
"go.temporal.io/server/common/persistence/sql"
|
|
"go.temporal.io/server/common/persistence/sql/sqlplugin"
|
|
"go.temporal.io/server/common/persistence/sql/sqlplugin/mysql/session"
|
|
"go.temporal.io/server/common/resolver"
|
|
)
|
|
|
|
const (
|
|
// PluginName is the name of the plugin
|
|
PluginName = "mysql8"
|
|
)
|
|
|
|
type plugin struct{}
|
|
|
|
var _ sqlplugin.Plugin = (*plugin)(nil)
|
|
|
|
func init() {
|
|
sql.RegisterPlugin(PluginName, &plugin{})
|
|
}
|
|
|
|
// CreateDB initialize the db object
|
|
func (p *plugin) CreateDB(
|
|
dbKind sqlplugin.DbKind,
|
|
cfg *config.SQL,
|
|
r resolver.ServiceResolver,
|
|
logger log.Logger,
|
|
metricsHandler metrics.Handler,
|
|
) (sqlplugin.GenericDB, error) {
|
|
connect := func() (*sqlx.DB, error) {
|
|
if cfg.Connect != nil {
|
|
return cfg.Connect(cfg)
|
|
}
|
|
return p.createDBConnection(dbKind, cfg, r)
|
|
}
|
|
handle := sqlplugin.NewDatabaseHandle(dbKind, connect, isConnNeedsRefreshError, logger, metricsHandler, clock.NewRealTimeSource())
|
|
db := newDB(dbKind, cfg.DatabaseName, handle, nil)
|
|
return db, nil
|
|
}
|
|
|
|
// CreateDBConnection creates a returns a reference to a logical connection to the
|
|
// underlying SQL database. The returned object is to tied to a single
|
|
// SQL database and the object can be used to perform CRUD operations on
|
|
// the tables in the database
|
|
func (p *plugin) createDBConnection(
|
|
dbKind sqlplugin.DbKind,
|
|
cfg *config.SQL,
|
|
resolver resolver.ServiceResolver,
|
|
) (*sqlx.DB, error) {
|
|
mysqlSession, err := session.NewSession(dbKind, cfg, resolver)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return mysqlSession.DB, nil
|
|
}
|