Skip to content

Commit

Permalink
move stop chan initialization out of pollDBStats
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Dec 16, 2024
1 parent 12241c9 commit 41c3ad9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions contrib/database/sql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"gopkg.in/DataDog/dd-trace-go.v1/internal"
"gopkg.in/DataDog/dd-trace-go.v1/internal/contribroutines"
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)
Expand All @@ -34,9 +33,8 @@ 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, stop chan struct{}) {
log.Debug("DB stats will be gathered and sent every %v.", interval)
stop := contribroutines.GetStopChan()
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
Expand Down
3 changes: 2 additions & 1 deletion contrib/database/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

sqlinternal "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql/internal"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/contribroutines"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"
)
Expand Down Expand Up @@ -211,7 +212,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, contribroutines.GetStopChan())
}
return db
}
Expand Down

0 comments on commit 41c3ad9

Please sign in to comment.