Skip to content

pyroscope.ebpf: otel profiler implementation#2920

Merged
korniltsev merged 68 commits intomainfrom
korniltsev/otel-profiler
Jul 14, 2025
Merged

pyroscope.ebpf: otel profiler implementation#2920
korniltsev merged 68 commits intomainfrom
korniltsev/otel-profiler

Conversation

@korniltsev
Copy link
Copy Markdown
Contributor

@korniltsev korniltsev commented Mar 6, 2025

PR Description

This PR changes the implementation of pyroscope.ebpf compoenent from grafana/pyroscope/ebpf to opentelemetry-ebpf-profiler - a fork of opentelemetry-ebpf-profiler.
The notable changes of the fork: native frame symbolization, dynamic profiling policy, target discovery labels.

The fork uses a rust library for symbol extraction. See https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/rust-crates.

In this PR I put all pyroscope.ebpf code behind a pyroscope_ebpf go tag.

Some component arguments became no-op as there are no corresponding knobs in the new implementations. These args a deprecated

// deprecated
	PidCacheSize int `alloy:"pid_cache_size,attr,optional"`
	// deprecated
	BuildIDCacheSize int `alloy:"build_id_cache_size,attr,optional"`
	// deprecated
	SameFileCacheSize int `alloy:"same_file_cache_size,attr,optional"`
	// deprecated
	CacheRounds int `alloy:"cache_rounds,attr,optional"`
	// deprecated
	GoTableFallback bool `alloy:"go_table_fallback,attr,optional"`
	// deprecated
	SymbolsMapSize int `alloy:"symbols_map_size,attr,optional"`

Which issue(s) this PR fixes

Notes to the Reviewer

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

@korniltsev korniltsev force-pushed the korniltsev/otel-profiler branch from d9663da to 3779c4e Compare March 6, 2025 12:21
Comment thread go.mod Outdated
Comment thread go.mod
Comment thread tools/build-image/Dockerfile Outdated
@korniltsev korniltsev force-pushed the korniltsev/otel-profiler branch from 3779c4e to 7c540d2 Compare March 6, 2025 12:32
@korniltsev korniltsev force-pushed the korniltsev/otel-profiler branch from 7c540d2 to ca84882 Compare March 6, 2025 12:53
@korniltsev korniltsev mentioned this pull request Mar 6, 2025
4 tasks
Comment thread .gitignore Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 10, 2025

💻 Deploy preview deleted.

@korniltsev korniltsev marked this pull request as ready for review March 11, 2025 08:21
@korniltsev korniltsev mentioned this pull request Jun 18, 2025
4 tasks
@korniltsev korniltsev marked this pull request as ready for review June 24, 2025 06:41
Comment thread docs/sources/reference/components/pyroscope/pyroscope.ebpf.md Outdated
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Comment thread docs/sources/reference/components/pyroscope/pyroscope.ebpf.md Outdated
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@marcsanmi marcsanmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏 , just left some nits!

| `python_enabled` | `bool` | A flag to enable or disable python profiling. | `true` | no |
| `ruby_enabled` | `bool` | A flag to enable or disable Ruby profiling. | `true` | no |
| `same_file_cache_size` | `int` | Deprecated (no-op), previously controlled the size of the elf file -> symbols table LRU cache. | `8` | no |
| `sample_rate` | `int` | How many times per second to collect profile samples. | `97` | no |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new default is 19?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, updating

| `go_table_fallback` | `bool` | Deprecated (no-op), previously enabled symbol lookup in `.sym` / `.dynsym` sections when `.gopclntab` lookup failed. | `false` | no |
| `hotspot_enabled` | `bool` | A flag to enable ordisable hotspot profiling. | `true` | no |
| `perl_enabled` | `bool` | A flag to enable or disable Perl profiling. | `true` | no |
| `php_enabled` | `bool` | A flag to enable or disable PHP profiling. | `true` | no |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should go_enabled be also documented?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current revision of the go consumes shit ton of memory and cpu and it works much better without it (i.e. using our symbolizer). We may want to add go here after we update our fork to include open-telemetry/opentelemetry-ebpf-profiler#456 which is not straightforward because it removes the rust lib and we rely on it. tldr - yes, but later.

| `perl_enabled` | `bool` | A flag to enable or disable Perl profiling. | `true` | no |
| `php_enabled` | `bool` | A flag to enable or disable PHP profiling. | `true` | no |
| `pid_cache_size` | `int` | Deprecated (no-op), previously controlled the size of the PID -> proc symbols table LRU cache. | `32` | no |
| `pid_map_size` | `int` | The size of eBPF PID map. | `2048` | no |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer used? Do you keep it for backwards compatibility? I think we should either update it to deprecated or just remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. deprecated. We may want to expose tracer.MapScaleFactor in the future.

time.Sleep(c.cfg.ReporterInterval)
continue
}
defer ctlr.Shutdown()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to cleanup FileObserver to avoid resource leaking?

  defer func() {
      ctlr.Shutdown()
      if c.cfg.FileObserver != nil {
          c.cfg.FileObserver.Cleanup()
      }
  }()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, nice catch

@korniltsev korniltsev requested a review from marcsanmi June 26, 2025 12:00
Copy link
Copy Markdown
Contributor

@marcsanmi marcsanmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@korniltsev korniltsev merged commit bd763f8 into main Jul 14, 2025
45 checks passed
@korniltsev korniltsev deleted the korniltsev/otel-profiler branch July 14, 2025 03:49
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/pyroscope Issues/PRs primarly affecting `pyroscope.` components frozen-due-to-age type/docs Docs Squad label across all Grafana Labs repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants