Repository navigation
refactor(ebpf-extractor): split binary into library crate with graceful shutdown - #380
Merged
0xB10C merged 3 commits intoApr 2, 2026
Merged
Conversation
Move all extractor logic from main.rs into lib.rs, matching the pattern established by the rpc, log, and p2p extractors. The new lib.rs exposes a public Args struct (with a new() constructor for programmatic use) and a public async run() function that can be called from integration tests. main.rs is reduced to arg parsing and a direct call to ebpf_extractor::run(). No behavioural changes - the extractor runs identically to before.
Add a shutdown_rx: watch::Receiver<bool> parameter to run(), matching the shutdown pattern used by the rpc, log, and p2p extractors. The poll loop checks the channel non-blockingly each iteration. main.rs spawns a lightweight Ctrl+C handler that sends the shutdown signal. The run() future itself executes directly on the main task (not via tokio::spawn) because libbpf types contain raw pointers that make the future !Send. This enables integration tests to programmatically start and stop the extractor via the watch channel.
Collaborator
|
Concept ACK on this refactor! I didn't put this high on my list personally as integration tests for the I don't want to recommend devs to run them locally due to their privilege requirements (especially if they aren't touching the |
Collaborator
Author
|
No worries, on the ever-growing list!! |
4 of 6 tasks
Collaborator
|
Reviewed and tested! Thank you @deadmanoz! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The ebpf-extractor was the only extractor without a
lib.rs/main.rssplit: all logic lived inmain.rs, which blocked integration test coverage for issue #26. This PR restructures it to match the rpc, log, and p2p extractors:lib.rsnow exposes a publicArgsstruct andpub async fn run(args, shutdown_rx), whilemain.rsis reduced to argument parsing, logger initialization, shutdown setup, and callingrun().Two implementation details intentionally diverge from the other extractors:
run()is not spawned withtokio::spawnThe ebpf extractor's
run()future is!Sendbecause it holds libbpf state built on raw-pointer-backed FFI types.tokio::spawnrequiresSend, since spawned tasks may move between runtime worker threads. As a result,run()executes directly on the main task and only the Ctrl+C handler is spawned.Shutdown uses synchronous
has_changed()instead oftokio::select!The main extraction loop calls
ring_buffers.poll_raw(Duration::from_secs(1)), which is a blocking FFI call rather than an async.awaitpoint. A non-blocking shutdown check before each poll iteration is therefore the natural fit, with up to ~1 second shutdown latency. Dropped senders are treated as shutdown, matching theErr(_) => breakbehavior used by the other extractors.The work is split into three commits:
lib.rsTesting
Verified locally (NixOS x86_64):
--help: CLI interface unchangedrun(), for example:No integration tests added yet.. though this PR provides the structural prerequisite for integration tests to follow!