-
Notifications
You must be signed in to change notification settings - Fork 118
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
Don't read Go maps anymore #1413
Conversation
}, test.Interval(100*time.Millisecond)) | ||
|
||
spans := trace.FindByOperationName(method) |
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.
This removed test was a long shot anyway. Essentially, since we had the ability to parse Go maps we used them to parse the outgoing headers on client calls. This didn't quite fit Beyla's usecase, we auto instrument, we don't expect users to put 'Traceparent' in their outgoing headers. But since it was free (in terms of functionality) we did it anyway, even though if you were tracking incoming call and user manually added traceparent, we'd actually provide a wrong trace. Now however, it's no longer possible. The map is pre-constructed and we can't read it in Go 1.24.
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.
Good stuff! Mostly nits from my end, but I think there may be a potential bug involving the "Traceparent:"
literal.
bpf/go_common.h
Outdated
@@ -401,4 +401,37 @@ static __always_inline void *unwrap_tls_conn_info(void *conn_ptr, void *tls_stat | |||
return conn_ptr; | |||
} | |||
|
|||
static __always_inline void process_meta_frame_headers(void *frame, tp_info_t *tp) { | |||
if (frame) { |
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.
nit: an early return may improve readability by reducing the indentation depth
bpf/go_common.h
Outdated
u64 fields_len = 0; | ||
bpf_probe_read(&fields_len, sizeof(fields_len), (void *)(frame + 8 + 8)); | ||
bpf_dbg_printk("fields ptr %llx, len %d", fields, fields_len); | ||
if (fields && fields_len > 0) { |
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.
idem
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.
Maybe my preference is otherwise :), indenting is a problem, but returns in middle of text are easy to miss.
bpf/go_common.h
Outdated
if (!bpf_memicmp((const char *)temp, "traceparent", W3C_KEY_LENGTH)) { | ||
bpf_dbg_printk("found grpc traceparent header"); | ||
bpf_probe_read(&temp, W3C_VAL_LENGTH, field.val_ptr); | ||
decode_go_traceparent(temp, tp->trace_id, tp->parent_id, &tp->flags); |
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.
should we break after this line?
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.
Good catch.
bpf/go_nethttp.h
Outdated
u64 len = (u64)GO_PARAM2(ctx); | ||
u8 *buf = (u8 *)GO_PARAM1(ctx); | ||
|
||
if (len >= 68) { |
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.
any chance we could slap a name here instead of a magic number? It's not clear what 68 means without any further context.
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.
100%, I forgot to update that.
bpf/go_nethttp.h
Outdated
|
||
connection_info_t *existing = bpf_map_lookup_elem(&ongoing_server_connections, &g_key); | ||
if (existing) { | ||
if (!bpf_memicmp((const char *)temp, "Traceparent: ", W3C_KEY_LENGTH + 2)) { |
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 think there's a potential bug here - the comment of bpf_memicmp
states that s2 needs to be lowercase, which is not the case here.
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.
Nice catch too, I forgot about those semantics.
bpf/go_nethttp.h
Outdated
goroutine_addr, | ||
&invocation.tp, | ||
(void *)(req + go_offset_of(ot, (go_offset){.v = _req_header_ptr_pos}))); | ||
__attribute__((__unused__)) u8 existing_tp = |
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.
do we still need this attribute xor existing_tp
?
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.
Nope we can clean up.
@@ -186,7 +186,7 @@ static __always_inline u8 valid_span(const unsigned char *span_id) { | |||
} | |||
|
|||
static __always_inline u8 valid_trace(const unsigned char *trace_id) { | |||
return *((u64 *)trace_id) != 0 && *((u64 *)(trace_id + 8)) != 0; | |||
return *((u64 *)trace_id) != 0 || *((u64 *)(trace_id + 8)) != 0; |
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.
nice catch!
Co-authored-by: Rafael Roquetto <rafaelroquetto@users.noreply.github.com>
Co-authored-by: Rafael Roquetto <rafaelroquetto@users.noreply.github.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1413 +/- ##
==========================================
+ Coverage 80.95% 80.99% +0.03%
==========================================
Files 146 146
Lines 14822 14877 +55
==========================================
+ Hits 11999 12049 +50
- Misses 2234 2240 +6
+ Partials 589 588 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Amazing! that's life saving
Since swiss maps are introduced in Go 1.24, our Go map key extraction will stop working. Please see issue #1369.
I took a look at implementing the swiss map lookup and I'm not sure it's possible to implement the double nested loop without hitting verifier issues, assuming we can reimplement all the bit masking required by the group logic.
So I took a different approach:
TODO:
Closes #1369