chore (replstore): fix registration with multiple sql drivers, again (#90990)

* replstore: fix registration with multiple sql drivers, again
* only compile regex once
This commit is contained in:
Kristin Laemmert
2024-07-25 15:13:36 -04:00
committed by GitHub
parent 9852513c65
commit daedb358dd
3 changed files with 25 additions and 15 deletions

View File

@ -61,7 +61,7 @@ func WrapDatabaseDriverWithHooks(dbType string, tracer tracing.Tracer) string {
// WrapDatabaseDriverWithHooks creates a fake database driver that
// executes pre and post functions which we use to gather metrics about
// database queries. It also registers the metrics.
func WrapDatabaseReplDriverWithHooks(dbType string, tracer tracing.Tracer) string {
func WrapDatabaseReplDriverWithHooks(dbType string, index uint, tracer tracing.Tracer) string {
drivers := map[string]driver.Driver{
migrator.SQLite: &sqlite3.SQLiteDriver{},
migrator.MySQL: &mysql.MySQLDriver{},
@ -73,7 +73,7 @@ func WrapDatabaseReplDriverWithHooks(dbType string, tracer tracing.Tracer) strin
return dbType
}
driverWithHooks := dbType + "ReplicaWithHooks"
driverWithHooks := dbType + fmt.Sprintf("ReplicaWithHooks%d", index)
sql.Register(driverWithHooks, sqlhooks.Wrap(d, &databaseQueryWrapper{log: log.New("sqlstore.metrics"), tracer: tracer}))
core.RegisterDriver(driverWithHooks, &databaseQueryWrapperDriver{dbType: dbType})
return driverWithHooks