Skip to content

Commit

Permalink
pyroscope.scrape: Adjust handling of scrape_timeout
Browse files Browse the repository at this point in the history
This automatically adapts the timeout when a ProfilingTarget is fetched
with Delta=true. In those cases the HTTP calll is block for
ScrapeInterval - 1s while the target profiles itself.

This also updates the ScrapeTimeout to 10s (default in prometheus).
  • Loading branch information
simonswine committed Jan 26, 2024
1 parent d017470 commit 5a57270
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 6 additions & 8 deletions component/pyroscope/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func NewDefaultArguments() Arguments {
Scheme: "http",
HTTPClientConfig: component_config.DefaultHTTPClientConfig,
ScrapeInterval: 15 * time.Second,
ScrapeTimeout: 15*time.Second + (3 * time.Second),
ScrapeTimeout: 10 * time.Second,
ProfilingConfig: DefaultProfilingConfig,
}
}
Expand All @@ -208,14 +208,12 @@ func (arg *Arguments) Validate() error {
if arg.ScrapeTimeout <= 0 {
return fmt.Errorf("scrape_timeout must be greater than 0")
}
if arg.ScrapeTimeout <= arg.ScrapeInterval {
return fmt.Errorf("scrape_timeout must be greater than scrape_interval")
}

if cfg, ok := arg.ProfilingConfig.ProcessCPU, true; ok {
if cfg.Enabled && arg.ScrapeTimeout < time.Second*2 {
return fmt.Errorf("%v scrape_timeout must be at least 2 seconds", pprofProcessCPU)
}
// ScrapeInterval must be at least 2 seconds, because if
// ProfilingTarget.Delta is true the ScrapeInterval - 1s is propagated in
// the `seconds` parameter and it must be >= 1.
if arg.ScrapeInterval <= 2 {
return fmt.Errorf("scrape_interval must be at least 2 seconds")
}

// We must explicitly Validate because HTTPClientConfig is squashed and it won't run otherwise
Expand Down
8 changes: 8 additions & 0 deletions component/pyroscope/scrape/scrape_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ type scrapeLoop struct {
}

func newScrapeLoop(t *Target, scrapeClient *http.Client, appendable pyroscope.Appendable, interval, timeout time.Duration, logger log.Logger) *scrapeLoop {

// if the URL parameter have a seconds parameter, then the collection will
// take at least scrape_duration - 1 second, as the HTTP request will block
// until the profile is collected.
if t.Params().Has("seconds") {
timeout += interval - time.Second
}

return &scrapeLoop{
Target: t,
logger: logger,
Expand Down

0 comments on commit 5a57270

Please sign in to comment.