Skip to content
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
11 changes: 8 additions & 3 deletions .github/workflows/workflow_integration_tests_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ jobs:
- name: build matrix
id: build-matrix
env:
# 3 partitions, one for each of:
# TestMultiProcess, TestMultiProcessAppCP, TestMultiProcessAppCPNoIP
PARTITIONS: 3
# 5 partitions, one for each of:
# 1. TestMultiProcess
# 2. TestMultiProcessAppCP
# 3. TestMultiProcessAppCPNoIP
# 4. TestMultiProcessAppCPTCPOnly
# 5. TestMultiProcessAppCPHeadersAndTCP

PARTITIONS: 5
TEST_TAGS: integration
run: |
echo -n "matrix=" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ integration-test-matrix-json:

.PHONY: vm-integration-test-matrix-json
vm-integration-test-matrix-json:
@./scripts/generate-integration-matrix.sh "$${TEST_TAGS:-integration}" internal/test/integration "$${PARTITIONS:-3}" "TestMultiProcess"
@./scripts/generate-integration-matrix.sh "$${TEST_TAGS:-integration}" internal/test/integration "$${PARTITIONS:-5}" "TestMultiProcess"

.PHONY: k8s-integration-test-matrix-json
k8s-integration-test-matrix-json:
Expand Down
2 changes: 2 additions & 0 deletions bpf/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#pragma once

#include <bpfcore/vmlinux.h>

#include <bpfcore/utils.h>

#include <pid/pid_helpers.h>
Expand Down
27 changes: 16 additions & 11 deletions bpf/common/connection_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ typedef struct connection_info_part {
u8 __pad;
} connection_info_part_t;

#ifdef BPF_DEBUG
static __always_inline void dbg_print_http_connection_info(connection_info_t *info) {
if (!k_bpf_debug) {
return;
}

bpf_dbg_printk("[conn] s_h = %llx, s_l = %llx, s_port=%d",
*(u64 *)(&info->s_addr),
*(u64 *)(&info->s_addr[8]),
Expand All @@ -79,18 +82,30 @@ static __always_inline void dbg_print_http_connection_info(connection_info_t *in
info->d_port);
}
static __always_inline void dbg_print_http_connection_info_part(connection_info_part_t *info) {
if (!k_bpf_debug) {
Comment thread
grcevski marked this conversation as resolved.
return;
}

bpf_dbg_printk("[conn part] s_h = %llx, s_l = %llx, s_port=%d",
*(u64 *)(&info->addr),
*(u64 *)(&info->addr[8]),
info->port);
}
static __always_inline void d_print_http_connection_info_part(connection_info_part_t *info) {
if (!k_bpf_debug) {
return;
}

bpf_d_printk("[conn part] s_h = %llx, s_l = %llx, s_port=%d",
*(u64 *)(&info->addr),
*(u64 *)(&info->addr[8]),
info->port);
}
static __always_inline void d_print_http_connection_info(connection_info_t *info) {
if (!k_bpf_debug) {
return;
}

bpf_d_printk("[conn] s_h = %llx, s_l = %llx, s_port=%d",
*(u64 *)(&info->s_addr),
*(u64 *)(&info->s_addr[8]),
Expand All @@ -100,16 +115,6 @@ static __always_inline void d_print_http_connection_info(connection_info_t *info
*(u64 *)(&info->d_addr[8]),
info->d_port);
}
#else
static __always_inline void dbg_print_http_connection_info(connection_info_t *info) {
}
static __always_inline void dbg_print_http_connection_info_part(connection_info_part_t *info) {
}
static __always_inline void d_print_http_connection_info_part(connection_info_part_t *info) {
}
static __always_inline void d_print_http_connection_info(connection_info_t *info) {
}
#endif

const u8 ip4ip6_prefix[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff};

Expand Down
8 changes: 4 additions & 4 deletions bpf/common/trace_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static __always_inline void urand_bytes(unsigned char *buf, u32 size) {
}
}

static __always_inline void decode_hex(unsigned char *dst, const unsigned char *src, int src_len) {
for (int i = 1, j = 0; i < src_len; i += 2) {
static __always_inline void decode_hex(unsigned char *dst, const unsigned char *src, u32 src_len) {
for (u32 i = 1, j = 0; i < src_len; i += 2) {
unsigned char p = src[i - 1];
unsigned char q = src[i];

Expand All @@ -49,8 +49,8 @@ static __always_inline void decode_hex(unsigned char *dst, const unsigned char *
}
}

static __always_inline void encode_hex(unsigned char *dst, const unsigned char *src, int src_len) {
for (int i = 0, j = 0; i < src_len; i++) {
static __always_inline void encode_hex(unsigned char *dst, const unsigned char *src, u32 src_len) {
for (u32 i = 0, j = 0; i < src_len; i++) {
unsigned char p = src[i];
dst[j++] = hex[(p >> 4) & 0xff];
dst[j++] = hex[p & 0x0f];
Expand Down
21 changes: 11 additions & 10 deletions bpf/generictracer/k_tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <bpfcore/bpf_helpers.h>
#include <bpfcore/bpf_tracing.h>

#include <common/common.h>
#include <common/connection_info.h>
#include <common/msg_buffer.h>
#include <common/dns.h>
#include <common/pin_internal.h>
Expand Down Expand Up @@ -647,12 +649,12 @@ int BPF_KPROBE(obi_kprobe_tcp_close, struct sock *sk, long timeout) {
if (is_tcp_socket_never_connected(sk)) {
cp_support_data_t *ct = bpf_map_lookup_elem(&cp_support_connect_info, &info);
bpf_dbg_printk("=== possibly never connected sock %d %llx ct=%llx ===", id, sk, ct);
#ifdef BPF_DEBUG
if (ct) {

if (k_bpf_debug && ct) {
bpf_dbg_printk(
"=== established %d, already failed %d ===", ct->established, ct->failed);
}
#endif

if (ct && !ct->established && !ct->failed) {
dbg_print_http_connection_info(&info.conn);
failed_to_connect_event(&info, orig_dport, ct->ts);
Expand Down Expand Up @@ -922,7 +924,6 @@ static __always_inline int return_recvmsg(void *ctx, struct sock *in_sock, u64 i

if (parse_sock_info((struct sock *)sock_ptr, &info.conn)) {
const u16 orig_dport = info.conn.d_port;
//dbg_print_http_connection_info(&info.conn);
sort_connection_info(&info.conn);
info.pid = pid_from_pid_tgid(id);

Expand Down Expand Up @@ -983,14 +984,14 @@ int BPF_KPROBE(obi_kprobe_tcp_cleanup_rbuf, struct sock *sk, int copied) {

bpf_dbg_printk("=== tcp_cleanup_rbuf id=%d copied_len %d ===", id, copied);

#ifdef BPF_DEBUG
connection_info_t conn = {};
if (k_bpf_debug) {
connection_info_t conn = {};

if (parse_sock_info(sk, &conn)) {
sort_connection_info(&conn);
dbg_print_http_connection_info(&conn);
if (parse_sock_info(sk, &conn)) {
sort_connection_info(&conn);
dbg_print_http_connection_info(&conn);
}
}
#endif

return return_recvmsg(ctx, sk, id, copied);
}
Expand Down
22 changes: 13 additions & 9 deletions bpf/generictracer/protocol_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <generictracer/k_tracer_tailcall.h>
#include <generictracer/protocol_common.h>

#include <logger/bpf_dbg.h>

#include <maps/accepted_connections.h>
#include <maps/active_ssl_connections.h>
#include <maps/ongoing_http.h>
Expand Down Expand Up @@ -121,11 +123,11 @@ http_get_or_create_trace_info(http_connection_metadata_t *meta,
bpf_dbg_printk("Using old traceparent id");
}

#ifdef BPF_DEBUG
unsigned char tp_buf[TP_MAX_VAL_LENGTH];
make_tp_string(tp_buf, &tp_p->tp);
bpf_dbg_printk("tp: %s", tp_buf);
#endif
if (k_bpf_debug) {
unsigned char tp_buf[TP_MAX_VAL_LENGTH];
make_tp_string(tp_buf, &tp_p->tp);
bpf_dbg_printk("tp: %s", tp_buf);
}

u8 skip_tp_parsing = 0;

Expand Down Expand Up @@ -175,10 +177,12 @@ http_get_or_create_trace_info(http_connection_metadata_t *meta,
if (meta && meta->type != EVENT_HTTP_CLIENT) {
decode_hex(tp_p->tp.parent_id, s_id, SPAN_ID_CHAR_LEN);
}
#ifdef BPF_DEBUG
make_tp_string(tp_buf, &tp_p->tp);
bpf_dbg_printk("new tp: %s", tp_buf);
#endif

if (k_bpf_debug) {
unsigned char tp_buf[TP_MAX_VAL_LENGTH];
make_tp_string(tp_buf, &tp_p->tp);
bpf_dbg_printk("new tp: %s", tp_buf);
}
} else {
bpf_dbg_printk("No additional traceparent in headers, using what was made before");
}
Expand Down
12 changes: 7 additions & 5 deletions bpf/generictracer/protocol_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <generictracer/maps/ongoing_tcp_req.h>
#include <generictracer/maps/tcp_req_mem.h>

#include <logger/bpf_dbg.h>

static __always_inline tcp_req_t *empty_tcp_req() {
int zero = 0;
tcp_req_t *value = bpf_map_lookup_elem(&tcp_req_mem, &zero);
Expand All @@ -36,11 +38,11 @@ static __always_inline void init_new_trace(tp_info_t *tp) {
urand_bytes(tp->span_id, SPAN_ID_SIZE_BYTES);
__builtin_memset(tp->parent_id, 0, sizeof(tp->span_id));

#ifdef BPF_DEBUG
unsigned char tp_buf[TP_MAX_VAL_LENGTH];
make_tp_string(tp_buf, tp);
bpf_dbg_printk("tp: %s", tp_buf);
#endif
if (k_bpf_debug) {
unsigned char tp_buf[TP_MAX_VAL_LENGTH];
make_tp_string(tp_buf, tp);
bpf_dbg_printk("tp: %s", tp_buf);
}
}

static __always_inline u8 already_tracked_tcp(const pid_connection_info_t *p_conn) {
Expand Down
5 changes: 5 additions & 0 deletions bpf/logger/bpf_dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#ifdef BPF_DEBUG

enum { k_bpf_debug = 1 };

typedef struct log_info {
u64 pid;
unsigned char log[80];
Expand Down Expand Up @@ -64,6 +66,9 @@ enum bpf_func_id___x {
bpf_printk(fmt, ##args); \
}
#else

enum { k_bpf_debug = 0 };

#define bpf_dbg_printk(fmt, args...)
#define bpf_d_printk(fmt, args...)
#endif
40 changes: 21 additions & 19 deletions bpf/rdns/rdns_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,27 @@ static __always_inline void parse_dns_response(struct xdp_md *ctx,
return;
}

#ifdef BPF_DEBUG
const __u16 id = bpf_ntohs(*(const __be16 *)(data));
const __u8 ra = get_bit(flags1, RA_OFFSET);
const __u8 aa = get_bit(flags0, AA_OFFSET);
const __u8 tc = get_bit(flags0, TC_OFFSET);
const __u8 rd = get_bit(flags0, RD_OFFSET);
bpf_dbg_printk("Found possible DNS response: %x!\n", id);
bpf_dbg_printk("flags[0] = %x\n", flags0);
bpf_dbg_printk("id: %x, qr: %u, opcode: %u, aa: %u, tc: %u, rd: %u, ra: %u\n",
id,
qr,
opcode,
aa,
tc,
rd,
ra);
bpf_dbg_printk("flags[1] = %x\n", flags1);
bpf_dbg_printk("z: %u, rcode: %u, qdcount = %u, ancount = %u\n", z, rcode, ancount, qdcount);
#endif //BPF_DEBUG
if (k_bpf_debug) {
[[maybe_unused]] const __u16 id = bpf_ntohs(*(const __be16 *)(data));
[[maybe_unused]] const __u8 ra = get_bit(flags1, RA_OFFSET);
[[maybe_unused]] const __u8 aa = get_bit(flags0, AA_OFFSET);
[[maybe_unused]] const __u8 tc = get_bit(flags0, TC_OFFSET);
[[maybe_unused]] const __u8 rd = get_bit(flags0, RD_OFFSET);

bpf_dbg_printk("Found possible DNS response: %x!\n", id);
bpf_dbg_printk("flags[0] = %x\n", flags0);
bpf_dbg_printk("id: %x, qr: %u, opcode: %u, aa: %u, tc: %u, rd: %u, ra: %u\n",
id,
qr,
opcode,
aa,
tc,
rd,
ra);
bpf_dbg_printk("flags[1] = %x\n", flags1);
bpf_dbg_printk(
"z: %u, rcode: %u, qdcount = %u, ancount = %u\n", z, rcode, ancount, qdcount);
}

// Parse question sections
__u32 __attribute__((unused)) dns_packet_size = 0;
Expand Down
6 changes: 4 additions & 2 deletions bpf/tctracer/tc_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ static __always_inline void populate_span_id_from_tcp_info(tp_info_t *tp, protoc
}

static __always_inline void print_tp(tp_info_pid_t *new_tp) {
#ifdef BPF_DEBUG
if (!k_bpf_debug) {
return;
}

unsigned char tp_buf[TP_MAX_VAL_LENGTH];

make_tp_string(tp_buf, &new_tp->tp);
bpf_dbg_printk("tp: %s", tp_buf);
#endif
}

static __always_inline void
Expand Down
16 changes: 0 additions & 16 deletions bpf/tpinjector/maps/egress_key_mem.h

This file was deleted.

16 changes: 16 additions & 0 deletions bpf/tpinjector/maps/sk_tp_info_pid_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <bpfcore/vmlinux.h>
#include <bpfcore/bpf_helpers.h>

#include <common/tp_info.h>

struct {
__uint(type, BPF_MAP_TYPE_SK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, u32);
__type(value, tp_info_pid_t);
} sk_tp_info_pid_map SEC(".maps");
Loading
Loading