Change the timeout from all queries to per query (#9471)

This commit is contained in:
bhsu-ms 2021-07-27 14:14:49 -07:00 committed by GitHub
parent 51720f3bd7
commit 27b98083f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View File

@ -22,6 +22,7 @@ generate it using `telegraf --usage <plugin-name>`.
dsn = "username:password@mysqlserver:3307/dbname?param=value"
## Timeout for any operation
## Note that the timeout for queries is per query not per gather.
# timeout = "5s"
## Connection time limits

View File

@ -30,6 +30,7 @@ const sampleConfig = `
dsn = "username:password@mysqlserver:3307/dbname?param=value"
## Timeout for any operation
## Note that the timeout for queries is per query not per gather.
# timeout = "5s"
## Connection time limits
@ -486,16 +487,13 @@ func (s *SQL) Stop() {
func (s *SQL) Gather(acc telegraf.Accumulator) error {
var wg sync.WaitGroup
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(s.Timeout))
defer cancel()
tstart := time.Now()
for _, query := range s.Queries {
wg.Add(1)
go func(q Query) {
defer wg.Done()
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(s.Timeout))
defer cancel()
if err := s.executeQuery(ctx, acc, q, tstart); err != nil {
acc.AddError(err)
}