Skip to content

Commit

Permalink
[bugfix] fix gather context timeout and display vcenter having sessio…
Browse files Browse the repository at this point in the history
…n issues
  • Loading branch information
Tesifonte Belda committed Jun 19, 2023
1 parent 9179a30 commit c16073a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions plugins/inputs/vcstat/vcstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ func (vcs *Config) Gather(acc telegraf.Accumulator) error {
)

// poll using a context with timeout
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(vcs.Timeout))
ctx, cancel := context.WithTimeout(
context.Background(),
time.Duration(vcs.pollInterval),
)
defer cancel()

if err = vcs.keepActiveSession(ctx, acc); err != nil {
Expand Down Expand Up @@ -314,10 +317,15 @@ func (vcs *Config) keepActiveSession(
col = vcs.vcc
if !col.IsActive(ctx) {
if vcs.SessionsCreated.Get() > 0 {
acc.AddError(fmt.Errorf("vCenter session not active, re-authenticating"))
acc.AddError(
fmt.Errorf(
"vCenter session not active, re-authenticating with %s",
vcs.VCenter,
),
)
}
if err = col.Open(time.Duration(vcs.Timeout)); err != nil {
return err
return fmt.Errorf("could open session with vCenter %s", err)
}
vcs.SessionsCreated.Incr(1)
}
Expand Down

0 comments on commit c16073a

Please sign in to comment.