Skip to content

Commit

Permalink
record duration after which scrape was cancelled (prometheus#876)
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Kotal <[email protected]>
Signed-off-by: Stephan Windischmann <[email protected]>
  • Loading branch information
vladak authored and Stephan Windischmann committed Oct 27, 2023
1 parent 5a181b7 commit cac39c6
Showing 1 changed file with 7 additions and 3 deletions.
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

0 comments on commit cac39c6

Please sign in to comment.