Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ func (q *Query) Collect(ctx context.Context, conn *sql.DB, ch chan<- Metric) {

// run executes the query on the provided database, in the provided context.
func (q *Query) run(ctx context.Context, conn *sql.DB) (*sql.Rows, errors.WithContext) {
if conn == nil {
return nil, errors.Errorf(q.logContext, "nil database connection")
}

if slog.Default().Enabled(ctx, slog.LevelDebug) {
start := time.Now()
defer func() {
Expand Down
3 changes: 2 additions & 1 deletion target.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ func (t *target) Collect(ctx context.Context, ch chan<- Metric) {
var wg sync.WaitGroup
// Don't bother with the collectors if target is down.
if targetUp {
conn := t.conn
wg.Add(len(t.collectors))
for _, c := range t.collectors {
// If using a single DB connection, collectors will likely run sequentially anyway. But we might have more.
go func(collector Collector) {
defer wg.Done()
collector.Collect(ctx, t.conn, ch)
collector.Collect(ctx, conn, ch)
}(c)
}
}
Expand Down
Loading