Instrumentation: Add counters and histograms for database queries (#28236)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
(cherry picked from commit 74d1d3c6a8)
This commit is contained in:
committed by
Arve Knudsen
parent
103765c349
commit
12dc0ea111
@@ -53,15 +53,21 @@ type Dialect interface {
|
||||
IsDeadlock(err error) bool
|
||||
}
|
||||
|
||||
type dialectFunc func(*xorm.Engine) Dialect
|
||||
|
||||
var supportedDialects = map[string]dialectFunc{
|
||||
MYSQL: NewMysqlDialect,
|
||||
SQLITE: NewSqlite3Dialect,
|
||||
POSTGRES: NewPostgresDialect,
|
||||
MYSQL + "WithHooks": NewMysqlDialect,
|
||||
SQLITE + "WithHooks": NewSqlite3Dialect,
|
||||
POSTGRES + "WithHooks": NewPostgresDialect,
|
||||
}
|
||||
|
||||
func NewDialect(engine *xorm.Engine) Dialect {
|
||||
name := engine.DriverName()
|
||||
switch name {
|
||||
case MYSQL:
|
||||
return NewMysqlDialect(engine)
|
||||
case SQLITE:
|
||||
return NewSqlite3Dialect(engine)
|
||||
case POSTGRES:
|
||||
return NewPostgresDialect(engine)
|
||||
if fn, exist := supportedDialects[name]; exist {
|
||||
return fn(engine)
|
||||
}
|
||||
|
||||
panic("Unsupported database type: " + name)
|
||||
|
||||
@@ -15,7 +15,7 @@ type Mysql struct {
|
||||
BaseDialect
|
||||
}
|
||||
|
||||
func NewMysqlDialect(engine *xorm.Engine) *Mysql {
|
||||
func NewMysqlDialect(engine *xorm.Engine) Dialect {
|
||||
d := Mysql{}
|
||||
d.BaseDialect.dialect = &d
|
||||
d.BaseDialect.engine = engine
|
||||
|
||||
@@ -15,7 +15,7 @@ type Postgres struct {
|
||||
BaseDialect
|
||||
}
|
||||
|
||||
func NewPostgresDialect(engine *xorm.Engine) *Postgres {
|
||||
func NewPostgresDialect(engine *xorm.Engine) Dialect {
|
||||
d := Postgres{}
|
||||
d.BaseDialect.dialect = &d
|
||||
d.BaseDialect.engine = engine
|
||||
|
||||
@@ -12,7 +12,7 @@ type Sqlite3 struct {
|
||||
BaseDialect
|
||||
}
|
||||
|
||||
func NewSqlite3Dialect(engine *xorm.Engine) *Sqlite3 {
|
||||
func NewSqlite3Dialect(engine *xorm.Engine) Dialect {
|
||||
d := Sqlite3{}
|
||||
d.BaseDialect.dialect = &d
|
||||
d.BaseDialect.engine = engine
|
||||
|
||||
Reference in New Issue
Block a user