mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add prometheus metrics to database.Store (#7713)
* Adds dbmetrics package and wraps database.Store with a Prometheus HistogramVec of timings. * Adds Wrappers method to database.Store to avoid double-wrapping interfaces * Fixes test flake in TestLicensesListFake
This commit is contained in:
@@ -24,11 +24,20 @@ type Store interface {
|
||||
querier
|
||||
// customQuerier contains custom queries that are not generated.
|
||||
customQuerier
|
||||
// wrapper allows us to detect if the interface has been wrapped.
|
||||
wrapper
|
||||
|
||||
Ping(ctx context.Context) (time.Duration, error)
|
||||
InTx(func(Store) error, *sql.TxOptions) error
|
||||
}
|
||||
|
||||
type wrapper interface {
|
||||
// Wrappers returns a list of wrappers that have been applied to the store.
|
||||
// This is used to detect if the store has already wrapped, and avoid
|
||||
// double-wrapping.
|
||||
Wrappers() []string
|
||||
}
|
||||
|
||||
// DBTX represents a database connection or transaction.
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
@@ -60,6 +69,10 @@ type sqlQuerier struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (*sqlQuerier) Wrappers() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
// Ping returns the time it takes to ping the database.
|
||||
func (q *sqlQuerier) Ping(ctx context.Context) (time.Duration, error) {
|
||||
start := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user