-
Notifications
You must be signed in to change notification settings - Fork 97
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
Switch to using per header field parsing #1636
base: main
Are you sure you want to change the base?
Conversation
@@ -20,6 +20,18 @@ static __always_inline bool bpf_memcmp(char *s1, char *s2, s32 size) | |||
return true; | |||
} | |||
|
|||
// assumes s2 is all lowercase | |||
static __always_inline int bpf_memicmp(const char *s1, const char *s2, s32 size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a helper we have used before in Beyla which can do case insensitive compares for the header fields. e.g. Traceparent, TRACEPARENT, TraceParent, traceparent all match.
return 0; | ||
} | ||
|
||
SEC("uprobe/textproto_Reader_readContinuedLineSlice") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add the function signature as a comment?
struct | ||
{ | ||
__uint(type, BPF_MAP_TYPE_HASH); | ||
__type(key, void *); | ||
__type(value, struct span_context); | ||
__uint(max_entries, MAX_CONCURRENT); | ||
} http_server_context_headers SEC(".maps"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have maps used for context tracking in:
opentelemetry-go-instrumentation/internal/include/go_context.h
Lines 14 to 21 in 5f77fdb
struct | |
{ | |
__uint(type, BPF_MAP_TYPE_HASH); | |
__type(key, void *); | |
__type(value, struct span_context); | |
__uint(max_entries, MAX_CONCURRENT_SPANS); | |
__uint(pinning, LIBBPF_PIN_BY_NAME); | |
} go_context_to_sc SEC(".maps"); |
To use these we need:
- pass NULL to
get_parent_span_context_fn
which will default to useget_parent_span_context
. - Call
start_tracking_span
to update the maps. - Call
stop_tracking_span
to delete the entries.
{ | ||
Sym: "net/textproto.(*Reader).readContinuedLineSlice", | ||
ReturnProbe: "uprobe_textproto_Reader_readContinuedLineSlice_Returns", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the package constraint we have for the go versions as defined in:
Line 60 in 5f77fdb
goWithoutSwissMaps = probe.PackageConstrainst{ |
This will only load the probe for version which have Swiss maps.
It also means will have to inject a constant specifying whether to extract the headers the old or the new way - I think that's a good solution until we'll have full support for Swiss maps.
This PR is changing how we parse handle the Go HTTP request headers to switch from parsing the Go map to using per header uprobe.
The existing tests should be sufficient to prove this initial version works, since we are already testing for context propagation.
In this first version of the PR I've simply switched how the parsing is done to use the new approach. This approach works regardless of the Go version used, e.g. it will work for Go < 1.24 and Go >= 1.24.
I'm looking for feedback on if we should add a load time constant for the BPF program for the Go version. If we test for the Go version in the BPF code we can choose to use the old approach and not mount the new probe.
There are few pros and cons to each approach:
Proposal 1: We don't read any Go maps until we have swiss maps support
Pros:
Cons:
Proposal 2: We use the Go version to turn this on and off
Pros:
Cons:
Relates to #1318