Skip to content

Replace obi-genfiles with Makefile-based code generation#1290

Merged
MrAlias merged 7 commits into
open-telemetry:mainfrom
MrAlias:replace-obi-genfiles
Feb 12, 2026
Merged

Replace obi-genfiles with Makefile-based code generation#1290
MrAlias merged 7 commits into
open-telemetry:mainfrom
MrAlias:replace-obi-genfiles

Conversation

@MrAlias
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias commented Feb 11, 2026

The obi-genfiles command is superfluous, its complexity can be simplified into direct use of make based commands. Other OpenTelemetry projects like opentelemetry-go-instrumentation run generation entirely using make, providing a simpler and more maintainable approach. This PR aligns OBI with that established pattern.

Changes

Removed

  • cmd/obi-genfiles/
  • Complex environment variable configuration (OTEL_EBPF_GENFILES_*)
  • Manual file walking and staleness detection logic

Added/Modified

  • generate target: Smart incremental builds using Make's dependency system
  • generate/all target: Force regeneration (for clean repos or CI)
  • docker-generate target: Simplified Docker-based generation
  • BPF2GO_MAKEBASE export: Enables bpf2go to generate Make-compatible dependency files (.d files)
  • Updated .gitignore to exclude generated .d files
  • generator.Dockerfile: Removed custom tool build stage, now just runs make generate

Benefits

1. Dramatically Faster Incremental Builds

  • Before: Every make generate took ~60 seconds (always regenerated everything)
  • After: make generate takes ~0.05 seconds when nothing changed (1200x faster)
$ time make generate
make: Nothing to be done for 'generate'.
make generate  0.02s user 0.02s system 100% cpu 0.047 total

2. Smart Dependency Tracking

The system now tracks source dependencies via .d files generated by bpf2go:

$ touch bpf/logger/logger.c && make generate
Generating pkg/internal/ebpf/logger/...  # Only rebuilds affected package

3. Parallel Execution Support

$ make -j4 generate  # 28.5s (287% CPU) vs 60s sequential (2x faster)

4. Simpler Architecture

  • No custom tool to maintain, test, or document
  • Uses standard Make patterns familiar to all developers

5. Single-Target Docker Generation

$ make docker-generate  # Just works, no environment variables needed

Validation

Clean Repository (git clean -dxf scenario)

$ rm -rf pkg/internal/ebpf/logger/bpf_*
$ make generate/all
### Generating all eBPF files...
# Successfully regenerates everything

Incremental Builds

$ make generate
make: Nothing to be done for 'generate'.

$ touch bpf/logger/logger.c
$ make generate
Generating pkg/internal/ebpf/logger/...  # Only rebuilds changed package

Dependency Tracking

24 .d files generated locally, providing accurate source dependency information

Backward Compatibility

  • make docker-generate continues to work (mounts workspace, runs generation in container)
  • All //go:generate directives unchanged
  • Generated files identical to previous method
  • CI/CD workflows can continue using same commands

Testing Performed

  • Clean repository build (make generate/all)
  • Incremental builds (make generate)
  • Dependency tracking (source file changes detected)
  • Parallel execution (make -j4 generate)
  • Docker-based generation (make docker-generate)
  • Performance validation (0.05s no-op vs 60s previously)

@MrAlias MrAlias added this to the v0.6.0 milestone Feb 11, 2026
@MrAlias MrAlias changed the title Replace cmd/obi-genfiles with direct make Replace obi-genfiles with Makefile-based code generation Feb 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.40%. Comparing base (9772495) to head (9d9f309).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1290      +/-   ##
==========================================
- Coverage   43.41%   43.40%   -0.02%     
==========================================
  Files         304      304              
  Lines       32779    32779              
==========================================
- Hits        14232    14228       -4     
- Misses      17630    17632       +2     
- Partials      917      919       +2     
Flag Coverage Δ
integration-test 21.07% <ø> (-0.04%) ⬇️
integration-test-arm 0.00% <ø> (ø)
integration-test-vm-x86_64-5.15.152 ?
integration-test-vm-x86_64-6.10.6 ?
k8s-integration-test 2.37% <ø> (ø)
oats-test 0.00% <ø> (ø)
unittests 44.28% <ø> (ø)

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MrAlias MrAlias marked this pull request as ready for review February 11, 2026 23:10
@MrAlias MrAlias requested a review from a team as a code owner February 11, 2026 23:10
Copilot AI review requested due to automatic review settings February 11, 2026 23:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the custom obi-genfiles generator tool and shifts eBPF code generation to a Makefile-driven workflow (including Docker-based generation), aiming to simplify the architecture and improve incremental rebuild performance.

Changes:

  • Removed cmd/obi-genfiles and its environment-variable-driven orchestration logic.
  • Added Makefile targets for incremental generation (generate), forced regeneration (generate/all), and containerized generation (docker-generate) using bpf2go .d dependency files.
  • Updated the generator container to run make generate and updated .gitignore to exclude generated .d files.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.

File Description
generator.Dockerfile Simplifies the generator image to run make generate instead of building/running obi-genfiles.
cmd/obi-genfiles/obi_genfiles.go Removes the bespoke generator implementation (file deleted).
Makefile Introduces Make-based incremental dependency tracking for eBPF codegen and updates Docker generation target.
.gitignore Ignores generated .d dependency files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread generator.Dockerfile Outdated
Comment thread generator.Dockerfile Outdated
Comment thread Makefile
Comment thread Makefile
Comment thread Makefile Outdated
Comment thread Makefile Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@rafaelroquetto rafaelroquetto left a comment

Choose a reason for hiding this comment

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

Niceeee! Thanks for doing this. obi-genfiles is a relic from that time in which we were experimenting with generating .o files directly into the OBI/Beyla package root (to avoid committing .o files to the repo) so it had to do some gymnastics to be able to write to Go modules and the likes. It no longer serves its purpose.

This is much better, cleaner and simpler (and faster!!)

Copy link
Copy Markdown
Contributor

@mariomac mariomac left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for doing

Copy link
Copy Markdown
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.

LGTM!

If there are no existing bpf generated files (i.e. a new clone or
cleaned repository), defer the generate command to generate/all so all
the files are first created.
Document parallel build issues.
@grcevski
Copy link
Copy Markdown
Contributor

The CI failures should get fixed once we merge the PR from @skl. I'm watching for it to finish CI and I'll merge.

@MrAlias MrAlias merged commit 03f80bc into open-telemetry:main Feb 12, 2026
55 of 56 checks passed
@MrAlias MrAlias mentioned this pull request Mar 5, 2026
MrAlias added a commit to MrAlias/opentelemetry-ebpf-instrumentation that referenced this pull request Mar 31, 2026
This target was used to ensure the github.com/cilium/ebpf package
version was the same in the generator as that used locally. This was
made unneeded in open-telemetry#1290.
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.

6 participants