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

Switch to using per header field parsing #1636

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

grcevski
Copy link
Contributor

@grcevski grcevski commented Jan 16, 2025

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:

  • Simpler to test, since all of our tests will be exercising the same code regardless of the Go version used.
  • Code is much simpler to reason about
  • Go iterates quickly on releases and old versions are quickly dropped out of support

Cons:

  • All go versions instrumentations are slower even for those that we know to read the maps for.

Proposal 2: We use the Go version to turn this on and off

Pros:

  • Older Go version instrumentations will be faster
  • If we ever implement support for swiss maps most of the code will already be there to handle < 1.24 and >= 1.24

Cons:

  • We need to add Go 1.24 release candidate tests to prove this new code works
  • Potential bugs might be version dependent
  • Diminishing returns for the complexity with new Go releases, unless we implement swiss map support quickly.

Relates to #1318

@grcevski grcevski requested a review from a team as a code owner January 16, 2025 22:21
@@ -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) {
Copy link
Contributor Author

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")
Copy link
Contributor

@RonFed RonFed Jan 18, 2025

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?

Comment on lines +53 to +59
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");
Copy link
Contributor

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:

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 use get_parent_span_context.
  • Call start_tracking_span to update the maps.
  • Call stop_tracking_span to delete the entries.

Comment on lines +112 to +115
{
Sym: "net/textproto.(*Reader).readContinuedLineSlice",
ReturnProbe: "uprobe_textproto_Reader_readContinuedLineSlice_Returns",
},
Copy link
Contributor

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:

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.

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