Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add support for generating non-bpf files #1710

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

rafaelroquetto
Copy link
Contributor

@rafaelroquetto rafaelroquetto commented Feb 28, 2025

This PR generalises the concept brought forth by build_ebpf.go into a tool that can be run standalone, and will generate every //go:generate tag for Beyla.

Projects that have a dependency on beyla (such as Alloy) can now simply run:

go run github.com/grafana/beyla/v2/cmd/beyla-genfiles

as part of their build process, simplifying their workflow.

Finally, it simplifies the generator image, which now simply relies on beyla-genfiles to do the work (and build in parallel).

Usage in Alloy: grafana/alloy#2734

Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 0% with 146 lines in your changes missing coverage. Please review.

Project coverage is 68.57%. Comparing base (c9291b2) to head (faa829a).

Files with missing lines Patch % Lines
cmd/beyla-genfiles/beyla_genfiles.go 0.00% 146 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1710      +/-   ##
==========================================
- Coverage   69.72%   68.57%   -1.15%     
==========================================
  Files         210      211       +1     
  Lines       21282    21635     +353     
==========================================
- Hits        14838    14837       -1     
- Misses       5716     6070     +354     
  Partials      728      728              
Flag Coverage Δ
integration-test 54.40% <ø> (-0.10%) ⬇️
k8s-integration-test 54.11% <ø> (+0.03%) ⬆️
oats-test 34.56% <ø> (-0.25%) ⬇️
unittests 45.04% <0.00%> (-0.75%) ⬇️

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 marked this pull request as ready for review February 28, 2025 19:19
@rafaelroquetto rafaelroquetto requested a review from a team as a code owner February 28, 2025 19:19
Copy link
Contributor

@grcevski grcevski left a comment

Choose a reason for hiding this comment

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

Looks great, I left a few questions and suggestions.

generate: export BPF2GO := $(BPF2GO)
generate: bpf2go
@echo "### Generating files..."
@BEYLA_GENFILES_RUN_LOCALLY=1 go generate cmd/beyla-genfiles/beyla_genfiles.go
Copy link
Contributor

Choose a reason for hiding this comment

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

Does run_locally use the local clang/llvm instead of a Docker image?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, that is exactly it

const OCI_BIN = "docker"
const GEN_IMG = "ghcr.io/grafana/beyla-ebpf-generator:main"
const OCIBin = "docker"
const GenImg = "ghcr.io/grafana/beyla-ebpf-generator:main"
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this cause us issues with releases? What I mean is that, if by some reason we drift the n.n.n release generation from main, would we still be able to compile the binaries on release update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually not - one of the goals of this PR is to actually delegate the entire logic of binary generation and what not to this script - the docker image simply does this:

BEYLA_GENFILES_RUN_LOCALLY=1 go run cmd/beyla-genfiles/beyla_genfiles.go

i.e. once inside the container, it just reinvokes this with the "locally" flag (in which case locally is now "inside the container").

What I do intend to do nonetheless (but if possible as a new PR sometime soon), is to version the image, if push comes to shove. Ultimately this could be made as an env var, and once we release, we can publish/tag different generator images.

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.

2 participants