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

Isolate BPF_TRACEPARENT macro #1457

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ jobs:
with:
arch: x86_64
kernel-version: 5.15.152
timeout-minutes: 90
7 changes: 6 additions & 1 deletion .github/workflows/workflow_integration_tests_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
description: 'Kernel version to use when running the tests'
required: true
type: string
timeout-minutes:
description: 'Timeout in minutes before the test is terminated'
required: false
type: number
default: 60
jobs:
test:
name: test
Expand All @@ -33,7 +38,7 @@ jobs:
- name: Run VM integration tests
run: |
sudo make -C test/vm KERNEL_VER=${{ inputs.kernel-version }} ARCH=${{ inputs.arch }} && [ -f testoutput/success ]
timeout-minutes: 60
timeout-minutes: ${{ inputs.timeout-minutes }}
- name: Upload integration test logs
uses: actions/upload-artifact@v4
if: always()
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ run-integration-test-k8s:
.PHONY: run-integration-test-vm
run-integration-test-vm:
@echo "### Running integration tests"
go test -p 1 -failfast -v -timeout 60m -mod vendor -a ./test/integration/... --tags=integration -run "^TestMultiProcess"
go test -p 1 -failfast -v -timeout 90m -mod vendor -a ./test/integration/... --tags=integration -run "^TestMultiProcess"

.PHONY: run-integration-test-arm
run-integration-test-arm:
Expand Down
66 changes: 33 additions & 33 deletions bpf/protocol_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,46 +90,46 @@ static __always_inline void http_get_or_create_trace_info(http_connection_metada
//make_tp_string(tp_buf, &tp_p->tp);
//bpf_dbg_printk("tp: %s", tp_buf);

#ifdef BPF_TRACEPARENT
// The below buffer scan can be expensive on high volume of requests. We make it optional
// for customers to enable it. Off by default.
if (!capture_header_buffer) {
if (meta) {
u32 type = trace_type_from_meta(meta);
set_trace_info_for_connection(conn, type, tp_p);
server_or_client_trace(meta->type, conn, tp_p);
if (k_bpf_traceparent_enabled) {
// The below buffer scan can be expensive on high volume of requests. We make it optional
// for customers to enable it. Off by default.
if (!capture_header_buffer) {
if (meta) {
u32 type = trace_type_from_meta(meta);
set_trace_info_for_connection(conn, type, tp_p);
server_or_client_trace(meta->type, conn, tp_p);
}
return;
}
return;
}

unsigned char *buf = tp_char_buf();
if (buf) {
int buf_len = bytes_len;
bpf_clamp_umax(buf_len, TRACE_BUF_SIZE - 1);

bpf_probe_read(buf, buf_len, u_buf);
unsigned char *res = bpf_strstr_tp_loop(buf, buf_len);

if (res) {
bpf_dbg_printk("Found traceparent %s", res);
unsigned char *t_id = extract_trace_id(res);
unsigned char *s_id = extract_span_id(res);
unsigned char *f_id = extract_flags(res);

decode_hex(tp_p->tp.trace_id, t_id, TRACE_ID_CHAR_LEN);
decode_hex((unsigned char *)&tp_p->tp.flags, f_id, FLAGS_CHAR_LEN);
if (meta && meta->type == EVENT_HTTP_CLIENT) {
decode_hex(tp_p->tp.span_id, s_id, SPAN_ID_CHAR_LEN);
unsigned char *buf = tp_char_buf();
if (buf) {
int buf_len = bytes_len;
bpf_clamp_umax(buf_len, TRACE_BUF_SIZE - 1);

bpf_probe_read(buf, buf_len, u_buf);
unsigned char *res = bpf_strstr_tp_loop(buf, buf_len);

if (res) {
bpf_dbg_printk("Found traceparent %s", res);
unsigned char *t_id = extract_trace_id(res);
unsigned char *s_id = extract_span_id(res);
unsigned char *f_id = extract_flags(res);

decode_hex(tp_p->tp.trace_id, t_id, TRACE_ID_CHAR_LEN);
decode_hex((unsigned char *)&tp_p->tp.flags, f_id, FLAGS_CHAR_LEN);
if (meta && meta->type == EVENT_HTTP_CLIENT) {
decode_hex(tp_p->tp.span_id, s_id, SPAN_ID_CHAR_LEN);
} else {
decode_hex(tp_p->tp.parent_id, s_id, SPAN_ID_CHAR_LEN);
}
} else {
decode_hex(tp_p->tp.parent_id, s_id, SPAN_ID_CHAR_LEN);
bpf_dbg_printk("No traceparent, making a new trace_id", res);
}
} else {
bpf_dbg_printk("No traceparent, making a new trace_id", res);
return;
}
} else {
return;
}
#endif

if (meta) {
u32 type = trace_type_from_meta(meta);
Expand Down
16 changes: 14 additions & 2 deletions bpf/trace_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
#include "ringbuf.h"
#include "pin_internal.h"

#ifdef BPF_TRACEPARENT
enum { k_bpf_traceparent_enabled = 1 };
#else
enum { k_bpf_traceparent_enabled = 0 };
#endif

typedef struct trace_key {
pid_key_t p_key; // pid key as seen by the userspace (for example, inside its container)
u64 extra_id; // pids namespace for the process
Expand Down Expand Up @@ -68,8 +74,11 @@ struct callback_ctx {
u32 pos;
};

#ifdef BPF_TRACEPARENT
static int tp_match(u32 index, void *data) {
if (!k_bpf_traceparent_enabled) {
return 0;
}

if (index >= (TRACE_BUF_SIZE - TRACE_PARENT_HEADER_LEN)) {
return 1;
}
Expand All @@ -86,6 +95,10 @@ static int tp_match(u32 index, void *data) {
}

static __always_inline unsigned char *bpf_strstr_tp_loop(unsigned char *buf, int buf_len) {
if (!k_bpf_traceparent_enabled) {
return NULL;
}

struct callback_ctx data = {.buf = buf, .pos = 0};

u32 nr_loops = (u32)buf_len;
Expand All @@ -98,7 +111,6 @@ static __always_inline unsigned char *bpf_strstr_tp_loop(unsigned char *buf, int

return NULL;
}
#endif

static __always_inline tp_info_pid_t *find_parent_trace(pid_connection_info_t *p_conn) {
trace_key_t t_key = {0};
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/generictracer/bpf_arm64_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/generictracer/bpf_debug_arm64_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/generictracer/bpf_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_x86_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/generictracer/bpf_x86_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/tctracer/bpf_arm64_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/tctracer/bpf_debug_arm64_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/tctracer/bpf_debug_x86_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/tctracer/bpf_x86_bpfel.o
Git LFS file not shown
Loading