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

Socket filter to track HTTP requests for non Go #122

Merged
merged 20 commits into from
May 26, 2023

Conversation

grcevski
Copy link
Contributor

@grcevski grcevski commented May 26, 2023

This PR adds support for tracking HTTP server and client requests, though a socket filter, which we can use for languages other than Go. We parse only minimal information on the eBPF side, which means we have to use a different ringbuffer structure than for Go applications. For this purpose I added an optional transformer function that takes the socket filter record and converts it to the standard HTTP trace record.

There are few things missing from this PR:

  • I forgot I had issues with closing the file descriptor required for the filter. I'll follow-up with the change in this PR shortly.
  • No tests! I'm going to follow-up on this in separate PRs, since this code doesn't impact any of the existing functionality and it's effectively disabled for Go applications.
  • I added a map to track PID to program names for reporting purposes, but I'm not using it. So essentially the code as it is now doesn't properly report the program name that the events are generated for. I'll follow-up with a PR to implement this. Technically we need to use the map only with system wide profiling.

bpf_builtins.h and compiler.h are two new headers I needed from Cilium, which bring the support for memcpy.

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

Astonishing! 🤯

bpf/http_sock.c Outdated
@@ -53,7 +45,7 @@ int BPF_KRETPROBE(kretprobe_sock_alloc, struct socket *sock) {
return 0;
}

bpf_dbg_printk("=== sock alloc %llx ===", id);
//bpf_dbg_printk("=== sock alloc %llx ===", id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you forget to uncomment all these bpf_dbg_printk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah! I was debugging an issue with system wide mode and there was too much output. I'll bring them back :)

@codecov-commenter
Copy link

codecov-commenter commented May 26, 2023

Codecov Report

Merging #122 (2be225f) into main (1001faa) will decrease coverage by 1.73%.
The diff coverage is 11.11%.

@@            Coverage Diff             @@
##             main     #122      +/-   ##
==========================================
- Coverage   71.78%   70.05%   -1.73%     
==========================================
  Files          27       28       +1     
  Lines        1857     1927      +70     
==========================================
+ Hits         1333     1350      +17     
- Misses        420      471      +51     
- Partials      104      106       +2     
Flag Coverage Δ
integration-test 58.49% <11.11%> (-1.30%) ⬇️
unittests 39.23% <4.76%> (-0.81%) ⬇️

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

Impacted Files Coverage Δ
pkg/ebpf/common/common.go 0.00% <0.00%> (ø)
pkg/ebpf/httpfltr/httpfltr.go 0.00% <0.00%> (ø)
pkg/ebpf/common/ringbuf.go 80.00% <50.00%> (-2.90%) ⬇️
pkg/ebpf/goruntime/goruntime.go 100.00% <100.00%> (ø)
pkg/ebpf/grpc/grpc.go 100.00% <100.00%> (ø)
pkg/ebpf/nethttp/nethttp.go 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@grcevski grcevski merged commit 518abdc into grafana:main May 26, 2023
@grcevski
Copy link
Contributor Author

Thanks again Mario!

@grcevski grcevski deleted the tcp_filter branch May 26, 2023 15:24
mattdurham pushed a commit to mattdurham/beyla that referenced this pull request Jan 22, 2025
Socket filter to track HTTP requests for non Go
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.

3 participants