Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report duration in log after which scrape was cancelled #876

Merged
merged 1 commit into from
May 16, 2023
Merged
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
10 changes: 7 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
config.WalkParams.ConfigureSNMP(&snmp)

// Do the actual walk.
getInitialStart := time.Now()
err := snmp.Connect()
if err != nil {
if err == context.Canceled {
return results, fmt.Errorf("scrape canceled (possible timeout) connecting to target %s", snmp.Target)
return results, fmt.Errorf("scrape cancelled after %s (possible timeout) connecting to target %s",
time.Since(getInitialStart), snmp.Target)
}
return results, fmt.Errorf("error connecting to target %s: %s", target, err)
}
Expand Down Expand Up @@ -220,7 +222,8 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
packet, err := snmp.Get(getOids[:oids])
if err != nil {
if err == context.Canceled {
return results, fmt.Errorf("scrape canceled (possible timeout) getting target %s", snmp.Target)
return results, fmt.Errorf("scrape cancelled after %s (possible timeout) getting target %s",
time.Since(getInitialStart), snmp.Target)
}
return results, fmt.Errorf("error getting target %s: %s", snmp.Target, err)
}
Expand Down Expand Up @@ -257,7 +260,8 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
}
if err != nil {
if err == context.Canceled {
return results, fmt.Errorf("scrape canceled (possible timeout) walking target %s", snmp.Target)
return results, fmt.Errorf("scrape canceled after %s (possible timeout) walking target %s",
time.Since(getInitialStart), snmp.Target)
}
return results, fmt.Errorf("error walking target %s: %s", snmp.Target, err)
}
Expand Down