diff --git a/.github/workflows/apps/latest_major_version.go b/.github/workflows/apps/latest_major_version.go index f471afe580..50edd0dc41 100644 --- a/.github/workflows/apps/latest_major_version.go +++ b/.github/workflows/apps/latest_major_version.go @@ -8,12 +8,12 @@ package main import ( "encoding/json" "fmt" - "sort" "github.com/Masterminds/semver/v3" "golang.org/x/mod/modfile" "net/http" "os" "regexp" + "sort" "strings" ) diff --git a/contrib/database/sql/metrics.go b/contrib/database/sql/metrics.go index d8ff4ed266..f0b5a5069b 100644 --- a/contrib/database/sql/metrics.go +++ b/contrib/database/sql/metrics.go @@ -33,20 +33,20 @@ var interval = 10 * time.Second // pollDBStats calls (*DB).Stats on the db at a predetermined interval. It pushes the DBStats off to the statsd client. // the caller should always ensure that db & statsd are non-nil -func pollDBStats(statsd internal.StatsdClient, db *sql.DB) { +func pollDBStats(statsd internal.StatsdClient, db *sql.DB, tags []string) { log.Debug("DB stats will be gathered and sent every %v.", interval) for range time.NewTicker(interval).C { log.Debug("Reporting DB.Stats metrics...") stat := db.Stats() - statsd.Gauge(MaxOpenConnections, float64(stat.MaxOpenConnections), []string{}, 1) - statsd.Gauge(OpenConnections, float64(stat.OpenConnections), []string{}, 1) - statsd.Gauge(InUse, float64(stat.InUse), []string{}, 1) - statsd.Gauge(Idle, float64(stat.Idle), []string{}, 1) - statsd.Gauge(WaitCount, float64(stat.WaitCount), []string{}, 1) - statsd.Timing(WaitDuration, stat.WaitDuration, []string{}, 1) - statsd.Gauge(MaxIdleClosed, float64(stat.MaxIdleClosed), []string{}, 1) - statsd.Gauge(MaxIdleTimeClosed, float64(stat.MaxIdleTimeClosed), []string{}, 1) - statsd.Gauge(MaxLifetimeClosed, float64(stat.MaxLifetimeClosed), []string{}, 1) + statsd.Gauge(MaxOpenConnections, float64(stat.MaxOpenConnections), tags, 1) + statsd.Gauge(OpenConnections, float64(stat.OpenConnections), tags, 1) + statsd.Gauge(InUse, float64(stat.InUse), tags, 1) + statsd.Gauge(Idle, float64(stat.Idle), tags, 1) + statsd.Gauge(WaitCount, float64(stat.WaitCount), tags, 1) + statsd.Timing(WaitDuration, stat.WaitDuration, tags, 1) + statsd.Gauge(MaxIdleClosed, float64(stat.MaxIdleClosed), tags, 1) + statsd.Gauge(MaxIdleTimeClosed, float64(stat.MaxIdleTimeClosed), tags, 1) + statsd.Gauge(MaxLifetimeClosed, float64(stat.MaxLifetimeClosed), tags, 1) } } diff --git a/contrib/database/sql/option.go b/contrib/database/sql/option.go index 567c861cb8..a8b8c36087 100644 --- a/contrib/database/sql/option.go +++ b/contrib/database/sql/option.go @@ -31,6 +31,7 @@ type config struct { tags map[string]interface{} dbmPropagationMode tracer.DBMPropagationMode dbStats bool + statsTags []string statsdClient internal.StatsdClient } @@ -292,3 +293,10 @@ func WithDBStats() Option { cfg.dbStats = true } } + +func WithDBStatsTags(tags []string) Option { + return func(cfg *config) { + cfg.dbStats = true + cfg.statsTags = tags + } +} diff --git a/contrib/database/sql/sql.go b/contrib/database/sql/sql.go index b26318d0d3..5aa3c5df81 100644 --- a/contrib/database/sql/sql.go +++ b/contrib/database/sql/sql.go @@ -211,7 +211,7 @@ func OpenDB(c driver.Connector, opts ...Option) *sql.DB { } db := sql.OpenDB(tc) if cfg.dbStats && cfg.statsdClient != nil { - go pollDBStats(cfg.statsdClient, db) + go pollDBStats(cfg.statsdClient, db, cfg.statsTags) } return db }