Skip to content

Commit

Permalink
feat(pyroscope/scrape): set scrape_interval as upper limit for `pro…
Browse files Browse the repository at this point in the history
…filing_duration`

Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber committed Apr 19, 2024
1 parent e835d35 commit 5304d84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/sources/reference/components/pyroscope.scrape.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ When the `delta` argument is `true`:
* A `seconds` parameter is automatically added to the HTTP request.
* The default value for the `seconds` query parameter is `scrape_interval - 1`.
If you set `profiling_duration`, then `seconds` is assigned the same value as `profiling_duration`.
For example, if you set `scrape_interval` to `"15s"`, then `seconds` defaults to `14s`.
If you set `profiling_duration` to `16s`, then `seconds` is set to `16s` regardless of the `scrape_interval` value.
However, the `profiling_duration` cannot be larger than `scrape_interval`.
For example, if you set `scrape_interval` to `"15s"`, then `seconds` defaults to `14s`
If you set `profiling_duration` to `16s`, then `scrape_interval` must be set to at least `17s`.
If the HTTP endpoint is `/debug/pprof/profile`, then the HTTP query will become `/debug/pprof/profile?seconds=14`

## Exported fields
Expand Down
11 changes: 8 additions & 3 deletions internal/component/pyroscope/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
pprofGoDeltaProfBlock string = "godeltaprof_block"
pprofGoDeltaProfMutex string = "godeltaprof_mutex"
defaultScrapeInterval time.Duration = 15 * time.Second
defaultProfilingDuration time.Duration = defaultScrapeInterval - 1 * time.Second
defaultProfilingDuration time.Duration = defaultScrapeInterval - 1*time.Second
)

func init() {
Expand Down Expand Up @@ -223,8 +223,13 @@ func (arg *Arguments) Validate() error {
if target.Enabled && target.Delta && arg.ScrapeInterval.Seconds() < 2 {
return fmt.Errorf("scrape_interval must be at least 2 seconds when using delta profiling")
}
if target.Enabled && target.Delta && arg.ProfilingDuration.Seconds() <= 1 {
return fmt.Errorf("profiling_duration must be larger then 1 second when using delta profiling")
if target.Enabled && target.Delta {
if arg.ProfilingDuration.Seconds() <= 1 {
return fmt.Errorf("profiling_duration must be larger than 1 second when using delta profiling")
}
if arg.ProfilingDuration.Seconds() >= arg.ScrapeInterval.Seconds() {
return fmt.Errorf("profiling_duration must be smaller than scrape_interval when using delta profiling")
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions internal/component/pyroscope/scrape/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ func TestUnmarshalConfig(t *testing.T) {
`,
expectedErr: "profiling_duration must be larger then 1 second when using delta profiling",
},
"erroneous cpu profiling_duration": {
in: `
targets = []
forward_to = null
scrape_timeout = "1s"
scrape_interval = "10s"
profiling_duration = "12s"
`,
expectedErr: "profiling_duration must be smaller than scrape_interval when using delta profiling",
},
"allow short scrape_intervals without delta": {
in: `
targets = []
Expand Down

0 comments on commit 5304d84

Please sign in to comment.