From cc8de1b1f454895d86368d3b9f67de2f9efa5bdc Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Fri, 13 Dec 2024 20:55:50 -0600 Subject: [PATCH] Isolate BPF_TRACEPARENT macro (#1457) --- ...quest_integration_tests_vm_5.15_x86_64.yml | 1 + .../workflow_integration_tests_vm.yml | 7 +- Makefile | 2 +- bpf/protocol_http.h | 66 +++++++++---------- bpf/trace_common.h | 16 ++++- .../ebpf/generictracer/bpf_arm64_bpfel.o | 2 +- .../generictracer/bpf_debug_arm64_bpfel.o | 2 +- .../ebpf/generictracer/bpf_debug_x86_bpfel.o | 2 +- .../ebpf/generictracer/bpf_tp_arm64_bpfel.o | 4 +- .../generictracer/bpf_tp_debug_arm64_bpfel.o | 4 +- .../generictracer/bpf_tp_debug_x86_bpfel.o | 4 +- .../ebpf/generictracer/bpf_tp_x86_bpfel.o | 4 +- .../ebpf/generictracer/bpf_x86_bpfel.o | 2 +- pkg/internal/ebpf/tctracer/bpf_arm64_bpfel.o | 2 +- .../ebpf/tctracer/bpf_debug_arm64_bpfel.o | 2 +- .../ebpf/tctracer/bpf_debug_x86_bpfel.o | 2 +- pkg/internal/ebpf/tctracer/bpf_x86_bpfel.o | 2 +- 17 files changed, 71 insertions(+), 53 deletions(-) diff --git a/.github/workflows/pull_request_integration_tests_vm_5.15_x86_64.yml b/.github/workflows/pull_request_integration_tests_vm_5.15_x86_64.yml index 3d74e8ba1..4ec81ea1c 100644 --- a/.github/workflows/pull_request_integration_tests_vm_5.15_x86_64.yml +++ b/.github/workflows/pull_request_integration_tests_vm_5.15_x86_64.yml @@ -14,3 +14,4 @@ jobs: with: arch: x86_64 kernel-version: 5.15.152 + timeout-minutes: 90 diff --git a/.github/workflows/workflow_integration_tests_vm.yml b/.github/workflows/workflow_integration_tests_vm.yml index e1b1d6f35..f52bc1dd9 100644 --- a/.github/workflows/workflow_integration_tests_vm.yml +++ b/.github/workflows/workflow_integration_tests_vm.yml @@ -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 @@ -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() diff --git a/Makefile b/Makefile index 8c5039e82..0726847d6 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/bpf/protocol_http.h b/bpf/protocol_http.h index 2ba6807ae..bf277782e 100644 --- a/bpf/protocol_http.h +++ b/bpf/protocol_http.h @@ -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); diff --git a/bpf/trace_common.h b/bpf/trace_common.h index de8861929..2e7e581aa 100644 --- a/bpf/trace_common.h +++ b/bpf/trace_common.h @@ -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 @@ -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; } @@ -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; @@ -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}; diff --git a/pkg/internal/ebpf/generictracer/bpf_arm64_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_arm64_bpfel.o index 8225c22dd..7c95dc01e 100644 --- a/pkg/internal/ebpf/generictracer/bpf_arm64_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_arm64_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f380d7d7c77b20fca265c45b9de1a1521c63d4aaa2fe5ca2eb1c89aad8bc091b +oid sha256:f3ceecd8dc691e2a51130d87cb97d2e1f9815d6ad5c00939ff6f09ac59988ede size 644568 diff --git a/pkg/internal/ebpf/generictracer/bpf_debug_arm64_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_debug_arm64_bpfel.o index 2af9aef91..436893ce6 100644 --- a/pkg/internal/ebpf/generictracer/bpf_debug_arm64_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_debug_arm64_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4a931ec421a75d9778f4723961845bb28baea93cd294f2146507a69231039f37 +oid sha256:973b7f16588f39b1dacd9ef2ed58d1ca9469da5ffa4e88023e36eb098f25c452 size 1083456 diff --git a/pkg/internal/ebpf/generictracer/bpf_debug_x86_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_debug_x86_bpfel.o index a2b9c910f..f79f8d324 100644 --- a/pkg/internal/ebpf/generictracer/bpf_debug_x86_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_debug_x86_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ab332dee7a243751d0065016ca4300ec555a5c436c557c93215d2f96161a3473 +oid sha256:2ceeba2b0f3a3743332a6ebff67605b156dcdb13aed3701224bf9dc4e96dafc8 size 1083024 diff --git a/pkg/internal/ebpf/generictracer/bpf_tp_arm64_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_tp_arm64_bpfel.o index 96979cc69..f710450f4 100644 --- a/pkg/internal/ebpf/generictracer/bpf_tp_arm64_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_tp_arm64_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c7b83fcb664d296dc1f4998e16bc8591fb20ec587438c6b6060c71fd2af82eae -size 659056 +oid sha256:01f1d89681982bf0e36571d26c81b4713d5d9e96176a558869ee2bfbc341b714 +size 659080 diff --git a/pkg/internal/ebpf/generictracer/bpf_tp_debug_arm64_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_tp_debug_arm64_bpfel.o index 79b66c476..8ba490604 100644 --- a/pkg/internal/ebpf/generictracer/bpf_tp_debug_arm64_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_tp_debug_arm64_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:28baf5ef2a234634c57a7cbf06efb8627a13ee746a010c6fa28c25fdcd267d2d -size 1101792 +oid sha256:34810ebd563410752ff847a9147f8de2281dacbef51067365383490814cc66b7 +size 1101832 diff --git a/pkg/internal/ebpf/generictracer/bpf_tp_debug_x86_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_tp_debug_x86_bpfel.o index a768fd6c0..d54c7130f 100644 --- a/pkg/internal/ebpf/generictracer/bpf_tp_debug_x86_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_tp_debug_x86_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6c2fd1b77062c819872198220247e37d488632381318acc4c9fda510d00a2f33 -size 1101360 +oid sha256:325d9eace95cce202a42299bfb07af2011a952fe41e26223779817cc94db6b38 +size 1101400 diff --git a/pkg/internal/ebpf/generictracer/bpf_tp_x86_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_tp_x86_bpfel.o index d1c6b699c..e6f059c24 100644 --- a/pkg/internal/ebpf/generictracer/bpf_tp_x86_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_tp_x86_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:833550ac375d9c0eaba85c9c3474898e0db525afb2db9fc49d6ef6785f26da71 -size 658432 +oid sha256:cebef1c8503e0294b8bfa848c60200e214e816f81ca30ef900a731a195eaa93b +size 658464 diff --git a/pkg/internal/ebpf/generictracer/bpf_x86_bpfel.o b/pkg/internal/ebpf/generictracer/bpf_x86_bpfel.o index 564434f3e..7c1b76b5e 100644 --- a/pkg/internal/ebpf/generictracer/bpf_x86_bpfel.o +++ b/pkg/internal/ebpf/generictracer/bpf_x86_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4ddd093fc457bd93105f26912bd9f31182531b039b8dc0c84601f15dfe1cbf07 +oid sha256:bb9ee4da5c64c5557fbb1a07383f1290c7b9bbd178cc4fac166430679ccb3a03 size 643944 diff --git a/pkg/internal/ebpf/tctracer/bpf_arm64_bpfel.o b/pkg/internal/ebpf/tctracer/bpf_arm64_bpfel.o index a24c53bd6..205303f00 100644 --- a/pkg/internal/ebpf/tctracer/bpf_arm64_bpfel.o +++ b/pkg/internal/ebpf/tctracer/bpf_arm64_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94fe11f74af15938bf98b3736faeea87ada8884509a00dbb134b072c8298d17d +oid sha256:ccd7200b401b48e6b855bbb1091741c40f1e9849d094bfa9bd54f0884f923cb9 size 220352 diff --git a/pkg/internal/ebpf/tctracer/bpf_debug_arm64_bpfel.o b/pkg/internal/ebpf/tctracer/bpf_debug_arm64_bpfel.o index 3f27b7693..87d727b5d 100644 --- a/pkg/internal/ebpf/tctracer/bpf_debug_arm64_bpfel.o +++ b/pkg/internal/ebpf/tctracer/bpf_debug_arm64_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b33b0864e1ccabaeac4c8a58d9f80ea90978544271f3ed18c52c40ff6e79ead8 +oid sha256:54ffd799fcd6039864bd6784881e2a09d01f96906a9fa5f2020954511d45bcce size 401768 diff --git a/pkg/internal/ebpf/tctracer/bpf_debug_x86_bpfel.o b/pkg/internal/ebpf/tctracer/bpf_debug_x86_bpfel.o index 4d012d643..7bdb5db97 100644 --- a/pkg/internal/ebpf/tctracer/bpf_debug_x86_bpfel.o +++ b/pkg/internal/ebpf/tctracer/bpf_debug_x86_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0759be44d7ca358cd54195e052f376f46317e71e355b28f4a2953be001ad08f7 +oid sha256:a1a67f91147525bdf8e2b2a483b6289e50010094f8f39e184c81eaac41bde0a3 size 403080 diff --git a/pkg/internal/ebpf/tctracer/bpf_x86_bpfel.o b/pkg/internal/ebpf/tctracer/bpf_x86_bpfel.o index 1722fb5ff..587fd5463 100644 --- a/pkg/internal/ebpf/tctracer/bpf_x86_bpfel.o +++ b/pkg/internal/ebpf/tctracer/bpf_x86_bpfel.o @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1b31d396bac748c01dd272816778182f81f1a2f99402ae766c72aa53dc995309 +oid sha256:474909f7f446ac742dae229303cc61e97a701ab411d0cf2781b592981013e6c9 size 221664