Skip to content

tools/coredump: allow running tests on darwin#621

Merged
christos68k merged 15 commits intoopen-telemetry:mainfrom
grafana:korniltsev/process_nonlinux
Aug 6, 2025
Merged

tools/coredump: allow running tests on darwin#621
christos68k merged 15 commits intoopen-telemetry:mainfrom
grafana:korniltsev/process_nonlinux

Conversation

@korniltsev
Copy link
Copy Markdown
Contributor

@korniltsev korniltsev commented Jul 16, 2025

Similar to #612

This will eventually help allowing running some unit tests (for example coredump tests) without spawning a full linux OS on non linux systems (at least darwin, maybe windows)

This PR makes running coredump tests on darwin possible

GODEBUG=asyncpreemptoff=1 go test -v ./tools/coredump/.

@korniltsev korniltsev marked this pull request as ready for review July 16, 2025 09:41
@korniltsev korniltsev requested review from a team as code owners July 16, 2025 09:41
@florianl
Copy link
Copy Markdown
Member

I think, there are more changes needed to reach this point:

$ GOOS=windows go build
# go.opentelemetry.io/ebpf-profiler/libpf/pfelf/internal/mmap
libpf/pfelf/internal/mmap/mmap.go:49:17: undefined: syscall.Munmap
libpf/pfelf/internal/mmap/mmap.go:116:23: undefined: syscall.Mmap
libpf/pfelf/internal/mmap/mmap.go:116:63: undefined: syscall.PROT_READ
libpf/pfelf/internal/mmap/mmap.go:116:82: undefined: syscall.MAP_SHARED
# go.opentelemetry.io/ebpf-profiler/rlimit
rlimit/rlimit.go:17:20: undefined: unix.Rlimit
rlimit/rlimit.go:18:19: undefined: unix.Rlimit
rlimit/rlimit.go:19:13: undefined: unix.RLIM_INFINITY
rlimit/rlimit.go:20:13: undefined: unix.RLIM_INFINITY
rlimit/rlimit.go:23:17: undefined: unix.Prlimit
rlimit/rlimit.go:23:33: undefined: unix.RLIMIT_MEMLOCK
rlimit/rlimit.go:28:18: undefined: unix.Setrlimit
rlimit/rlimit.go:28:33: undefined: unix.RLIMIT_MEMLOCK

@rockdaboot
Copy link
Copy Markdown
Contributor

I think, there are more changes needed to reach this point:

Maybe change the title and say non-linux open source systems!? I guess supporting Windows builds just adds more complexity without gaining any value.

@florianl
Copy link
Copy Markdown
Member

It is not just Windows.

$ GOOS=darwin go build
# go.opentelemetry.io/ebpf-profiler/rlimit
rlimit/rlimit.go:23:17: undefined: unix.Prlimit
$ GOOS=netbsd go build
# go.opentelemetry.io/ebpf-profiler/rlimit
rlimit/rlimit.go:23:17: undefined: unix.Prlimi

@korniltsev
Copy link
Copy Markdown
Contributor Author

I think, there are more changes needed to reach this point:

yes, they are in different packages. rlimit and processmanager/ebpf are my next targets.

I want the change to be small and self contained and revertable just in case

@rockdaboot
Copy link
Copy Markdown
Contributor

@korniltsev Please be more specific in the PR title.

@korniltsev korniltsev changed the title process: allow compiling on nonlinux systems process: allow compiling on darwin Jul 16, 2025
@korniltsev
Copy link
Copy Markdown
Contributor Author

@korniltsev Please be more specific in the PR title.

Thanks, updated

@korniltsev
Copy link
Copy Markdown
Contributor Author

I guess supporting Windows builds just adds more complexity without gaining any value.

It would gain the same value as darwin.
I have not looked into windows yet, darwin will probably be slightly easier as it does support mmap.

Comment thread process/debug.go
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe rename the file to debug_linux.go

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.

applied

@korniltsev
Copy link
Copy Markdown
Contributor Author

Just had an idea similar tohttps://github.com//pull/625. Maybe instead of introducing build tags, we can split the package - move the ptrace specific code into a separate ptrace package

@christos68k
Copy link
Copy Markdown
Member

christos68k commented Jul 16, 2025

Before approving this, I would like to have the complete picture in terms of how the code structure is changing and also the build system. In principle, I'm not against enabling limited compilation on non-Linux systems, but not if it comes with a lot of extra complexity and potential support headaches.

The profiler only works on Linux [1] and that's where the focus should be. @korniltsev If you have multiple PRs in mind, then I'd delay approving/merging until you open all of them so we can look at them as a whole.

[1] Technically it also works inside Docker-on-macOS as that spins up a Linux kernel that supports eBPF that's shared across containers running on the same macOS host. Maybe it also works on WSL2.

@korniltsev
Copy link
Copy Markdown
Contributor Author

I dont have any more new PRs in mind regarding this.

There are 2 things I want to do.

  1. There is a rlimit: allow compiling rlimit on non-linux systems #624 with an alternative proposal WIP: split processmanager/ebpf in two packages: interface and implementation #625
  2. tools/coredump: allow running tests on darwin #621

Together they allow compiling and running coredump tests.

The tests fail with an unexpected SIGURG signal - that would require another fix.

Thats it. This will enable running a big and useful subset of unit tests without spawning virtual machines.

@korniltsev
Copy link
Copy Markdown
Contributor Author

korniltsev commented Jul 16, 2025

To add a bit more on my previous comment:

I see 2 possible solutions to what I am trying to achieve.

  1. guard linux specific code with go build tags
  2. Split packages both processmanager/ebpf and process in half - keep the base interfaces inplace and move the specific implementations to a separate package, for example process/ptrace and processmanager/ebpf/cilium. I kind of like this idea more now. It's should be a good change on it's own - separating concerns.

Do you have any other ideas how this could be done?

@korniltsev korniltsev changed the title process: allow compiling on darwin tools/coredump: allow running on darwin Jul 25, 2025
@korniltsev
Copy link
Copy Markdown
Contributor Author

lets maybe try a different approach - I've closed all my other PRs and consolidated everything here.

Now the tests can be run with GODEBUG=asyncpreemptoff=1 go test -v ./tools/coredump/.

I'd appreciate another round of reviews and discussions. 🙏

@korniltsev korniltsev changed the title tools/coredump: allow running on darwin tools/coredump: allow running tests on darwin Jul 25, 2025
Comment thread process/machine_amd64.go Outdated

import "debug/elf"

const currentMachine = elf.EM_X86_64
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 would probably move these currentMachine things to pfelf as CurrentMachine. They are occasionally needed in other parts too.

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.

Applied. Though I could not find where to use them in other parts after a quick search.

uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: tools/coredump/modulecache
key: coredumps-macos-${{ hashFiles('tools/coredump/testdata/*/*.json') }}
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.

Does the key need to be separate from others? I think this could be shared, because only the actual downloaded files are in the cache. There's nothing linux/mac specific.

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. Replaced the key with arm64 to be shared.

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.

I don't fully understand the restore-keys options though. It feels like they are never used

Comment thread processmanager/ebpf/ebpf.go Outdated
updatePoolQueueCap = 8
)

// EbpfHandler provides the functionality to interact with eBPF maps.
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.

If I understand correctly, this and rest of this PR is about separating EbpfHandler interface out from the processmanager/ebpf so that the interface can be included elsewhere without pulling in the actual ebpf code which does not compile?

Could we do this the otherway around? Just move this interface to some other package like processmanager/ebpfapi? Need to also check how this kind of split is done elsewhere.

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.

If I understand correctly, this and rest of this PR is about separating EbpfHandler interface out from the processmanager/ebpf so that the interface can be included elsewhere without pulling in the actual ebpf code which does not compile?

Yes, this is correct in regards the changes in the pmebpf package.
There are some other changes in the process package, but they are slightly different - solving the compilation issues with build tags. I do think it makes sense to split process into processapi in a similar way you suggested ebpfapi - let me know if you think we should do this within the same change or as a separate or at all.

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.

Could we do this the otherway around? Just move this interface to some other package like processmanager/ebpfapi? Need to also check how this kind of split is done elsewhere.

Yes, this should work. Applied

Copy link
Copy Markdown
Contributor

@fabled fabled left a comment

Choose a reason for hiding this comment

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

LGTM

@christos68k christos68k merged commit 66e4959 into open-telemetry:main Aug 6, 2025
28 checks passed
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Sep 18, 2025
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Sep 18, 2025
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Sep 18, 2025
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants