Skip to content

Commit

Permalink
Disable context propagation on kprobes (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski authored Jan 18, 2024
1 parent 896bc89 commit 9542752
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 23 deletions.
8 changes: 4 additions & 4 deletions bpf/http_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ static __always_inline void handle_buf_with_connection(pid_connection_info_t *pi
http_connection_metadata_t *meta = bpf_map_lookup_elem(&filtered_connections, pid_conn);
get_or_create_trace_info(meta, pid_conn->pid, &pid_conn->conn, u_buf, bytes_len, capture_header_buffer);

if (!meta) {
bpf_dbg_printk("No META!");
}

#if 0 // disabled for now, until we have better way to detect when it's safe to assume same thread
if (meta) {
tp_info_pid_t *tp_p = trace_info_for_connection(&pid_conn->conn);
if (tp_p) {
Expand All @@ -309,7 +306,10 @@ static __always_inline void handle_buf_with_connection(pid_connection_info_t *pi
} else {
bpf_dbg_printk("Can't find trace info, this is a bug!");
}
} else {
bpf_dbg_printk("No META!");
}
#endif
// we copy some small part of the buffer to the info trace event, so that we can process an event even with
// incomplete trace info in user space.
bpf_probe_read(info->buf, FULL_BUF_SIZE, u_buf);
Expand Down
4 changes: 3 additions & 1 deletion bpf/trace_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static __always_inline void get_or_create_trace_info(http_connection_metadata_t

u8 found_tp = 0;

#if 0 // disabled for now, until we have better way to detect when it's safe to assume same thread
if (meta) {
if (meta->type == EVENT_HTTP_CLIENT) {
tp_p->pid = -1; // we only want to prevent correlation of duplicate server calls by PID
Expand All @@ -183,7 +184,8 @@ static __always_inline void get_or_create_trace_info(http_connection_metadata_t
}
}
}

#endif

if (!found_tp) {
bpf_dbg_printk("Generating new traceparent id");
urand_bytes(tp_p->tp.trace_id, TRACE_ID_SIZE_BYTES);
Expand Down
Binary file modified pkg/internal/ebpf/httpfltr/bpf_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpfltr/bpf_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpfltr/bpf_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpfltr/bpf_debug_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_debug_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_debug_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_tp_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_tp_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_tp_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/httpssl/bpf_tp_debug_bpfel_x86.o
Binary file not shown.
16 changes: 9 additions & 7 deletions test/integration/multiprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ func TestMultiProcess(t *testing.T) {
assert.Empty(t, results)
})

t.Run("Nested traces with kprobes: node python rails", func(t *testing.T) {
testNestedHTTPTracesKProbes(t)
})

t.Run("Nested traces with kprobes: SSL node python rails", func(t *testing.T) {
testNestedHTTPSTracesKProbes(t)
})
if kprobeTraces {
t.Run("Nested traces with kprobes: node python rails", func(t *testing.T) {
testNestedHTTPTracesKProbes(t)
})

t.Run("Nested traces with kprobes: SSL node python rails", func(t *testing.T) {
testNestedHTTPSTracesKProbes(t)
})
}

t.Run("BPF pinning folders mounted", func(t *testing.T) {
// 1 beyla pinned map folder for all processes
Expand Down
8 changes: 5 additions & 3 deletions test/integration/red_test_nodeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func testNodeClientWithMethodAndStatusCode(t *testing.T, method string, statusCo
We check that the traceID has that 16 character 0 suffix and then we
use the first 16 characters for looking up by Parent span.
*/
require.True(t, span.TraceID != "")
require.True(t, strings.HasSuffix(span.TraceID, traceIDLookup))
require.True(t, strings.HasPrefix(span.SpanID, "00"))
if kprobeTraces {
require.True(t, span.TraceID != "")
require.True(t, strings.HasSuffix(span.TraceID, traceIDLookup))
require.True(t, strings.HasPrefix(span.SpanID, "00"))
}
}
10 changes: 6 additions & 4 deletions test/integration/red_test_rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ func testREDMetricsForRustHTTPLibrary(t *testing.T, url, comm, namespace string,
require.Len(t, res, 1)
parent := res[0]
require.NotEmpty(t, parent.TraceID)
require.Equal(t, traceID, parent.TraceID)
// Validate that "parent" is a CHILD_OF the traceparent's "parent-id"
childOfPID := trace.ChildrenOf(parentID)
require.Len(t, childOfPID, 1)
if kprobeTraces {
require.Equal(t, traceID, parent.TraceID)
// Validate that "parent" is a CHILD_OF the traceparent's "parent-id"
childOfPID := trace.ChildrenOf(parentID)
require.Len(t, childOfPID, 1)
}
require.NotEmpty(t, parent.SpanID)
// check duration is at least 2us
assert.Less(t, (2 * time.Microsecond).Microseconds(), parent.Duration)
Expand Down
2 changes: 2 additions & 0 deletions test/integration/suites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/grafana/beyla/test/integration/components/docker"
)

var kprobeTraces = false // disabled for now until we figure a safe way to determine server client relationships

func TestSuite(t *testing.T) {
compose, err := docker.ComposeSuite("docker-compose.yml", path.Join(pathOutput, "test-suite.log"))
require.NoError(t, err)
Expand Down
10 changes: 6 additions & 4 deletions test/integration/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,12 @@ func testHTTPTracesKProbes(t *testing.T) {
require.Len(t, res, 1)
parent := res[0]
require.NotEmpty(t, parent.TraceID)
require.Equal(t, traceID, parent.TraceID)
// Validate that "parent" is a CHILD_OF the traceparent's "parent-id"
childOfPID := trace.ChildrenOf(parentID)
require.Len(t, childOfPID, 1)
if kprobeTraces {
require.Equal(t, traceID, parent.TraceID)
// Validate that "parent" is a CHILD_OF the traceparent's "parent-id"
childOfPID := trace.ChildrenOf(parentID)
require.Len(t, childOfPID, 1)
}
require.NotEmpty(t, parent.SpanID)
// check duration is at least 2us
assert.Less(t, (2 * time.Microsecond).Microseconds(), parent.Duration)
Expand Down

0 comments on commit 9542752

Please sign in to comment.