Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

WIP: Generate eBPF files as part of the build process #1666

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rafaelroquetto
Copy link
Contributor

@rafaelroquetto rafaelroquetto commented Feb 14, 2025

Instead of committing eBPF binaries and generated code, this PR adds the required changes to allow for the eBPF binaries to be generated as part of the Beyla build process. In particular, it adds the necessary boilerplate to allow projects that vendor Beyla to be able to produce these binaries without requiring a clang/llvm toolchain.

The main motivations are

  • prevent malicious pre-compiled binaries from being injected into the Beyla tree
  • removing the binaries ensures that they remain consistent with the source code, preventing discrepancies.
  • repos importing Beyla (i.e. Alloy) won’t need to manage git-lfs, as the removal of pre-built binaries eliminates that requirement and reduces repository overhead, and the requirement for special branches - git-lfs has been removed.

The go module vendoring system, via go mod can be quite pedantic. In order to force the contents of the bpf/ directory to be distributed, a few placeholder files had to be added. Projects vendoring Beyla then need to add the following import:

Vendoring Beyla

import _ "github.com/grafana/beyla/bpf"

Additionally, because go build is not suitable for building non-go source code, projects vendoring Beyla are required to explicitly trigger the eBPF file generation as a fair trade off by issuing:

go generate vendor/github.com/grafana/beyla/bpf/build_ebpf.go

Changes to the generator image

The docker generator image now uses a Go / Alpine base image. This has massively simplified the Dockerfile and shrunk the image size in more than 1GB.

Another benefit of the new image is the ability of generating the eBPF files in parallel. It's significantly faster than make generate. As a result, it's now the preferred way of building eBPF images, and has been reflected in the Makefile. Finally, this promotes docker to being an official build requirement, but at the same time, the requirement for having clang/llvm is now dropped. I find this to be a fair trade-off, given most of our user base is more likely to have docker installed rather than clang.

Note

The image has been renamed from beyla-generator to beyla-bpf-generator to prevent any clashes during development

Epilogue

For Beyla itself, nothing changes apart from the fact that make dev now defaults to docker-generate. You can still compile things locally by running make generate, as customary.

Finally, after experimenting with multiple approaches, I believe the other feasible alternative would be to simply commit go binaries as done by most other projects, without git-lfs - and live with the set of problems this causes.

There's no free lunch.

See related Alloy branch: grafana/alloy#2734

Copy link

codecov bot commented Feb 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.30%. Comparing base (77da7ea) to head (8714274).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1666      +/-   ##
==========================================
- Coverage   72.34%   72.30%   -0.05%     
==========================================
  Files         197      197              
  Lines       19995    19995              
==========================================
- Hits        14465    14457       -8     
- Misses       4836     4842       +6     
- Partials      694      696       +2     
Flag Coverage Δ
integration-test 54.24% <ø> (+0.15%) ⬆️
k8s-integration-test 54.94% <ø> (+0.57%) ⬆️
oats-test 35.25% <ø> (+0.03%) ⬆️
unittests 47.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rafaelroquetto rafaelroquetto added documentation Improvements or additions to documentation do-not-merge WIP or something that musn't be merged labels Feb 15, 2025
@rafaelroquetto rafaelroquetto marked this pull request as ready for review February 15, 2025 02:17
@rafaelroquetto rafaelroquetto requested a review from a team as a code owner February 15, 2025 02:17
@rafaelroquetto rafaelroquetto marked this pull request as draft February 15, 2025 02:25
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
do-not-merge WIP or something that musn't be merged documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant